Package samples.partialmocking

Examples of samples.partialmocking.PrivatePartialMockingExample


public class PrivatePartialMockingExampleTest {

  @Test
  public void spyingOnPrivateMethodsWorks() throws Exception {
    final String expected = "TEST VALUE";
    PrivatePartialMockingExample underTest = spy(new PrivatePartialMockingExample());
    final String nameOfMethodToMock = "methodToMock";
    final String input = "input";
    when(underTest, nameOfMethodToMock, input).thenReturn(expected);

    assertEquals(expected, underTest.methodToTest());

    verifyPrivate(underTest).invoke(nameOfMethodToMock, input);
  }
View Full Code Here


  }

  @Test
  public void partialMockingOfPrivateMethodsWorks() throws Exception {
    final String expected = "TEST VALUE";
    PrivatePartialMockingExample underTest = spy(new PrivatePartialMockingExample());
    final String nameOfMethodToMock = "methodToMock";
    final String input = "input";
    doReturn(expected).when(underTest, nameOfMethodToMock, input);

    assertEquals(expected, underTest.methodToTest());

    verifyPrivate(underTest).invoke(nameOfMethodToMock, input);
  }
View Full Code Here

  }

  @Test
  public void spyingOnPrivateMethodsWorksWithoutSpecifyingMethodName() throws Exception {
    final String expected = "TEST VALUE";
    PrivatePartialMockingExample underTest = spy(new PrivatePartialMockingExample());
    final String input = "input";
    final Method methodToMock = method(PrivatePartialMockingExample.class, String.class);
    when(underTest, methodToMock).withArguments(input).thenReturn(expected);

    assertEquals(expected, underTest.methodToTest());

    verifyPrivate(underTest).invoke(methodToMock).withArguments(input);
  }
View Full Code Here

  }

  @Test
  public void partialMockingOfPrivateMethodsWorksWithoutSpecifyingMethodName() throws Exception {
    final String expected = "TEST VALUE";
    PrivatePartialMockingExample underTest = spy(new PrivatePartialMockingExample());
    final String input = "input";
    final Method methodToMock = method(PrivatePartialMockingExample.class, String.class);
    doReturn(expected).when(underTest, methodToMock).withArguments(input);

    assertEquals(expected, underTest.methodToTest());

    verifyPrivate(underTest).invoke(methodToMock).withArguments(input);
  }
View Full Code Here

TOP

Related Classes of samples.partialmocking.PrivatePartialMockingExample

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.