Package samples.staticandinstance

Examples of samples.staticandinstance.StaticAndInstanceDemo


public class NoAnnotationUsageTest extends TestCase {

  public void testGetMessage() throws Exception {
    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class, "getPrivateMessage");

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(staticExpected);
    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replay(tested);
    replay(StaticAndInstanceDemo.class);

    String actual = tested.getMessage();

    verify(tested);
    verify(StaticAndInstanceDemo.class);

    assertEquals(privateExpected + staticExpected, actual);
View Full Code Here


  }

  public void testGetMessage2() throws Exception {
    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class, "getPrivateMessage");

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(staticExpected);
    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replay(tested);
    replay(StaticAndInstanceDemo.class);

    String actual = tested.getMessage();

    verify(tested);
    verify(StaticAndInstanceDemo.class);

    assertEquals(privateExpected + staticExpected, actual);
View Full Code Here

  @Test
  public void testMockStaticMethodAndInstanceMethod() throws Exception {
    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class,
        "getPrivateMessage");

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(
        staticExpected);
    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replay(tested);
    replay(StaticAndInstanceDemo.class);

    String actual = tested.getMessage();

    verify(tested);
    verify(StaticAndInstanceDemo.class);

    assertEquals(privateExpected + staticExpected, actual);
View Full Code Here

    assertEquals(privateExpected + staticExpected, actual);
  }

  @Test
  public void testMockPrivateButNotStatic() throws Exception {
    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class,
        "getPrivateMessage");

    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replay(tested);

    String actual = tested.getMessage();

    verify(tested);

    assertEquals(privateExpected + "hello world!", actual);
  }
View Full Code Here

    assertEquals(privateExpected + "hello world!", actual);
  }

  @Test
  public void testMockStaticButNotInstance() throws Exception {
    StaticAndInstanceDemo tested = new StaticAndInstanceDemo();

    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    final String staticExpected = "static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(
        staticExpected);

    replay(StaticAndInstanceDemo.class);

    String actual = tested.getMessage();

    verify(StaticAndInstanceDemo.class);

    assertEquals("Private " + staticExpected, actual);
  }
View Full Code Here

@PrepareForTest(StaticAndInstanceDemo.class)
public class StaticAndInstanceWithConstructorCodeDemoTest {

  @Test
  public void testStaticAndInstanceWithConstructor() throws Exception {
    StaticAndInstanceDemo staticAndInstanceDemoMock = createMock(StaticAndInstanceDemo.class);

    StaticAndInstanceWithConstructorCodeDemo tested = new StaticAndInstanceWithConstructorCodeDemo(
        staticAndInstanceDemoMock);

    niceReplayAndVerify();

    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    final String instanceExpected = "value";
    expect(staticAndInstanceDemoMock.getMessage()).andReturn(
        instanceExpected);

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(
        staticExpected);
View Full Code Here

public class StaticAndInstanceDemoTest {

  @Test
  public void partialMockingOfStaticAndInstanceMethod() throws Exception {
    spy(StaticAndInstanceDemo.class);
    StaticAndInstanceDemo tested = spy(new StaticAndInstanceDemo());

    final String staticExpected = "a static message";
    when(StaticAndInstanceDemo.getStaticMessage()).thenReturn(staticExpected);
    final String privateExpected = "A private message ";
    when(tested, "getPrivateMessage").thenReturn(privateExpected);

    String actual = tested.getMessage();

    verifyStatic();  StaticAndInstanceDemo.getStaticMessage();
    verifyPrivate(tested).invoke("getPrivateMessage");
    assertEquals(privateExpected + staticExpected, actual);
  }
View Full Code Here

public class NoAnnotationUsageTest extends TestCase {

  public void testGetMessage() throws Exception {
    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class, "getPrivateMessage");

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(staticExpected);
    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replay(tested);
    replay(StaticAndInstanceDemo.class);

    String actual = tested.getMessage();

    verify(tested);
    verify(StaticAndInstanceDemo.class);

    assertEquals(privateExpected + staticExpected, actual);
View Full Code Here

  }

  public void testGetMessage2() throws Exception {
    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class, "getPrivateMessage");

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(staticExpected);
    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replay(tested);
    replay(StaticAndInstanceDemo.class);

    String actual = tested.getMessage();

    verify(tested);
    verify(StaticAndInstanceDemo.class);

    assertEquals(privateExpected + staticExpected, actual);
View Full Code Here

  @Test
  public void testMockStaticMethodAndInstanceMethod() throws Exception {
    mockStaticPartial(StaticAndInstanceDemo.class, "getStaticMessage");

    StaticAndInstanceDemo tested = createPartialMock(StaticAndInstanceDemo.class, "getPrivateMessage");

    final String staticExpected = "a static message";
    expect(StaticAndInstanceDemo.getStaticMessage()).andReturn(staticExpected);
    final String privateExpected = "A private message ";
    expectPrivate(tested, "getPrivateMessage").andReturn(privateExpected);

    replayAll();

    String actual = tested.getMessage();

    verifyAll();

    assertEquals(privateExpected + staticExpected, actual);
  }
View Full Code Here

TOP

Related Classes of samples.staticandinstance.StaticAndInstanceDemo

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.