Package samples.expectnew

Examples of samples.expectnew.ExpectNewDemo


    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
  }

  @Test
  public void testNewWithArrayVarArgsWhenFirstArgumentIsNullAndSubseqentArgumentsAreNotNull() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);

    final byte[] byteArrayOne = null;
    final byte[] byteArrayTwo = new byte[] { 17 };
    whenNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo).thenReturn(
        varArgsConstructorDemoMock);
    when(varArgsConstructorDemoMock.getByteArrays()).thenReturn(new byte[][] { byteArrayTwo });

    byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
    assertEquals(1, varArgs.length);
    assertSame(byteArrayTwo, varArgs[0]);

    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
  }
View Full Code Here


    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
  }

  @Test
  public void testNewWithArrayVarArgsWhenFirstArgumentIsNotNullButSubseqentArgumentsAreNull() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);

    final byte[] byteArrayOne = new byte[] { 42 };
    final byte[] byteArrayTwo = null;
    whenNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo).thenReturn(
        varArgsConstructorDemoMock);
    when(varArgsConstructorDemoMock.getByteArrays()).thenReturn(new byte[][] { byteArrayOne });

    byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
    assertEquals(1, varArgs.length);
    assertSame(byteArrayOne, varArgs[0]);

    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
  }
View Full Code Here

  }

  @Test
  public void testNewWithArrayVarArgsWhenFirstArgumentIsNullSecondArgumentIsNotNullAndThirdArgumentIsNull()
      throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);

    final byte[] byteArrayOne = null;
    final byte[] byteArrayTwo = new byte[] { 42 };
    final byte[] byteArrayThree = null;
    whenNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo, byteArrayThree).thenReturn(
        varArgsConstructorDemoMock);
    when(varArgsConstructorDemoMock.getByteArrays()).thenReturn(new byte[][] { byteArrayTwo });

    byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo, byteArrayThree);
    assertEquals(1, varArgs.length);
    assertSame(byteArrayTwo, varArgs[0]);

    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo, byteArrayThree);
  }
View Full Code Here

    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo, byteArrayThree);
  }

  @Test
  public void testNewWithArrayVarArgsWhenAllArgumentsAreNull() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();
    VarArgsConstructorDemo varArgsConstructorDemoMock = mock(VarArgsConstructorDemo.class);

    final byte[] byteArrayOne = null;
    final byte[] byteArrayTwo = null;
    whenNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo).thenReturn(
        varArgsConstructorDemoMock);
    when(varArgsConstructorDemoMock.getByteArrays()).thenReturn(new byte[][] { byteArrayTwo });

    byte[][] varArgs = tested.newVarArgs(byteArrayOne, byteArrayTwo);
    assertEquals(1, varArgs.length);
    assertSame(byteArrayTwo, varArgs[0]);

    verifyNew(VarArgsConstructorDemo.class).withArguments(byteArrayOne, byteArrayTwo);
  }
View Full Code Here

  @Test(expected = NullPointerException.class)
  public void testNewWithWrongArgument() throws Exception {
    final int numberOfTimes = 2;
    final String expected = "used";

    ExpectNewDemo tested = new ExpectNewDemo();
    ExpectNewServiceUser expectNewServiceImplMock = mock(ExpectNewServiceUser.class);
    Service serviceMock = mock(Service.class);

    whenNew(ExpectNewServiceUser.class).withArguments(serviceMock, numberOfTimes).thenReturn(
        expectNewServiceImplMock);
    when(expectNewServiceImplMock.useService()).thenReturn(expected);

    assertEquals(expected, tested.newWithWrongArguments(serviceMock, numberOfTimes));

    verifyNew(ExpectNewServiceUser.class).withArguments(serviceMock, numberOfTimes);
    /*
     * Should throw NPE because the default behavior of Mockito when a
     * something isn't expected is to return a default value. In this case
View Full Code Here

    fail("Should throw NPE!");
  }

  @Test
  public void testExpectNewButNoNewCallWasMade() throws Exception {
    ExpectNewDemo tested = new ExpectNewDemo();

    MyClass myClassMock1 = mock(MyClass.class);

    whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock1);

    tested.makeDate();

    try {
      verifyNew(MyClass.class).withNoArguments();
      fail("Should throw AssertionError!");
    } catch (AssertionError e) {
View Full Code Here

@PrepareForTest( { MyClass.class, ExpectNewDemo.class, DataInputStream.class })
public class WhenNewTest {

    @Test
    public void testNewWithCheckedException() throws Exception {
        ExpectNewDemo tested = new ExpectNewDemo();

        final String expectedFailMessage = "testing checked exception";
        whenNew(MyClass.class).withNoArguments().thenThrow(new IOException(expectedFailMessage));

        try {
            tested.throwExceptionAndWrapInRunTimeWhenInvoction();
            fail("Should throw a checked Exception!");
        } catch (RuntimeException e) {
            assertTrue(e.getCause() instanceof IOException);
            assertEquals(expectedFailMessage, e.getMessage());
        }
View Full Code Here

        verifyNew(MyClass.class).withNoArguments();
    }

    @Test
    public void testGetMessage() throws Exception {
        ExpectNewDemo tested = new ExpectNewDemo();
        MyClass myClassMock = mock(MyClass.class);

        whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);

        String expected = "Hello altered World";
        when(myClassMock.getMessage()).thenReturn("Hello altered World");

        String actual = tested.getMessage();

        verify(myClassMock).getMessage();
        verifyNew(MyClass.class).withNoArguments();
        assertEquals("Expected and actual did not match", expected, actual);
    }
View Full Code Here

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

    @Test
    public void testGetMessageWithArgument() throws Exception {
        ExpectNewDemo tested = new ExpectNewDemo();

        MyClass myClassMock = mock(MyClass.class);
        whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);

        String expected = "Hello altered World";
        when(myClassMock.getMessage("test")).thenReturn("Hello altered World");

        String actual = tested.getMessageWithArgument();

        verify(myClassMock).getMessage("test");
        verifyNew(MyClass.class).withNoArguments();
        assertEquals("Expected and actual did not match", expected, actual);
    }
View Full Code Here

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

    @Test
    public void testInvokeVoidMethod() throws Exception {
        ExpectNewDemo tested = new ExpectNewDemo();

        MyClass myClassMock = mock(MyClass.class);
        whenNew(MyClass.class).withNoArguments().thenReturn(myClassMock);

        doNothing().when(myClassMock).voidMethod();

        tested.invokeVoidMethod();

        verify(myClassMock).voidMethod();
        verifyNew(MyClass.class).withNoArguments();
    }
View Full Code Here

TOP

Related Classes of samples.expectnew.ExpectNewDemo

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.