-
Notifications
You must be signed in to change notification settings - Fork 4
InternalMethodInvocation
Mehdi Mohammadi edited this page Dec 29, 2013
·
1 revision
Default Java accessibility is package and it's a known practice to put production classes and test-cases in the same package structure for testing package methods.
We translate [package accessibility] (AccessibilityTransformer) to similar protected internal but internal accessibility refer to assemblies. In .Net, developers usually put test-cases in a different project (assembly) from production classes. However, test-cases namespace will be same as production classes, they couldn't access 'protected internal' members.
We translate these calls to use Reflection.
[Java]
package project.core;
public class Shape
{
int method(int a, int b)
{
return 0;
}
}
package project.core;
public class ShapeTest extends TestCase
{
public void testMethod()
{
Shape shape = new Shape();
assertEquals(0, shape.method(0, 1));
}
}
[C#]
namespace Project.Core
{
public class Shape
{
protected internal int method(int a, int b)
{
return 0;
}
}
}
namespace Project.Core
{
[TestFixture]
public class ShapeTest
{
[Test]
public void testMethod()
{
Shape shape = new Shape();
assertEquals(0, Helpers.ReflectionHelper.CallInternalMethod("method", shape, new object[] {0, 1}););
}
}
}