use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateBasedOnObjectTypeAtASpecificPlaceInTheClassHierarchy.
@Test
public void testSetInternalStateBasedOnObjectTypeAtASpecificPlaceInTheClassHierarchy() throws Exception {
final String value = "a string";
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, (Object) value, ClassWithInternalState.class);
assertEquals(value, Whitebox.getInternalState(tested, "finalString"));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateWithInvalidArgumentType.
@Test(expected = IllegalArgumentException.class)
public void testSetInternalStateWithInvalidArgumentType() throws Exception {
final int value = 22;
final String fieldName = "internalState";
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState() {
};
Whitebox.setInternalState(tested, fieldName, new Object());
assertEquals(value, Whitebox.getInternalState(tested, fieldName));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testGetInternalState_superClass_object.
@Test
public void testGetInternalState_superClass_object() throws Exception {
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Object internalState = Whitebox.getInternalState(tested, "internalState", ClassWithInternalState.class);
assertEquals(0, internalState);
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateWithNull.
@Test(expected = IllegalArgumentException.class)
public void testSetInternalStateWithNull() throws Exception {
final int value = 22;
final String fieldName = "internalState";
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState() {
};
Whitebox.setInternalState(tested, fieldName, (Object) null);
assertEquals(value, Whitebox.getInternalState(tested, fieldName));
}
use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateBasedOnObjectTypeWhenArgumentIsAPrimitiveType.
@SuppressWarnings("deprecation")
@Test
public void testSetInternalStateBasedOnObjectTypeWhenArgumentIsAPrimitiveType() throws Exception {
final int value = 22;
ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
Whitebox.setInternalState(tested, value);
assertEquals((Integer) value, Whitebox.getInternalState(tested, "anotherInternalState", ClassWithChildThatHasInternalState.class, Integer.class));
}
Aggregations