How to use method of org.easymock.samples.EnclosedTest class

Best Easymock code snippet using org.easymock.samples.EnclosedTest.

Run Easymock automation tests on LambdaTest cloud grid

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

copy
1/**
2 * Copyright 2001-2015 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.easymock.samples;
17
18import org.easymock.EasyMockRunner;
19import org.easymock.EasyMockSupport;
20import org.easymock.Mock;
21import org.easymock.TestSubject;
22import org.easymock.samples.ClassTested;
23import org.easymock.samples.Collaborator;
24import org.junit.Before;
25import org.junit.Test;
26import org.junit.experimental.runners.Enclosed;
27import org.junit.runner.RunWith;
28
29import static org.easymock.EasyMock.expect;
30import static org.junit.Assert.assertFalse;
31import static org.junit.Assert.assertTrue;
32
33/**
34 * Test demonstrating the use of JUnit 4.12 new enclosed feature
35 *
36 * @author Henri Tremblay
37 */
38@RunWith(Enclosed.class)
39public class EnclosedTest {
40
41    @RunWith(EasyMockRunner.class)
42    public static abstract class Fixtures extends EasyMockSupport {
43
44        @TestSubject
45        ClassTested classUnderTest = new ClassTested();
46
47        @Mock
48        Collaborator mock;
49    }
50
51    public static class VoteRemoval extends Fixtures {
52
53        @Before
54        public void when() {
55            // expect document addition
56            mock.documentAdded("Document");
57        }
58
59        @Test
60        public void voteForRemoval() {
61            // expect to be asked to vote, and vote for it
62            expect(mock.voteForRemoval("Document")).andReturn((byte) 42);
63            // expect document removal
64            mock.documentRemoved("Document");
65
66            replayAll();
67            classUnderTest.addDocument("Document", "content");
68            assertTrue(classUnderTest.removeDocument("Document"));
69            verifyAll();
70        }
71
72        @Test
73        public void voteAgainstRemoval() {
74            // expect to be asked to vote, and vote against it
75            expect(mock.voteForRemoval("Document")).andReturn((byte) -42); //
76            // document removal is *not* expected
77
78            replayAll();
79            classUnderTest.addDocument("Document", "content");
80            assertFalse(classUnderTest.removeDocument("Document"));
81            verifyAll();
82        }
83    }
84
85    public static class VoteRemovals extends Fixtures {
86
87        @Before
88        public void when() {
89            mock.documentAdded("Document 1");
90            mock.documentAdded("Document 2");
91        }
92
93        @Test
94        public void voteForRemovals() {
95            expect(mock.voteForRemovals("Document 1", "Document 2")).andReturn((byte) 42);
96            mock.documentRemoved("Document 1");
97            mock.documentRemoved("Document 2");
98            replayAll();
99            classUnderTest.addDocument("Document 1", "content 1");
100            classUnderTest.addDocument("Document 2", "content 2");
101            assertTrue(classUnderTest.removeDocuments(new String[] { "Document 1", "Document 2" }));
102            verifyAll();
103        }
104
105        @Test
106        public void voteAgainstRemovals() {
107            expect(mock.voteForRemovals("Document 1", "Document 2")).andReturn((byte) -42);
108            replayAll();
109            classUnderTest.addDocument("Document 1", "content 1");
110            classUnderTest.addDocument("Document 2", "content 2");
111            assertFalse(classUnderTest.removeDocuments("Document 1", "Document 2"));
112            verifyAll();
113        }
114    }
115}
116
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)