use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalMultipleOfSameTypeOnSpecificPlaceInHierarchy.
@Test
public void testSetInternalMultipleOfSameTypeOnSpecificPlaceInHierarchy() throws Exception {
final int value = 31;
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
try {
Whitebox.setInternalState(tested, value, ClassWithInternalState.class);
fail("should throw TooManyFieldsFoundException!");
} catch (TooManyFieldsFoundException e) {
assertEquals("Two or more fields matching type int.", e.getMessage());
}
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateInClassAndMakeSureThatTheChildClassIsNotAffectedEvenThoughItHasAFieldWithTheSameName.
@Test
public void testSetInternalStateInClassAndMakeSureThatTheChildClassIsNotAffectedEvenThoughItHasAFieldWithTheSameName() throws Exception {
final int value = 22;
final String fieldName = "anotherInternalState";
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState() {
};
Whitebox.setInternalState(tested, fieldName, value);
assertEquals(value, Whitebox.getInternalState(tested, fieldName));
assertEquals(-1, Whitebox.getInternalState(tested, fieldName, ClassWithInternalState.class));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testInvokePrivateMethodWithASubTypeOfTheArgumentType.
@Test
public void testInvokePrivateMethodWithASubTypeOfTheArgumentType() throws Exception {
ClassWithPrivateMethods tested = new ClassWithPrivateMethods();
ClassWithChildThatHasInternalState argument = new ClassWithChildThatHasInternalState();
assertSame(argument, Whitebox.invokeMethod(tested, "methodWithObjectArgument", argument));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateBasedOnObjectSubClassTypeAtASpecificPlaceInTheClassHierarchy.
@Test
public void testSetInternalStateBasedOnObjectSubClassTypeAtASpecificPlaceInTheClassHierarchy() throws Exception {
final ClassWithPrivateMethods value = new ClassWithPrivateMethods() {
};
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, value, ClassWithInternalState.class);
assertSame(value, tested.getClassWithPrivateMethods());
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testGetInternalState_superClass_parameterized.
@SuppressWarnings("deprecation")
@Test
public void testGetInternalState_superClass_parameterized() throws Exception {
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
int internalState = Whitebox.getInternalState(tested, "internalState", ClassWithInternalState.class, int.class);
assertEquals(0, internalState);
}
Aggregations