Package samples.expectnew

Examples of samples.expectnew.ExpectNewDemo


        verifyAll();
    }

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

        final byte[] byteArrayOne = null;
        final byte[] byteArrayTwo = null;
        expectNew(VarArgsConstructorDemo.class, byteArrayOne, byteArrayTwo).andReturn(varArgsConstructorDemoMock);
        expect(varArgsConstructorDemoMock.getByteArrays()).andReturn(new byte[][] { byteArrayTwo });

        replayAll();

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

        verifyAll();
    }
View Full Code Here


        }
    }

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

        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).times(3);
View Full Code Here

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

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

        expectNew(ExpectNewServiceUser.class, serviceMock, numberOfTimes).andReturn(expectNewServiceImplMock);
        expect(expectNewServiceImplMock.useService()).andReturn(expected);

        replayAll();

        try {
            assertEquals(expected, tested.newWithWrongArguments(serviceMock, numberOfTimes));
            verifyAll();
            fail("Should throw AssertionError!");
        } catch (AssertionError e) {
            assertEquals(
                    "\n  Unexpected constructor call samples.expectnew.ExpectNewServiceUser(EasyMock for interface samples.Service, 4):"
View Full Code Here

        Whitebox.invokeMethod(tested, "simpleMultipleNewPrivate");
    }

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

        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).once();

        replay(myClassMock1, MyClass.class);
        tested.simpleSingleNew();
        verify(myClassMock1, MyClass.class);
    }
View Full Code Here

        }
    }

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

        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).once();

        replayAll();
        try {
            tested.makeDate();
            verifyAll();
            fail("Should throw AssertionError!");
        } catch (AssertionError e) {
            assertTrue(e.getMessage().contains(MyClass.class.getName() + "(): expected: 1, actual: 0"));
        }
View Full Code Here

        verify(myClassMock1, MyClass.class);
    }

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

        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();

        replay(myClassMock1, MyClass.class);
        tested.simpleSingleNew();
        verify(myClassMock1, MyClass.class);
    }
View Full Code Here

        verify(myClassMock1, MyClass.class);
    }

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

        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).atLeastOnce();

        replay(myClassMock1, MyClass.class);
        tested.simpleMultipleNew();
        verify(myClassMock1, MyClass.class);
    }
View Full Code Here

@PrepareForTest(ExpectNewDemo.class)
public class ResetMockTest {

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

    MyClass myClassMock = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock);
    expect(myClassMock.getMessage()).andReturn("message");

    replayAll();

    String message = tested.getMessage();

    verifyAll();
    assertEquals("message", message);

    reset(myClassMock);
    reset(MyClass.class);

    expectNew(MyClass.class).andReturn(myClassMock);
    expect(myClassMock.getMessage()).andReturn("message");

    replayAll();

    message = tested.getMessage();

    verifyAll();
    assertEquals("message", message);
  }
View Full Code Here

        }
    }

    @Test
    public void testSimpleMultipleNew_withRange_OK() throws Exception {
        ExpectNewDemo tested = new ExpectNewDemo();
        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).times(1, 5);

        replay(myClassMock1, MyClass.class);

        tested.simpleMultipleNew();

        verify(myClassMock1, MyClass.class);
    }
View Full Code Here

    assertEquals("message", message);
  }

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

    MyClass myClassMock = createMock(MyClass.class);
    expectNew(MyClass.class).andReturn(myClassMock);
    expect(myClassMock.getMessage()).andReturn("message");

    replayAll();

    String message = tested.getMessage();

    verifyAll();
    assertEquals("message", message);

    reset(myClassMock, MyClass.class);

    expectNew(MyClass.class).andReturn(myClassMock);
    expect(myClassMock.getMessage()).andReturn("message");

    replayAll();

    message = tested.getMessage();

    verifyAll();
    assertEquals("message", message);
  }
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.