Search in sources :

Example 16 with ClassWithChildThatHasInternalState

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"));
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 17 with ClassWithChildThatHasInternalState

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));
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 18 with ClassWithChildThatHasInternalState

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);
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 19 with ClassWithChildThatHasInternalState

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));
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 20 with ClassWithChildThatHasInternalState

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));
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 ClassWithChildThatHasInternalState (org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState)20 ClassWithPrivateMethods (org.powermock.reflect.testclasses.ClassWithPrivateMethods)3 ClassWithInternalState (org.powermock.reflect.testclasses.ClassWithInternalState)2 Field (java.lang.reflect.Field)1 TooManyFieldsFoundException (org.powermock.reflect.exceptions.TooManyFieldsFoundException)1