Package samples.newmocking

Examples of samples.newmocking.MyClass


    @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();
View Full Code Here


        verify(myClassMock1, MyClass.class);
    }

    @Test
    public void testSimpleMultipleNew_withRange_lowerBoundLessThan0() throws Exception {
        MyClass myClassMock1 = createMock(MyClass.class);

        try {

            expectNew(MyClass.class).andReturn(myClassMock1).times(-20, 2);
            fail("Should throw IllegalArgumentException.");
View Full Code Here

    }

    @Test
    public void testSimpleMultipleNew_withRange_upperBoundLessThan0() throws Exception {

        MyClass myClassMock1 = createMock(MyClass.class);
        try {
            expectNew(MyClass.class).andReturn(myClassMock1).times(-1, -2);
            fail("Should throw IllegalArgumentException.");
        } catch (IllegalArgumentException e) {
            assertTrue(e.getMessage().contains("<="));
View Full Code Here

    }

    @Test
    public void testSimpleMultipleNew_withRange_upperBoundLessThanLowerBound() throws Exception {

        MyClass myClassMock1 = createMock(MyClass.class);
        try {
            expectNew(MyClass.class).andReturn(myClassMock1).times(10, 2);
            fail("Should throw IllegalArgumentException.");
        } catch (IllegalArgumentException e) {
            assertTrue(e.getMessage().contains("<="));
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);
View Full Code Here

    }

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

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

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

    }

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

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

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

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

        MyClass myClassMock1 = createMock(MyClass.class);

        expectNew(MyClass.class).andReturn(myClassMock1).times(4);

        replay(myClassMock1, MyClass.class);
        try {
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();

        replay(myClassMock1, MyClass.class);
        try {
View Full Code Here

  @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();
View Full Code Here

TOP

Related Classes of samples.newmocking.MyClass

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.