Package samples.privateandfinal

Examples of samples.privateandfinal.PrivateFinal


        tested.doObjectStuff("Testing");
    }

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

        final String name = "test";
        tested.say(name);
        assertEquals("Hello " + name, tested.say(name));

        when(tested, "sayIt", name).thenReturn("First", "Second");

        assertEquals("First", tested.say(name));
        assertEquals("Second", tested.say(name));
    }
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

    }

    @Test
    public void captorAnnotationWorksOnPrivateMethods() throws Exception {
        final String expected = "testing";
        PrivateFinal demo = spy(new PrivateFinal());
        demo.say(expected);

        verifyPrivate(demo).invoke("sayIt", captor.capture());
        assertEquals(expected, captor.getValue());
    }
View Full Code Here

        tested.doObjectStuff("Testing");
    }

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

        final String name = "test";
        tested.say(name);
        assertEquals("Hello " + name, tested.say(name));

        when(tested, "sayIt", name).thenReturn("First", "Second");

        assertEquals("First", tested.say(name));
        assertEquals("Second", tested.say(name));
    }
View Full Code Here

        tested.doObjectStuff("Testing");
    }

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

        final String name = "test";
        tested.say(name);
        assertEquals("Hello " + name, tested.say(name));

        when(tested, "sayIt", name).thenReturn("First", "Second");

        assertEquals("First", tested.say(name));
        assertEquals("Second", tested.say(name));
    }
View Full Code Here

        tested.doObjectStuff("Testing");
    }

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

        final String name = "test";
        tested.say(name);
        assertEquals("Hello " + name, tested.say(name));

        when(tested, "sayIt", name).thenReturn("First", "Second");

        assertEquals("First", tested.say(name));
        assertEquals("Second", tested.say(name));
    }
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

    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

@PrepareForTest(PrivateFinal.class)
public class StupidPrivateFinalTest extends TestCase {

  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);
    assertEquals("Expected and actual did not match", expected, actual);
  }
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.