How to use method of org.jmock.test.acceptance.WarnAboutMultipleThreadsAcceptanceTests class

Best Jmock-library code snippet using org.jmock.test.acceptance.WarnAboutMultipleThreadsAcceptanceTests.

Run Jmock-library automation tests on LambdaTest cloud grid

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

copy
1package org.jmock.test.acceptance;
2
3import static org.hamcrest.Matchers.equalTo;
4import static org.junit.Assert.assertThat;
5
6import java.lang.Thread.UncaughtExceptionHandler;
7import java.util.ArrayList;
8import java.util.Collections;
9import java.util.List;
10import java.util.concurrent.Executors;
11import java.util.concurrent.ThreadFactory;
12
13import junit.framework.TestCase;
14
15import org.jmock.Expectations;
16import org.jmock.Mockery;
17import org.jmock.lib.concurrent.Blitzer;
18
19public class WarnAboutMultipleThreadsAcceptanceTests extends TestCase {
20    List<Throwable> exceptionsOnBackgroundThreads = Collections.synchronizedList(new ArrayList<Throwable>());
21    
22    Blitzer blitzer = new Blitzer(1, Executors.newFixedThreadPool(1, new ThreadFactory() {
23        public Thread newThread(Runnable r) {
24            Thread t = new Thread(r);
25            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
26                public void uncaughtException(Thread t, Throwable e) {
27                    exceptionsOnBackgroundThreads.add(e);
28                }
29            });
30            return t;
31        }
32    }));
33    
34    public void testKillsThreadsThatTryToCallMockeryThatIsNotThreadSafe() throws InterruptedException {
35        Mockery mockery = new Mockery();
36        
37        final MockedType mock = mockery.mock(MockedType.class, "mock");
38        
39        mockery.checking(new Expectations() {{
40            allowing (mock).doSomething();
41        }});
42        
43        blitzer.blitz(new Runnable() {
44            public void run() {
45                mock.doSomething();
46            }            
47        });
48        
49        assertThat(exceptionsOnBackgroundThreads.size(), equalTo(blitzer.totalActionCount()));
50    }
51    
52    @Override
53    public void tearDown() {
54        blitzer.shutdown();
55    }
56}
57
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)