use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateBasedOnObjectTypeWhenArgumentIsAPrimitiveTypeUsingGenerics.
@Test
public void testSetInternalStateBasedOnObjectTypeWhenArgumentIsAPrimitiveTypeUsingGenerics() throws Exception {
final int value = 22;
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, value);
assertEquals((Integer) value, Whitebox.<Integer>getInternalState(tested, "anotherInternalState", ClassWithChildThatHasInternalState.class));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateBasedOnObjectType.
@Test
public void testSetInternalStateBasedOnObjectType() throws Exception {
final String value = "a string";
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, value);
assertEquals(value, Whitebox.getInternalState(tested, String.class));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetAndGetInternalStateAtASpecificPlaceInTheHierarchyBasedOnFieldType.
@Test
public void testSetAndGetInternalStateAtASpecificPlaceInTheHierarchyBasedOnFieldType() throws Exception {
final int value = 22;
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, int.class, value, ClassWithInternalState.class);
assertEquals(42, (int) Whitebox.getInternalState(tested, int.class));
assertEquals(value, (int) Whitebox.getInternalState(tested, int.class, ClassWithInternalState.class));
assertEquals(value, Whitebox.getInternalState(tested, "staticState", ClassWithInternalState.class));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateBasedOnObjectTypeAtASpecificPlaceInTheClassHierarchyForPrimitiveType.
@Test
public void testSetInternalStateBasedOnObjectTypeAtASpecificPlaceInTheClassHierarchyForPrimitiveType() throws Exception {
final long value = 31;
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, value, ClassWithInternalState.class);
assertEquals(value, tested.getInternalLongState());
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateInChildClassWithoutSpecifyingTheChildClass.
@Test
public void testSetInternalStateInChildClassWithoutSpecifyingTheChildClass() throws Exception {
final int value = 22;
final String fieldName = "internalState";
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState() {
};
Whitebox.setInternalState(tested, fieldName, value);
assertEquals(value, Whitebox.getInternalState(tested, fieldName));
}
Aggregations