How to use method of org.jmock.lib.legacy.ClassImposteriser class

Best Jmock-library code snippet using org.jmock.lib.legacy.ClassImposteriser.

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package net.jxta.util;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5import static org.junit.Assert.assertNull;
6
7import java.io.IOException;
8import java.util.concurrent.TimeUnit;
9
10import net.jxta.test.util.JUnitRuleMockery;
11
12import org.jmock.Expectations;
13import org.jmock.lib.legacy.ClassImposteriser;
14import org.junit.Before;
15import org.junit.Rule;
16import org.junit.Test;
17
18public class QueuingServerPipeAcceptorTest {
19
20    @Rule
21    public JUnitRuleMockery mockContext = new JUnitRuleMockery() {{
22        setImposteriser(ClassImposteriser.INSTANCE);
23    }};
24
25    private static final int BACKLOG = 10;
26    QueuingServerPipeAcceptor acceptor;
27
28    @Before
29    public void setUp() throws Exception {
30        acceptor = new QueuingServerPipeAcceptor(BACKLOG, 100);
31    }
32
33    @Test
34    public void testDiscardsConnectionsBeyondBacklog() throws Exception {
35        for(int i=0; i < BACKLOG; i++) {
36            acceptor.pipeAccepted(createPipe("pipe" + i));
37        }
38
39        // add one last one, which should be ignored
40        acceptor.pipeAccepted(createPipe("pipeToIgnore"));
41
42        for(int i=0; i < BACKLOG; i++) {
43            assertNotNull(acceptor.accept(0L, TimeUnit.MILLISECONDS));
44        }
45
46        assertNull(acceptor.accept(0L, TimeUnit.MILLISECONDS));
47    }
48
49    @Test
50    public void testSetTimeoutBackwardsCompatible() {
51    	acceptor.setTimeoutBackwardsCompatible(5000);
52    	assertEquals(5000, acceptor.getTimeout());
53    }
54
55    @Test
56    public void testSetTimeoutBackwardsCompatible_toZero() {
57    	// zero is equivalent to "no timeout"
58    	acceptor.setTimeoutBackwardsCompatible(0);
59    	assertEquals(Long.MAX_VALUE, acceptor.getTimeout());
60    }
61
62    @Test(expected=IllegalArgumentException.class)
63    public void testSetTimeoutBackwardsCompatible_toNegative() {
64    	acceptor.setTimeoutBackwardsCompatible(-1);
65    }
66
67    private JxtaBiDiPipe createPipe(String name) throws IOException {
68        final JxtaBiDiPipe mockedPipe = mockContext.mock(JxtaBiDiPipe.class, name);
69        mockContext.checking(new Expectations() {{
70            ignoring(mockedPipe);
71        }});
72
73        return mockedPipe;
74    }
75
76}
77
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)