use of org.powermock.reflect.testclasses.ClassWithInternalState in project powermock by powermock.
the class WhiteBoxTest method assertThatWhiteboxWorksWithGenericsWhenSpecifyingFieldName.
@Test
public void assertThatWhiteboxWorksWithGenericsWhenSpecifyingFieldName() throws Exception {
ClassWithInternalState object = new ClassWithInternalState();
Set<String> state = Whitebox.getInternalState(object, "genericState");
assertSame(object.getGenericState(), state);
}
use of org.powermock.reflect.testclasses.ClassWithInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalStateWithMultipleValues.
@Test
public void testSetInternalStateWithMultipleValues() throws Exception {
ClassWithInternalState tested = new ClassWithInternalState();
final ClassWithPrivateMethods classWithPrivateMethods = new ClassWithPrivateMethods();
final String stringState = "someStringState";
Whitebox.setInternalState(tested, classWithPrivateMethods, stringState);
assertEquals(stringState, Whitebox.getInternalState(tested, String.class));
assertSame(classWithPrivateMethods, Whitebox.getInternalState(tested, ClassWithPrivateMethods.class));
}
use of org.powermock.reflect.testclasses.ClassWithInternalState in project powermock by powermock.
the class WhiteBoxTest method testSetInternalMultipleOfSameType.
@Test
public void testSetInternalMultipleOfSameType() throws Exception {
final int value = 31;
ClassWithInternalState tested = new ClassWithInternalState();
try {
Whitebox.setInternalState(tested, value);
fail("should throw TooManyFieldsFoundException!");
} catch (TooManyFieldsFoundException e) {
assertEquals("Two or more fields matching type int.", e.getMessage());
}
}
use of org.powermock.reflect.testclasses.ClassWithInternalState in project powermock by powermock.
the class WhiteBoxTest method assertThatErrorMessageIsCorrectWhenNoInstanceFieldFound.
@Test
public void assertThatErrorMessageIsCorrectWhenNoInstanceFieldFound() throws Exception {
ClassWithInternalState classWithInternalState = new ClassWithInternalState();
try {
Whitebox.setInternalState(classWithInternalState, (byte) 23);
fail("Should throw a FieldNotFoundException.");
} catch (FieldNotFoundException e) {
assertEquals("No instance field assignable from \"java.lang.Byte\" could be found in the class hierarchy of " + ClassWithInternalState.class.getName() + ".", e.getMessage());
}
}
use of org.powermock.reflect.testclasses.ClassWithInternalState in project powermock by powermock.
the class WhiteBoxTest method testFinalState.
@Test
@Ignore("Reflection and direct call returns different values.")
public void testFinalState() {
ClassWithInternalState state = new ClassWithInternalState();
String expected = "changed";
Whitebox.setInternalState(state, "finalString", expected);
assertEquals(expected, state.getFinalString());
assertEquals(expected, Whitebox.getInternalState(state, "finalString"));
}
Aggregations