Package org.jmock

Examples of org.jmock.States


    @Test
    public void testDownloadFileLarge() throws IOException
    {
        setupForDownloadFileTests();

        final States state = context.states("readStep").startsAs("1");
        context.checking(new Expectations()
        {
            {
                oneOf(httpReader).read(with(any(char[].class)), with(any(int.class)), with(any(int.class)));
                when(state.is("1"));
                then(state.is("2"));
                will(new ReadAction("ABCDEFGHIJ"));

                oneOf(httpReader).read(with(any(char[].class)), with(any(int.class)), with(any(int.class)));
                when(state.is("2"));
                then(state.is("3"));
                will(new ReadAction("abcdefghij"));

                oneOf(httpReader).read(with(any(char[].class)));
                when(state.is("3"));
                then(state.is("4"));
                will(new ReadAction("MMM"));

                oneOf(httpReader).read(with(any(char[].class)));
                when(state.is("4"));
                then(state.is("5"));
                will(new ReadAction("ZZZ"));

                oneOf(httpReader).read(with(any(char[].class)));
                when(state.is("5"));
                then(state.is("6"));
                will(returnValue(-1));

                oneOf(httpReader).close();
                when(state.is("6"));
                then(state.is("E"));
            }
        });

        assertEquals("ABCDEFGHIJabcdefghijMMMZZZ", sut.downloadFile(URL, ACCOUNT_ID));
View Full Code Here


    @Test(expected = AssertionError.class)
    public void testDownloadFileTooLarge() throws IOException
    {
        setupForDownloadFileTests();

        final States state = context.states("readStep").startsAs("1");
        context.checking(new Expectations()
        {
            {
                oneOf(httpReader).read(with(any(char[].class)), with(any(int.class)), with(any(int.class)));
                when(state.is("1"));
                then(state.is("2"));
                will(new ReadAction("ABCDEFGHIJabcdefghij"));

                oneOf(httpReader).read(with(any(char[].class)));
                when(state.is("2"));
                then(state.is("3"));
                will(new ReadAction("01234567890123456789"));

                oneOf(httpReader).read(with(any(char[].class)));
                when(state.is("3"));
                then(state.is("4"));
                will(new ReadAction("AbCdEfGhIjK"));
            }
        });

        sut.downloadFile(URL, ACCOUNT_ID);
View Full Code Here

    /**
     * Starts the timer.
     */
    private void setupToRun()
    {
        final States state = context.states("setupSegregator").startsAs("setup");
        context.checking(new Expectations()
        {
            {
                oneOf(timer).scheduleRepeating(with(any(Integer.class)));
                when(state.is("setup"));
            }
        });
        sut.start();
        state.become("");

incrementTime();
    }
View Full Code Here

        sut.register(action1, 2);
        sut.register(action2, 3);

        TimerHandler hdlr = timerHandlerInt.getObject();

        final States state = context.states("time").startsAs("1");
        context.checking(new Expectations()
        {
            {
                oneOf(action1).run();
                when(state.is("3"));
                oneOf(action1).run();
                when(state.is("5"));
                oneOf(action1).run();
                when(state.is("7"));
                oneOf(action1).run();
                when(state.is("9"));
                oneOf(action1).run();
                when(state.is("11"));

                oneOf(action2).run();
                when(state.is("4"));
                oneOf(action2).run();
                when(state.is("7"));
                oneOf(action2).run();
                when(state.is("10"));

                allowing(actionProcessor).setQueueRequests(true);
                allowing(actionProcessor).fireQueuedRequests();
                allowing(actionProcessor).setQueueRequests(false);
            }
        });

        for (int i = 2; i <= 9 + 3; i++)
        {
            incrementTime();
            state.become(Integer.toString(i));
            hdlr.run();
        }

        context.assertIsSatisfied();
    }
View Full Code Here

        // Will become idle at time = 15
        sut.register(action1, 0);

        TimerHandler hdlr = timerHandlerInt.getObject();

        final States state = context.states("time").startsAs("notLast");
        context.checking(new Expectations()
        {
            {
                exactly(IDLE_TIMEOUT - 1).of(action1).run();
                when(state.is("notLast"));

                oneOf(timer).cancel();
                when(state.is("last"));

                allowing(actionProcessor).setQueueRequests(true);
                allowing(actionProcessor).fireQueuedRequests();
                allowing(actionProcessor).setQueueRequests(false);
            }
        });

        for (int i = 1; i <= IDLE_TIMEOUT; i++)
        {
            if (i == IDLE_TIMEOUT)
            {
                state.become("last");
            }
            hdlr.run();

            incrementTime();
        }
View Full Code Here

        // At this point, time = 1
        // Will become idle at time = 15, except activty at 3 will bump it to 18

        TimerHandler hdlr = timerHandlerInt.getObject();

        final States state = context.states("time").startsAs("notLast");
        context.checking(new Expectations()
        {
            {
                oneOf(timer).cancel();
                when(state.is("last"));
            }
        });

        for (int i = 1; i <= IDLE_TIMEOUT + activityAtTime; i++)
        {
            if (i == IDLE_TIMEOUT + activityAtTime)
            {
                state.become("last");
            }
            if (i == activityAtTime)
            {
                sut.userActivityDetected();
            }
View Full Code Here

        TimerHandler hdlr = timerHandlerInt.getObject();

        // At this point, time = 1
        // Will become idle at time = 15
        final States state = context.states("time").startsAs("makeIdle");
        context.checking(new Expectations()
        {
            {
                oneOf(timer).cancel();
                when(state.is("makeIdle"));
            }
        });
        for (int i = 1; i <= IDLE_TIMEOUT; i++)
        {
            if (i == IDLE_TIMEOUT)
            {
                state.become("makeIdle");
            }
            hdlr.run();

            incrementTime();
        }
View Full Code Here

TOP

Related Classes of org.jmock.States

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.