Package samples.privateandfinal

Examples of samples.privateandfinal.PrivateFinal


public class PrivateFinalTest {

  @Test
  public void testMockPrivatAndFinal() throws Exception {

    PrivateFinal tested = createPartialMock(PrivateFinal.class,
        "sayIt");
    String expected = "Hello altered World";
    expectPrivate(tested, "sayIt", "name").andReturn(expected);
    replay(tested);

    String actual = tested.say("name");

    verify(tested);
    assertEquals("Expected and actual did not match", expected, actual);
  }
View Full Code Here


@PrepareForTest(PrivateFinal.class)
public class PrivateFinalTest {

  @Test
  public void testSay() throws Exception {
    PrivateFinal tested = createPartialMock(PrivateFinal.class, "sayIt");
    String expected = "Hello altered World";
    expectPrivate(tested, "sayIt", "name").andReturn(expected);
    replay(tested);

    String actual = tested.say("name");

    verify(tested);
    Assert.assertEquals(expected, actual);
  }
View Full Code Here

    assertEquals("Expected and actual did not match", expected, actual);
  }

  @Test
  public void testMultiplePartialMocksOfSameType() throws Exception {
    PrivateFinal tested1 = createPartialMock(PrivateFinal.class,
        "sayIt");
    String expected1 = "Hello altered World";
    expectPrivate(tested1, "sayIt", "name").andReturn(expected1);
    replay(tested1);
    PrivateFinal tested2 = createPartialMock(PrivateFinal.class,
        "sayIt");
    String expected2 = "Hello qweqweqwe";
    expectPrivate(tested2, "sayIt", "name").andReturn(expected2);
    replay(tested2);

    String actual1 = tested1.say("name");
    verify(tested1);
    assertEquals("Expected and actual did not match", expected1, actual1);
    String actual2 = tested2.say("name");
    verify(tested2);
    assertEquals("Expected and actual did not match", expected2, actual2);
  }
View Full Code Here

    Assert.assertEquals(expected, actual);
  }

  @Test
  public void testMultiMock() throws Exception {
    PrivateFinal tested1 = createPartialMock(PrivateFinal.class, "sayIt");
    String expected1 = "Hello altered World";
    expectPrivate(tested1, "sayIt", "name").andReturn(expected1);
    replay(tested1);
    PrivateFinal tested2 = createPartialMock(PrivateFinal.class, "sayIt");
    String expected2 = "Hello qweqweqwe";
    expectPrivate(tested2, "sayIt", "name").andReturn(expected2);
    replay(tested2);

    String actual1 = tested1.say("name");
    verify(tested1);
    Assert.assertEquals(expected1, actual1);
    String actual2 = tested2.say("name");
    verify(tested2);
    Assert.assertEquals(expected2, actual2);
  }
View Full Code Here

    spy.finalVoidCaller();
  }

  @Test
  public void assertSpyingOnPrivateFinalInstanceMethodWorks() throws Exception {
    PrivateFinal spy = spy(new PrivateFinal());

    final String expected = "test";
    assertEquals("Hello " + expected, spy.say(expected));

    when(spy, "sayIt", isA(String.class)).thenReturn(expected);

    assertEquals(expected, spy.say(expected));

    verifyPrivate(spy, times(2)).invoke("sayIt", expected);
  }
View Full Code Here

    verifyPrivate(spy, times(2)).invoke("sayIt", expected);
  }

  @Test
  public void assertSpyingOnPrivateFinalInstanceMethodWorksWhenUsingJavaLangReflectMethod() throws Exception {
    PrivateFinal spy = spy(new PrivateFinal());

    final String expected = "test";
    assertEquals("Hello " + expected, spy.say(expected));
   
    final Method methodToExpect = method(PrivateFinal.class, "sayIt");
    when(spy, methodToExpect).withArguments(isA(String.class)).thenReturn(expected);

    assertEquals(expected, spy.say(expected));

    verifyPrivate(spy, times(2)).invoke(methodToExpect).withArguments(expected);
  }
View Full Code Here

    spy.finalVoidCaller();
  }

  @Test
  public void assertSpyingOnPrivateFinalInstanceMethodWorks() throws Exception {
    PrivateFinal spy = spy(new PrivateFinal());

    final String expected = "test";
    assertEquals("Hello " + expected, spy.say(expected));

    when(spy, "sayIt", isA(String.class)).thenReturn(expected);

    assertEquals(expected, spy.say(expected));

    verifyPrivate(spy, times(2)).invoke("sayIt", expected);
  }
View Full Code Here

    verifyPrivate(spy, times(2)).invoke("sayIt", expected);
  }

  @Test
  public void assertSpyingOnPrivateFinalInstanceMethodWorksWhenUsingJavaLangReflectMethod() throws Exception {
    PrivateFinal spy = spy(new PrivateFinal());

    final String expected = "test";
    assertEquals("Hello " + expected, spy.say(expected));
   
    final Method methodToExpect = method(PrivateFinal.class, "sayIt");
    when(spy, methodToExpect).withArguments(isA(String.class)).thenReturn(expected);

    assertEquals(expected, spy.say(expected));

    verifyPrivate(spy, times(2)).invoke(methodToExpect).withArguments(expected);
  }
View Full Code Here

    spy.finalVoidCaller();
  }

  @Test
  public void assertSpyingOnPrivateFinalInstanceMethodWorks() throws Exception {
    PrivateFinal spy = spy(new PrivateFinal());

    final String expected = "test";
    assertEquals("Hello " + expected, spy.say(expected));

    when(spy, "sayIt", isA(String.class)).thenReturn(expected);

    assertEquals(expected, spy.say(expected));

    verifyPrivate(spy, times(2)).invoke("sayIt", expected);
  }
View Full Code Here

    verifyPrivate(spy, times(2)).invoke("sayIt", expected);
  }

  @Test
  public void assertSpyingOnPrivateFinalInstanceMethodWorksWhenUsingJavaLangReflectMethod() throws Exception {
    PrivateFinal spy = spy(new PrivateFinal());

    final String expected = "test";
    assertEquals("Hello " + expected, spy.say(expected));
   
    final Method methodToExpect = method(PrivateFinal.class, "sayIt");
    when(spy, methodToExpect).withArguments(isA(String.class)).thenReturn(expected);

    assertEquals(expected, spy.say(expected));

    verifyPrivate(spy, times(2)).invoke(methodToExpect).withArguments(expected);
  }
View Full Code Here

TOP

Related Classes of samples.privateandfinal.PrivateFinal

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.