Search in sources :

Example 6 with ClassWithPrivateMethods

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

the class WhiteBoxTest method testInvokePrivateMethodWithArrayArgument.

@Test
public void testInvokePrivateMethodWithArrayArgument() throws Exception {
    ClassWithPrivateMethods tested = new ClassWithPrivateMethods();
    assertEquals("Hello World", Whitebox.invokeMethod(tested, "evilConcatOfStrings", new Object[] { new String[] { "Hello ", "World" } }));
}
Also used : ClassWithPrivateMethods(org.powermock.reflect.testclasses.ClassWithPrivateMethods) Test(org.junit.Test)

Example 7 with ClassWithPrivateMethods

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

the class WhiteBoxTest method testInvokePrivateMethodWithASubTypeOfTheArgumentType.

@Test
public void testInvokePrivateMethodWithASubTypeOfTheArgumentType() throws Exception {
    ClassWithPrivateMethods tested = new ClassWithPrivateMethods();
    ClassWithChildThatHasInternalState argument = new ClassWithChildThatHasInternalState();
    assertSame(argument, Whitebox.invokeMethod(tested, "methodWithObjectArgument", argument));
}
Also used : ClassWithPrivateMethods(org.powermock.reflect.testclasses.ClassWithPrivateMethods) ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 8 with ClassWithPrivateMethods

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

the class WhiteBoxTest method testSetInternalStateBasedOnObjectSubClassTypeAtASpecificPlaceInTheClassHierarchy.

@Test
public void testSetInternalStateBasedOnObjectSubClassTypeAtASpecificPlaceInTheClassHierarchy() throws Exception {
    final ClassWithPrivateMethods value = new ClassWithPrivateMethods() {
    };
    ClassWithChildThatHasInternalState tested = new ClassWithChildThatHasInternalState();
    Whitebox.setInternalState(tested, value, ClassWithInternalState.class);
    assertSame(value, tested.getClassWithPrivateMethods());
}
Also used : ClassWithPrivateMethods(org.powermock.reflect.testclasses.ClassWithPrivateMethods) ClassWithChildThatHasInternalState(org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState) Test(org.junit.Test)

Example 9 with ClassWithPrivateMethods

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

Example 10 with ClassWithPrivateMethods

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

the class WhiteBoxTest method testInvokeVarArgsMethod_noArguments.

@Test
public void testInvokeVarArgsMethod_noArguments() throws Exception {
    ClassWithPrivateMethods tested = new ClassWithPrivateMethods();
    assertEquals(0, Whitebox.invokeMethod(tested, "varArgsMethod"));
}
Also used : ClassWithPrivateMethods(org.powermock.reflect.testclasses.ClassWithPrivateMethods) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 ClassWithPrivateMethods (org.powermock.reflect.testclasses.ClassWithPrivateMethods)11 ClassWithChildThatHasInternalState (org.powermock.reflect.testclasses.ClassWithChildThatHasInternalState)4 AbstractClass (org.powermock.reflect.testclasses.AbstractClass)1 ClassWithInternalState (org.powermock.reflect.testclasses.ClassWithInternalState)1