Search in sources :

Example 1 with ClassWithInternalState

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

the class WhiteBoxTest method whiteboxSetInternalStateWorksOnArraysWhenNotDefiningMethodName.

@Test
public void whiteboxSetInternalStateWorksOnArraysWhenNotDefiningMethodName() {
    ClassWithInternalState tested = new ClassWithInternalState();
    final String[] expected = new String[] { "string1", "string2" };
    Whitebox.setInternalState(tested, expected);
    assertArrayEquals(expected, tested.getStringArray());
}
Also used : ClassWithInternalState(org.powermock.reflect.testclasses.ClassWithInternalState) Test(org.junit.Test)

Example 2 with ClassWithInternalState

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

the class WhiteBoxTest method testGetInternalState_object.

@Test
public void testGetInternalState_object() throws Exception {
    ClassWithInternalState tested = new ClassWithInternalState();
    tested.increaseInteralState();
    Object internalState = Whitebox.getInternalState(tested, "internalState");
    assertTrue("InternalState should be instanceof Integer", internalState instanceof Integer);
    assertEquals(1, internalState);
}
Also used : ClassWithInternalState(org.powermock.reflect.testclasses.ClassWithInternalState) Test(org.junit.Test)

Example 3 with ClassWithInternalState

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

the class WhiteBoxTest method testGetInternalState_parmaterizedType.

@SuppressWarnings("deprecation")
@Test
public void testGetInternalState_parmaterizedType() throws Exception {
    ClassWithInternalState tested = new ClassWithInternalState();
    tested.increaseInteralState();
    int internalState = Whitebox.getInternalState(tested, "internalState", tested.getClass(), int.class);
    assertEquals(1, internalState);
}
Also used : ClassWithInternalState(org.powermock.reflect.testclasses.ClassWithInternalState) Test(org.junit.Test)

Example 4 with ClassWithInternalState

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

the class WhiteBoxTest method whiteboxSetInternalStateWorksOnArraysWhenDefiningMethodName.

@Test
public void whiteboxSetInternalStateWorksOnArraysWhenDefiningMethodName() {
    ClassWithInternalState tested = new ClassWithInternalState();
    final String[] expected = new String[] { "string1", "string2" };
    Whitebox.setInternalState(tested, "stringArray", expected);
    assertArrayEquals(expected, tested.getStringArray());
}
Also used : ClassWithInternalState(org.powermock.reflect.testclasses.ClassWithInternalState) Test(org.junit.Test)

Example 5 with ClassWithInternalState

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

the class WhiteBoxTest method getInternalStateThrowsTooManyFieldsFoundWhenTooManyFieldsMatchTheSuppliedType.

@Test(expected = TooManyFieldsFoundException.class)
public void getInternalStateThrowsTooManyFieldsFoundWhenTooManyFieldsMatchTheSuppliedType() {
    ClassWithInternalState tested = new ClassWithInternalState();
    assertNotNull(Whitebox.getInternalState(tested, Object.class));
}
Also used : ClassWithInternalState(org.powermock.reflect.testclasses.ClassWithInternalState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 ClassWithInternalState (org.powermock.reflect.testclasses.ClassWithInternalState)11 Ignore (org.junit.Ignore)1 FieldNotFoundException (org.powermock.reflect.exceptions.FieldNotFoundException)1 TooManyFieldsFoundException (org.powermock.reflect.exceptions.TooManyFieldsFoundException)1 ClassWithPrivateMethods (org.powermock.reflect.testclasses.ClassWithPrivateMethods)1