Package org.easymock.tests

Examples of org.easymock.tests.IMethods


    @After
    public void tearDown() throws Exception {
    }

    private Capture<Integer> testCaptureType(final CaptureType type) {
        final IMethods mock = createMock(IMethods.class);
        final Capture<Integer> captured = new Capture<Integer>(type);

        expect(mock.oneArg(capture(captured))).andReturn("1");
        expect(mock.oneArg(anyInt())).andReturn("1");
        expect(mock.oneArg(capture(captured))).andReturn("2").times(2);
        mock.twoArgumentMethod(capture(captured), eq(5));
        mock.twoArgumentMethod(capture(captured), capture(captured));

        replay(mock);

        mock.oneArg(0);
        mock.oneArg(1);
        mock.oneArg(2);
        mock.oneArg(3);
        mock.twoArgumentMethod(4, 5);
        mock.twoArgumentMethod(6, 7);

        verify(mock);

        return captured;
    }
View Full Code Here


    // after replay issue?

    @Test
    public void testCaptureRightOne() {
        final Capture<String> captured = new Capture<String>();
        final IMethods mock = createMock(IMethods.class);

        expect(mock.oneArg(and(eq("test"), capture(captured)))).andReturn("answer1");
        expect(mock.oneArg("a")).andReturn("answer2");

        replay(mock);

        assertEquals("answer2", mock.oneArg("a"));
        assertFalse(captured.hasCaptured());

        assertEquals("answer1", mock.oneArg("test"));
        assertEquals("test", captured.getValue());

        verify(mock);
    }
View Full Code Here

    }

    @Test
    public void testPrimitiveVsObject() {
        final Capture<Integer> capture = new Capture<Integer>();
        final IMethods mock = createMock(IMethods.class);

        expect(mock.oneArg(capture(capture))).andReturn("answer");
        expect(mock.oneArg((Integer) capture(capture))).andReturn("answer");

        replay(mock);

        assertEquals("answer", mock.oneArg(2));
        assertEquals(2, capture.getValue().intValue());

        assertEquals("answer", mock.oneArg(Integer.valueOf(3)));
        assertEquals(3, capture.getValue().intValue());

        verify(mock);
    }
View Full Code Here

    }

    @Test
    public void testAnd() {
        final Capture<String> captured = new Capture<String>();
        final IMethods mock = createMock(IMethods.class);

        expect(mock.oneArg(and(capture(captured), eq("test")))).andReturn("answer");

        replay(mock);

        assertEquals("answer", mock.oneArg("test"));
        assertEquals("test", captured.getValue());

        verify(mock);
    }
View Full Code Here

        final Capture<Double> captureD = new Capture<Double>();
        final Capture<Byte> captureB = new Capture<Byte>();
        final Capture<Character> captureC = new Capture<Character>();
        final Capture<Boolean> captureBool = new Capture<Boolean>();

        final IMethods mock = createMock(IMethods.class);

        expect(mock.oneArg(capture(captureI))).andReturn("answerI");
        expect(mock.oneArg(capture(captureL))).andReturn("answerL");
        expect(mock.oneArg(capture(captureF))).andReturn("answerF");
        expect(mock.oneArg(capture(captureD))).andReturn("answerD");
        expect(mock.oneArg(capture(captureB))).andReturn("answerB");
        expect(mock.oneArg(capture(captureC))).andReturn("answerC");
        expect(mock.oneArg(capture(captureBool))).andReturn("answerZ");

        replay(mock);

        assertEquals("answerI", mock.oneArg(1));
        assertEquals("answerL", mock.oneArg(2l));
        assertEquals("answerF", mock.oneArg(3.0f));
        assertEquals("answerD", mock.oneArg(4.0));
        assertEquals("answerB", mock.oneArg((byte) 5));
        assertEquals("answerC", mock.oneArg((char) 6));
        assertEquals("answerZ", mock.oneArg(true));

        assertEquals(1, captureI.getValue().intValue());
        assertEquals(2l, captureL.getValue().longValue());
        assertEquals(3.0f, captureF.getValue().floatValue(), 0.0);
        assertEquals(4.0, captureD.getValue().doubleValue(), 0.0);
View Full Code Here

    }

    @Test
    public void testCapture_2617107() {

        final IMethods mock = createMock(IMethods.class);

        final Capture<String> cap1 = new Capture<String>();
        final Capture<String> cap2 = new Capture<String>();
        final Capture<String> cap3 = new Capture<String>();
        final Capture<String> cap4 = new Capture<String>();

        mock.simpleMethodWithArgument(and(isA(String.class), capture(cap1)));
        mock.simpleMethodWithArgument(and(isA(String.class), capture(cap2)));
        mock.simpleMethodWithArgument(and(isA(String.class), capture(cap3)));
        mock.simpleMethodWithArgument(and(isA(String.class), capture(cap4)));

        replay(mock);

        final String[] s = { "one", "two", "three", "four" };

        for (final String element : s) {
            mock.simpleMethodWithArgument(element);
        }

        assertEquals("one", cap1.getValue());
        assertEquals("two", cap2.getValue());
        assertEquals("three", cap3.getValue());
View Full Code Here

    @Test
    public void testCapture1_2446744() {
        final Capture<String> capture1 = new Capture<String>();
        final Capture<String> capture2 = new Capture<String>();
        final Capture<String> capture3 = new Capture<String>();
        final IMethods mock = createMock(IMethods.class);
        expect(mock.oneArg(capture(capture1))).andReturn("1").once();
        expect(mock.oneArg(capture(capture2))).andReturn("2").once();
        expect(mock.oneArg(capture(capture3))).andReturn("3").once();

        replay(mock);

        for (int i = 0; i < 3; i++) {
            final String string = "Run" + (i + 1);
            mock.oneArg(string);
        }

        assertEquals("Run3", capture3.getValue());
        assertEquals("Run2", capture2.getValue());
        assertEquals("Run1", capture1.getValue());
View Full Code Here

    }

    @Test
    public void testCapture2_2446744() {
        final Capture<String> capture = new Capture<String>(CaptureType.ALL);
        final IMethods mock = createMock(IMethods.class);
        expect(mock.oneArg(capture(capture))).andReturn("1").once();
        expect(mock.oneArg(capture(capture))).andReturn("2").once();
        expect(mock.oneArg(capture(capture))).andReturn("3").once();

        replay(mock);

        for (int i = 0; i < 3; i++) {
            final String string = "Run" + (i + 1);
            mock.oneArg(string);
        }

        assertEquals(Arrays.asList("Run1", "Run2", "Run3"), capture.getValues());
    }
View Full Code Here

    }

    @Test
    public void testCaptureFromStub() {
        final Capture<String> capture = new Capture<String>(CaptureType.ALL);
        final IMethods mock = createMock(IMethods.class);
        expect(mock.oneArg(capture(capture))).andStubReturn("1");

        replay(mock);

        mock.oneArg("test");

        assertEquals("test", capture.getValue());
    }
View Full Code Here

    @Test
    public void callbackGetsArgumentsEvenIfAMockCallsAnother() {

        final StringBuilder buffer = new StringBuilder();

        final IMethods mock2 = createStrictMock(IMethods.class);
        mock2.simpleMethod();
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() {
                // empty, only needed to force deletion of arguments
                return null;
            }
        }).times(2);

        mock.simpleMethodWithArgument((String) notNull());
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() {
                mock2.simpleMethod();
                buffer.append((String) getCurrentArguments()[0]);
                return null;
            }
        }).times(2);
View Full Code Here

TOP

Related Classes of org.easymock.tests.IMethods

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.