Examples of IMethods


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

Examples of org.mockitousage.IMethods

    @Test
    public void testSomething() {
        List mocks = new LinkedList();
        for (int i = 0; i < 50000; i++) {
            System.out.println("Mock no: " + i);
            IMethods mock = mock(IMethods.class);
            mocks.add(mock);
           
            when(mock.simpleMethod(1)).thenReturn("one");
            when(mock.simpleMethod(2)).thenReturn("two");
           
            assertEquals("one", mock.simpleMethod(1));
            assertEquals("two", mock.simpleMethod(2));
           
            verify(mock).simpleMethod(1);
            verify(mock).simpleMethod(2);
        }
    }
View Full Code Here

Examples of org.mockitousage.IMethods

    public static class NoWarnings {
       
        @Test
        @Ignore
        public void test() {
            IMethods mock = mock(IMethods.class);
            mock.simpleMethod(1);
            mock.otherMethod();
           
            verify(mock).simpleMethod(1);
            throw new RuntimeException("boo");
        }
View Full Code Here

Examples of org.mockitousage.IMethods

        }

        public void testIgnored() {}

        public void _test() {
            IMethods mock = mock(IMethods.class);
           
            //some stubbing
            when(mock.simpleMethod(1)).thenReturn("foo");
            when(mock.otherMethod()).thenReturn("foo");
            when(mock.booleanObjectReturningMethod()).thenReturn(false);

            //stub called with different args:
            String ret = mock.simpleMethod(2);

            //assertion fails due to stub called with different args
            assertEquals("foo", ret);
        }
View Full Code Here

Examples of org.mockitousage.IMethods

    }
   
    @Test
    public void shouldNotShowTypesWhenTypesAreTheSameEvenIfToStringGivesTheSameResult() throws Exception {
        //given
        IMethods mock = mock(IMethods.class);
        mock.simpleMethod(new Foo(10));
       
        try {
            //when
            verify(mock).simpleMethod(new Foo(20));
            fail();
View Full Code Here

Examples of org.mockitousage.IMethods

   
    @Test
    public void shouldSayUnstubbedMethodWasInvokedHere() {
        mock = mock(IMethods.class, RETURNS_SMART_NULLS);
       
        IMethods m = mock.iMethodsReturningMethod();
       
        m.simpleMethod();
    }
View Full Code Here

Examples of org.mockitousage.IMethods

//issue 151
public class StubbingMocksThatAreConfiguredToReturnMocksTest extends TestBase {

    @Test
    public void shouldAllowStubbingMocksConfiguredWithRETURNS_MOCKS() {
        IMethods mock = mock(IMethods.class, RETURNS_MOCKS);
        when(mock.objectReturningMethodNoArgs()).thenReturn(null);
    }
View Full Code Here

Examples of org.mockitousage.IMethods

        when(mock.objectReturningMethodNoArgs()).thenReturn(null);
    }

    @Test
    public void shouldAllowStubbingMocksConfiguredWithRETURNS_MOCKSWithDoApi() {
        IMethods mock = mock(IMethods.class, RETURNS_MOCKS);
        doReturn(null).when(mock).objectReturningMethodNoArgs();
    }
View Full Code Here

Examples of org.mockitousage.IMethods

    public void single_mock_being_serialized_in_different_classloaders_by_multiple_threads() throws ExecutionException, InterruptedException {
        // given
        int iterations = 2;
        int threadingFactor = 200;
        final ExecutorService executorService = Executors.newFixedThreadPool(threadingFactor);
        final IMethods iMethods_that_store_invocations = mock(IMethods.class, withSettings().serializable());

        // when
        for (int i = 0; i <= iterations; i++) {
            List<Future> futures = new ArrayList<Future>(threadingFactor);
            final CyclicBarrier barrier_that_will_wait_until_threads_are_ready = new CyclicBarrier(threadingFactor);

            // prepare all threads by submitting a callable
            //  - that will serialize the mock a 'threadingFactor' times
            //  - that will use the mock a 'threadingFactor' times
            for (int j = 0; j < threadingFactor; j++) {
                // submit a callable that will serialize the mock 'iMethods'
                futures.add(executorService.submit(new Callable<Object>() {
                    public Object call() throws Exception {
                        barrier_that_will_wait_until_threads_are_ready.await();

                        randomCallOn(iMethods_that_store_invocations);

                        return SimpleSerializationUtil.serializeMock(iMethods_that_store_invocations).toByteArray();
                    }
                }));

                // submit a callable that will only use the mock 'iMethods'
                executorService.submit(new Callable<Object>() {
                    public Object call() throws Exception {
                        barrier_that_will_wait_until_threads_are_ready.await();
                        return iMethods_that_store_invocations.longObjectReturningMethod();
                    }
                });
            }

            // ensure we are getting the futures
View Full Code Here

Examples of org.mockitousage.IMethods

        // when
        ByteArrayOutputStream serialized = serializeMock(imethodsMock);

        // then
        IMethods readObject = deserializeMock(serialized, IMethods.class);
        assertTrue(readObject.booleanReturningMethod());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.