Package samples.constructorargs

Examples of samples.constructorargs.ConstructorArgsDemo


@PrepareForTest(ConstructorArgsDemo.class)
public class ConstructorArgsDemoTest {

  @Test
  public void testGetTheSecret_noConstructor() throws Exception {
    ConstructorArgsDemo tested = createMock(ConstructorArgsDemo.class);
    assertNull(Whitebox.getInternalState(tested, "secret", ConstructorArgsDemo.class));
  }
View Full Code Here


  }

  @Test
  public void testGetTheSecret_defaultConstructor() throws Exception {
    final Constructor<ConstructorArgsDemo> constructor = ConstructorArgsDemo.class.getConstructor((Class<?>[]) null);
    ConstructorArgsDemo tested = createMock(ConstructorArgsDemo.class, new ConstructorArgs(constructor));
    assertEquals("default", Whitebox.getInternalState(tested, "secret", ConstructorArgsDemo.class));
  }
View Full Code Here

  }

  @Test
  public void testGetTheSecret_stringConstructor() throws Exception {
    final String expected = "my own secret";
    ConstructorArgsDemo tested = createMock(ConstructorArgsDemo.class, expected);
    assertEquals(expected, Whitebox.getInternalState(tested, "secret", ConstructorArgsDemo.class));
  }
View Full Code Here

  }

  @Test
  public void testGetTheSecret_stringConstructorAndMockedPrivateSecret() throws Exception {
    final String originalSecret = "my own secret";
    ConstructorArgsDemo tested = createPartialMock(ConstructorArgsDemo.class, new String[] { "theSecretIsPrivate" }, originalSecret);
    assertEquals(originalSecret, Whitebox.getInternalState(tested, "secret", ConstructorArgsDemo.class));

    final String myNewSecret = "my new secret";
    expectPrivate(tested, "theSecretIsPrivate").andReturn(myNewSecret);

    replay(tested);

    final String actual = tested.getTheSecret();

    verify(tested);

    assertEquals(myNewSecret, actual);
  }
View Full Code Here

TOP

Related Classes of samples.constructorargs.ConstructorArgsDemo

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.