Search in sources :

Example 6 with ClassWithChildThatHasInternalState

use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.

the class WhiteBoxTest method testSetInternalState_superClass.

@Test
public void testSetInternalState_superClass() throws Exception {
    ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
    tested.increaseInteralState();
    Whitebox.setInternalState(tested, "anotherInternalState", 2, ClassWithInternalState.class);
    assertEquals(2, tested.getAnotherInternalState());
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 7 with ClassWithChildThatHasInternalState

use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.

the class WhiteBoxTest method testSetInternalStateBasedOnObjectTypeAtANonSpecificPlaceInTheClassHierarchyForPrimitiveType.

@Test
public void testSetInternalStateBasedOnObjectTypeAtANonSpecificPlaceInTheClassHierarchyForPrimitiveType() throws Exception {
    final long value = 31;
    ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
    Whitebox.setInternalState(tested, value);
    assertEquals(value, tested.getInternalLongState());
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 8 with ClassWithChildThatHasInternalState

use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.

the class WhiteBoxTest method testSetAndGetInternalStateBasedOnFieldType.

@Test
public void testSetAndGetInternalStateBasedOnFieldType() throws Exception {
    final int value = 22;
    ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
    Whitebox.setInternalState(tested, int.class, value);
    assertEquals(value, (int) Whitebox.getInternalState(tested, int.class));
    assertEquals(value, Whitebox.getInternalState(tested, "anotherInternalState"));
    assertEquals(value, Whitebox.getInternalState(tested, "anotherInternalState", ClassWithChildThatHasInternalState.class));
}
Also used : ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 9 with ClassWithChildThatHasInternalState

use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.

the class WhiteBoxTest method testGetAllInstanceFields.

@Test
public void testGetAllInstanceFields() throws Exception {
    Set<Field> allFields = Whitebox.getAllInstanceFields(new ClassWithChildThatHasInternalState());
    assertEquals(8, allFields.size());
}
Also used : Field(java.lang.reflect.Field) ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 10 with ClassWithChildThatHasInternalState

use of org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState in project powermock by powermock.

the class WhiteBoxTest method testSetInternalStateBasedOnObjectSubClassType.

@Test
public void testSetInternalStateBasedOnObjectSubClassType() throws Exception {
    final ClassWithPrivateMethods value = new ClassWithPrivateMethods() {
    };
    ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState() {
    };
    Whitebox.setInternalState(tested, value);
    assertSame(value, tested.getClassWithPrivateMethods());
}
Also used : ClassWithPrivateMethods(org.powermock.reflect.testclasses.ClassWithPrivateMethods) 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