How to use method of org.easymock.EasyMock class

Best Easymock code snippet using org.easymock.EasyMock.

Run Easymock automation tests on LambdaTest cloud grid

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

copy
1/*******************************************************************************
2 * This file is part of OpenNMS(R).
3 *
4 * Copyright (C) 2012-2014 The OpenNMS Group, Inc.
5 * OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
6 *
7 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
8 *
9 * OpenNMS(R) is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published
11 * by the Free Software Foundation, either version 3 of the License,
12 * or (at your option) any later version.
13 *
14 * OpenNMS(R) is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with OpenNMS(R).  If not, see:
21 *      http://www.gnu.org/licenses/
22 *
23 * For more information contact:
24 *     OpenNMS(R) Licensing <license@opennms.org>
25 *     http://www.opennms.org/
26 *     http://www.opennms.com/
27 *******************************************************************************/
28
29package org.opennms.features.topology.app.internal;
30
31import static org.junit.Assert.assertEquals;
32
33import java.util.ArrayList;
34import java.util.Collection;
35
36import org.easymock.EasyMock;
37import org.junit.Before;
38import org.junit.Ignore;
39import org.junit.Test;
40import org.opennms.core.test.MockLogAppender;
41import org.opennms.features.topology.api.Graph;
42import org.opennms.features.topology.api.GraphContainer;
43import org.opennms.features.topology.api.SelectionListener;
44import org.opennms.features.topology.api.SelectionManager;
45import org.opennms.features.topology.api.topo.AbstractVertex;
46import org.opennms.features.topology.api.topo.Edge;
47import org.opennms.features.topology.api.topo.EdgeRef;
48import org.opennms.features.topology.api.topo.Vertex;
49import org.opennms.features.topology.api.topo.VertexRef;
50import org.opennms.features.topology.app.internal.support.IconRepositoryManager;
51
52import com.vaadin.server.PaintException;
53import com.vaadin.server.PaintTarget;
54
55@Ignore
56public class TopologyComponentTest {
57
58	@Before
59	public void setUp() {
60		MockLogAppender.setupLogging();
61	}
62
63    @Test
64    @Ignore("Figure out how to verify mock paint calls")
65    public void testTopologyComponentGraph() throws PaintException {
66        PaintTarget target = EasyMock.createMock(PaintTarget.class);
67        
68        mockInitialSetup(target);
69        
70        mockDefaultGraph(target);
71        
72        SelectionManager selectionManager = EasyMock.createMock(SelectionManager.class);
73        SelectionListener listener = EasyMock.anyObject();
74        selectionManager.addSelectionListener(listener);
75        EasyMock.expect(selectionManager.isVertexRefSelected(EasyMock.anyObject(VertexRef.class))).andReturn(false).anyTimes();
76        EasyMock.expect(selectionManager.isEdgeRefSelected(EasyMock.anyObject(EdgeRef.class))).andReturn(false).anyTimes();
77        
78        EasyMock.replay(target, selectionManager);
79        
80        TestTopologyProvider topoProvider = new TestTopologyProvider("test");
81        assertEquals(2, topoProvider.getVertices().size());
82        assertEquals(1, topoProvider.getEdges().size());
83        GraphContainer graphContainer = new VEProviderGraphContainer(topoProvider, new ProviderManager());
84        graphContainer.setSelectionManager(selectionManager);
85        TopologyComponent topoComponent = getTopologyComponent(graphContainer);
86        
87        topoComponent.markAsDirty();
88        
89        EasyMock.verify(target, selectionManager);
90    }
91
92    private static TopologyComponent getTopologyComponent(GraphContainer dataSource) {
93        TopologyComponent topologyComponent = new TopologyComponent(dataSource, new IconRepositoryManager(), null);
94        return topologyComponent;
95    }
96    
97    @Test
98    @Ignore("Figure out how to verify mock paint calls")
99    public void testTopologyComponentGraphUpdate() throws PaintException {
100        PaintTarget target = EasyMock.createMock(PaintTarget.class);
101        
102        mockInitialSetup(target);
103        
104        mockGraphTagStart(target);
105        
106        mockVertex(target);
107        
108        mockVertex(target);
109        
110        mockVertex(target);
111        
112        mockEdge(target);
113        
114        mockGraphTagEnd(target);
115        
116        SelectionManager selectionManager = EasyMock.createMock(SelectionManager.class);
117        SelectionListener listener = EasyMock.anyObject();
118        selectionManager.addSelectionListener(listener);
119        EasyMock.expect(selectionManager.getSelectedVertexRefs()).andReturn(new ArrayList<VertexRef>()).anyTimes();
120        EasyMock.expect(selectionManager.isVertexRefSelected(EasyMock.anyObject(VertexRef.class))).andReturn(false).anyTimes();
121        EasyMock.expect(selectionManager.isEdgeRefSelected(EasyMock.anyObject(EdgeRef.class))).andReturn(false).anyTimes();
122        
123        EasyMock.replay(target, selectionManager);
124        
125        TestTopologyProvider topoProvider = new TestTopologyProvider("test");
126        assertEquals(2, topoProvider.getVertices().size());
127        assertEquals(1, topoProvider.getEdges().size());
128        GraphContainer graphContainer = new VEProviderGraphContainer(topoProvider, new ProviderManager());
129        graphContainer.setSelectionManager(selectionManager);
130        TopologyComponent topoComponent = getTopologyComponent(graphContainer);
131        
132        AbstractVertex newVertex = topoProvider.addVertex(0, 0);
133        newVertex.setLabel("New Vertex");
134        assertEquals(3, topoProvider.getVertices().size());
135        assertEquals(1, topoProvider.getEdges().size());
136        /**
137         * TODO This should not be necessary... the container should listen for vertex added events
138         * and redo its own layout.
139         */
140        graphContainer.redoLayout();
141        
142        topoComponent.markAsDirty();
143        
144        EasyMock.verify(target, selectionManager);
145        
146    }
147    
148    @Test
149    @Ignore("Figure out how to verify mock paint calls")
150    public void testTopologyComponentGraphUpdateGroup() throws PaintException {
151        PaintTarget target = EasyMock.createMock(PaintTarget.class);
152        
153        // Initial set up has only the group vertex
154        mockInitialSetup(target);
155        
156        mockGraphTagStart(target);
157        
158        mockVertex(target);
159        
160        mockGraphTagEnd(target);
161        
162        // the set the zoomlevel to 1 and we should see two vertices and an edge
163        //mockGraphAttrs(target, 1, false);
164        // semantic zoom level changes should trigger a fitToView
165        mockGraphAttrs(target, 1, true);
166        
167        mockGraphTagStart(target);
168        
169        mockVertex(target);
170        
171        mockVertex(target);
172        
173        mockEdge(target);
174
175        mockGraphTagEnd(target);
176
177        SelectionManager selectionManager = EasyMock.createMock(SelectionManager.class);
178        SelectionListener listener = EasyMock.anyObject();
179        selectionManager.addSelectionListener(listener);
180        EasyMock.expect(selectionManager.getSelectedVertexRefs()).andReturn(new ArrayList<VertexRef>()).anyTimes();
181        EasyMock.expect(selectionManager.isVertexRefSelected(EasyMock.anyObject(VertexRef.class))).andReturn(false).anyTimes();
182        EasyMock.expect(selectionManager.isEdgeRefSelected(EasyMock.anyObject(EdgeRef.class))).andReturn(false).anyTimes();
183
184        EasyMock.replay(target, selectionManager);
185        
186        TestTopologyProvider topologyProvider = new TestTopologyProvider("test");
187        GraphContainer graphContainer = new VEProviderGraphContainer(topologyProvider, new ProviderManager());
188        graphContainer.setSelectionManager(selectionManager);
189        TopologyComponent topoComponent = getTopologyComponent(graphContainer);
190        
191        Collection<Vertex> vertIds = topologyProvider.getVertices();
192        assertEquals(2, vertIds.size());
193        
194        Vertex groupId = topologyProvider.addGroup(this.getClass().getSimpleName(), "GroupIcon.jpg");
195        
196        for(Vertex v : vertIds) {
197            if(!v.isGroup()) {
198                topologyProvider.setParent(v, groupId);
199            }
200        }
201        
202        assertEquals(3, topologyProvider.getVertices().size());
203        assertEquals(1, topologyProvider.getEdges().size());
204        
205        /**
206         * TODO This should not be necessary... the container should listen for vertex added events
207         * and redo its own layout.
208         */
209        graphContainer.redoLayout();
210        
211        topoComponent.markAsDirty();
212        
213        graphContainer.setSemanticZoomLevel(1);
214        
215        topoComponent.markAsDirty();
216        
217        EasyMock.verify(target, selectionManager);
218        
219    }
220    
221    @Test
222    @Ignore
223    public void testTopologyComponentSendCorrectEdgeIds() throws PaintException {
224        SelectionManager selectionManager = EasyMock.createMock(SelectionManager.class);
225        SelectionListener listener = EasyMock.anyObject();
226        selectionManager.addSelectionListener(listener);
227        EasyMock.expect(selectionManager.isVertexRefSelected(EasyMock.anyObject(VertexRef.class))).andReturn(false).anyTimes();
228        EasyMock.expect(selectionManager.isEdgeRefSelected(EasyMock.anyObject(EdgeRef.class))).andReturn(false).anyTimes();
229        EasyMock.replay(selectionManager);
230
231        TestTopologyProvider topoProvider = new TestTopologyProvider("test");
232        GraphContainer graphContainer = new VEProviderGraphContainer(topoProvider, new ProviderManager());
233        graphContainer.setSelectionManager(selectionManager);
234        TopologyComponent topoComponent = getTopologyComponent(graphContainer);
235        Graph graph = topoComponent.getGraph();
236        
237        Collection<? extends Edge> edges = graph.getDisplayEdges();
238        assertEquals(1, edges.size());
239        
240        Edge edge = edges.iterator().next();
241        
242        PaintTarget target = EasyMock.createMock(PaintTarget.class);
243        
244        mockedDefaultToprData(target);
245        
246        EasyMock.replay(target);
247        
248        //topoComponent.paintContent(target);
249        
250        EasyMock.verify(target);
251        
252        System.err.println("\n****** Right before Creation of a Group ******\n");
253        
254        Collection<Vertex> vertIds = topoProvider.getVertices();
255        
256        Vertex groupId = topoProvider.addGroup(this.getClass().getSimpleName(), "GroupIcon.jpg");
257        
258        for(Vertex v: vertIds) {
259            if(!v.isGroup()) {
260                topoProvider.setParent(v, groupId);
261            }
262            
263        }
264        
265        PaintTarget target2 = EasyMock.createMock(PaintTarget.class);
266        mockInitialSetup(target2);
267        
268        mockGraphTagStart(target2);
269       
270        for(Vertex v : graph.getDisplayVertices()) {
271        	String key = v.getKey();
272        	mockVertexWithKey(target2, key);
273        }
274        
275        for(Edge e: graph.getDisplayEdges()) {
276        	Vertex sourceV = graphContainer.getBaseTopology().getVertex(e.getSource().getVertex(), graphContainer.getCriteria());
277        	Vertex targetV = graphContainer.getBaseTopology().getVertex(e.getTarget().getVertex(), graphContainer.getCriteria());
278            String sourceKey = sourceV.getKey();
279            String targetKey = targetV.getKey();
280            mockEdgeWithKeys(target2, e.getKey(), sourceKey, targetKey);
281        }
282        mockGraphTagEnd(target2);
283        
284        EasyMock.replay(target2);
285        
286        topoComponent.markAsDirty();
287        
288        EasyMock.verify(target2);
289    }
290
291    private static void mockedDefaultToprData(PaintTarget target)
292            throws PaintException {
293        mockInitialSetup(target);
294        
295        mockGraphTagStart(target);
296        
297        mockVertex(target);
298        
299        mockVertex(target);
300        
301        mockEdge(target);
302        
303        mockGraphTagEnd(target);
304        
305    }
306
307    private static void mockInitialSetup(PaintTarget target) throws PaintException {
308    	mockGraphAttrs(target, 0, true);
309    }
310    
311    private static void mockGraphAttrs(PaintTarget target, int semanticZoomLevel, boolean fitToView) throws PaintException {
312        target.addAttribute("activeTool", "pan");
313        
314        target.addAttribute(EasyMock.eq("boundX"), EasyMock.anyInt());
315        target.addAttribute(EasyMock.eq("boundY"), EasyMock.anyInt());
316        target.addAttribute(EasyMock.eq("boundWidth"),EasyMock.anyInt());
317        target.addAttribute(EasyMock.eq("boundHeight"), EasyMock.anyInt());
318    }
319
320    private static void mockDefaultGraph(PaintTarget target) throws PaintException {
321        mockGraphTagStart(target);
322        mockVertex(target);
323        
324        mockVertex(target);
325        
326        mockEdge(target);
327        
328        mockGraphTagEnd(target);
329    }
330
331    private static void mockGraphTagEnd(PaintTarget target) throws PaintException {
332        target.endTag("graph");
333    }
334
335    private static void mockGraphTagStart(PaintTarget target) throws PaintException {
336        target.startTag("graph");
337    }
338
339    private static void mockEdge(PaintTarget target) throws PaintException {
340        target.startTag("edge");
341        target.addAttribute(eq("key"), EasyMock.notNull(String.class));
342        target.addAttribute(eq("source"), EasyMock.notNull(String.class));
343        target.addAttribute(eq("target"), EasyMock.notNull(String.class));
344        target.addAttribute("selected", false);
345        target.addAttribute(eq("cssClass"), EasyMock.notNull(String.class));
346        target.addAttribute(eq("tooltipText"), EasyMock.notNull(String.class));
347        target.endTag("edge");
348    }
349    
350    private static void mockEdgeWithKeys(PaintTarget target, String edgeKey, String sourceId, String targetId) throws PaintException {
351        target.startTag("edge");
352        target.addAttribute("key", edgeKey);
353        target.addAttribute("source", sourceId);
354        target.addAttribute("target", targetId);
355        target.addAttribute(eq("tooltipText"), EasyMock.notNull(String.class));
356        target.endTag("edge");
357    }
358
359    private static void mockVertex(PaintTarget target) throws PaintException {
360        target.startTag("vertex");
361        target.addAttribute(EasyMock.eq("key"), EasyMock.notNull(String.class));
362        target.addAttribute(eq("initialX"), EasyMock.anyInt());
363        target.addAttribute(eq("initialY"), EasyMock.anyInt());
364        target.addAttribute(eq("x"), EasyMock.anyInt());
365        target.addAttribute(eq("y"), EasyMock.anyInt());
366        target.addAttribute(eq("selected"), EasyMock.anyBoolean());
367        target.addAttribute(eq("iconUrl"), EasyMock.notNull(String.class));
368        target.addAttribute(EasyMock.eq("label"), EasyMock.notNull(String.class));
369        target.addAttribute(EasyMock.eq("tooltipText"), EasyMock.notNull(String.class));
370        
371        target.endTag("vertex");
372    }
373    
374    private static void mockVertexWithKey(PaintTarget target, String key) throws PaintException {
375        target.startTag("vertex");
376        target.addAttribute("key", key);
377        target.addAttribute(eq("x"), EasyMock.anyInt());
378        target.addAttribute(eq("y"), EasyMock.anyInt());
379        target.addAttribute(eq("selected"), EasyMock.anyBoolean());
380        target.addAttribute(eq("iconUrl"), EasyMock.notNull(String.class));
381        target.addAttribute("semanticZoomLevel", 1);
382        target.addAttribute(eq("tooltipText"), EasyMock.notNull(String.class));
383        target.addAttribute(eq("label"), EasyMock.notNull(String.class));
384        
385        target.endTag("vertex");
386    }
387
388    private static String eq(String arg) {
389        return EasyMock.eq(arg);
390    }
391
392}
393
Full Screen
copy
1package hudson.plugins.sctmexecutor.service;
2
3import static org.junit.Assert.assertNotNull;
4import static org.junit.Assert.assertTrue;
5import hudson.plugins.sctmexecutor.exceptions.SCTMException;
6
7import java.util.ArrayList;
8
9import org.easymock.EasyMock;
10import org.junit.After;
11import org.junit.Before;
12import org.junit.Test;
13
14import com.borland.sctm.ws.execution.entities.ExecutionHandle;
15import com.borland.sctm.ws.execution.entities.ExecutionResult;
16
17public class TestSCTMReRunProxy {
18  
19  private ISCTMService proxy;
20  private ISCTMService mockService;
21
22  @Before
23  public void setUp() throws Exception {
24    mockService = EasyMock.createStrictMock(ISCTMService.class);
25    proxy = new SCTMReRunProxy(mockService);
26  }
27
28  @After
29  public void tearDown() throws Exception {
30    EasyMock.verify(mockService);
31    proxy = null;
32    mockService = null;
33  }
34
35  @Test
36  public void testGetExecutionResult() throws SCTMException {
37    EasyMock.expect(mockService.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andThrow(new SCTMException(""));
38    EasyMock.expectLastCall().andThrow(new SCTMException(""));
39    EasyMock.expectLastCall().andReturn(new ExecutionResult());   
40    EasyMock.replay(mockService);
41    assertNotNull(proxy.getExecutionResult(new ExecutionHandle()));
42    EasyMock.verify(mockService);
43  }
44  
45  @Test(expected=SCTMException.class)
46  public void testGetExecutionResultReRunFailed() throws SCTMException {
47    EasyMock.expect(mockService.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andThrow(new SCTMException(""));
48    for (int i=0; i<SCTMReRunProxy.MAXRERUN; i++)
49      EasyMock.expectLastCall().andThrow(new SCTMException(""));
50    
51    EasyMock.replay(mockService);
52    assertNotNull(proxy.getExecutionResult(new ExecutionHandle()));
53  }
54
55  @Test
56  public void testIsFinished() throws SCTMException {
57    EasyMock.expect(mockService.isFinished((ExecutionHandle)EasyMock.notNull())).andThrow(new SCTMException(""));
58    EasyMock.expectLastCall().andThrow(new SCTMException(""));
59    EasyMock.expectLastCall().andReturn(true);
60    EasyMock.replay(mockService);
61    assertTrue(proxy.isFinished(new ExecutionHandle()));
62  }
63  
64  @Test(expected=SCTMException.class)
65  public void testIsFinishedReRunFailed() throws SCTMException {
66    EasyMock.expect(mockService.isFinished((ExecutionHandle)EasyMock.notNull())).andThrow(new SCTMException(""));
67    for (int i=0; i<SCTMReRunProxy.MAXRERUN; i++)
68      EasyMock.expectLastCall().andThrow(new SCTMException(""));
69    
70    EasyMock.replay(mockService);
71    assertTrue(proxy.isFinished(new ExecutionHandle()));
72  }
73
74  @Test
75  public void testStartInt() throws SCTMException {
76    EasyMock.expect(mockService.start(EasyMock.gt(0))).andThrow(new SCTMException(""));
77    EasyMock.expectLastCall().andThrow(new SCTMException(""));
78    EasyMock.expectLastCall().andReturn(new ArrayList<ExecutionHandle>());
79    EasyMock.replay(mockService);
80    assertNotNull(proxy.start(12345));
81  }
82  
83  @Test(expected=SCTMException.class)
84  public void testStartIntReRunFailed() throws SCTMException {
85    EasyMock.expect(mockService.start(EasyMock.gt(0))).andThrow(new SCTMException(""));
86    for (int i=0; i<SCTMReRunProxy.MAXRERUN; i++)
87      EasyMock.expectLastCall().andThrow(new SCTMException(""));
88
89    EasyMock.replay(mockService);
90    assertNotNull(proxy.start(12345));
91  }
92
93  @Test
94  public void testStartIntString() throws SCTMException {
95    EasyMock.expect(mockService.start(EasyMock.gt(0), (String)EasyMock.notNull())).andThrow(new SCTMException(""));
96    EasyMock.expectLastCall().andThrow(new SCTMException(""));
97    EasyMock.expectLastCall().andReturn(new ArrayList<ExecutionHandle>());
98    EasyMock.replay(mockService);
99    assertNotNull(proxy.start(12345, ""));
100  }
101  
102  @Test(expected=SCTMException.class)
103  public void testStartIntStringReRunFailed() throws SCTMException {
104    EasyMock.expect(mockService.start(EasyMock.gt(0), (String)EasyMock.notNull())).andThrow(new SCTMException(""));
105    for (int i=0; i<SCTMReRunProxy.MAXRERUN; i++)
106      EasyMock.expectLastCall().andThrow(new SCTMException(""));
107
108    EasyMock.replay(mockService);
109    assertNotNull(proxy.start(12345, ""));
110  }
111
112}
113
Full Screen
copy
1package hudson.plugins.sctmexecutor;
2
3import static org.junit.Assert.assertTrue;
4import hudson.plugins.sctmexecutor.exceptions.SCTMException;
5import hudson.plugins.sctmexecutor.service.ISCTMService;
6
7import java.io.FileNotFoundException;
8import java.io.PrintStream;
9import java.rmi.RemoteException;
10import java.util.ArrayList;
11import java.util.Collection;
12
13import org.easymock.EasyMock;
14import org.junit.Test;
15
16import com.borland.sctm.ws.execution.entities.ExecutionHandle;
17import com.borland.sctm.ws.execution.entities.ExecutionResult;
18import com.borland.sctm.ws.execution.entities.TestDefinitionResult;
19
20public class TestResultCollector {
21  
22  private static final int DEFAULT_BUILDNUMBER = -1;
23
24  @Test
25  public void collectingResults() throws SCTMException, FileNotFoundException {
26    ISCTMService serviceMock = createServiceMock();
27    ExecutionResult result = createDummyResult();
28    EasyMock.expect(serviceMock.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andReturn(result);
29    
30    ITestResultWriter resultWriterMock = EasyMock.createStrictMock(ITestResultWriter.class);
31    resultWriterMock.write(result);
32    
33    ExecutionRunnable aut = new ExecutionRunnable(serviceMock, 1, DEFAULT_BUILDNUMBER, resultWriterMock, new PrintStream("test.log"));
34    aut.setResultCollectingDelay(1);
35    
36    EasyMock.replay(serviceMock);
37    EasyMock.replay(resultWriterMock);
38    aut.run();
39    EasyMock.verify(serviceMock);
40    EasyMock.verify(resultWriterMock);
41  }
42  
43  @Test
44  public void runCollectorThread() throws SCTMException, FileNotFoundException {
45    ISCTMService serviceMock = EasyMock.createStrictMock(ISCTMService.class);
46    Collection<ExecutionHandle> handles = new ArrayList<ExecutionHandle>();
47    handles.add(new ExecutionHandle(1, System.currentTimeMillis()));
48    EasyMock.expect(serviceMock.getExecDefinitionName(EasyMock.anyInt())).andReturn("ExecDefName");
49    EasyMock.expect(serviceMock.start(EasyMock.eq(1), EasyMock.cmpEq("1234"))).andReturn(handles);
50    EasyMock.expect(serviceMock.isFinished((ExecutionHandle) EasyMock.notNull())).andReturn(false);
51    EasyMock.expectLastCall().times(2).andReturn(false);
52    EasyMock.expectLastCall().andReturn(true);
53    ExecutionResult result = createDummyResult();
54    EasyMock.expect(serviceMock.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andReturn(result);
55    
56    ITestResultWriter resultWriterMock = EasyMock.createStrictMock(ITestResultWriter.class);
57    resultWriterMock.write(result);
58    
59    ExecutionRunnable aut = new ExecutionRunnable(serviceMock, 1, 1234, resultWriterMock, new PrintStream("test.log"));
60    aut.setResultCollectingDelay(1);
61    
62    EasyMock.replay(serviceMock);
63    EasyMock.replay(resultWriterMock);
64    long start = System.currentTimeMillis();
65    aut.run();
66    long duration = (System.currentTimeMillis()-start)/1000;
67    assertTrue(duration > 8 && duration < 16);
68    EasyMock.verify(serviceMock);
69    EasyMock.verify(resultWriterMock);
70  }
71  
72  @Test(expected=RuntimeException.class)
73  public void testBadRun() throws Exception {
74    ISCTMService serviceMock = EasyMock.createStrictMock(ISCTMService.class);
75    EasyMock.expect(serviceMock.isFinished((ExecutionHandle) EasyMock.notNull())).andThrow(new RemoteException());
76    
77    ExecutionRunnable aut = new ExecutionRunnable(serviceMock, 1, DEFAULT_BUILDNUMBER, null, new PrintStream("test.log"));
78    aut.setResultCollectingDelay(1);
79    
80    EasyMock.replay(serviceMock);
81    aut.run();
82    EasyMock.verify(serviceMock);
83  }
84  
85  @Test(expected=RuntimeException.class)
86  public void testBadResult() throws Exception {
87    ISCTMService serviceMock = createServiceMock();
88    EasyMock.expect(serviceMock.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andThrow(new RemoteException());
89    EasyMock.expect(serviceMock.isFinished((ExecutionHandle) EasyMock.notNull())).andReturn(true);
90    EasyMock.expect(serviceMock.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andThrow(new RemoteException());
91    EasyMock.expect(serviceMock.isFinished((ExecutionHandle) EasyMock.notNull())).andReturn(true);
92    EasyMock.expect(serviceMock.getExecutionResult((ExecutionHandle)EasyMock.notNull())).andThrow(new RemoteException());
93    
94    ExecutionRunnable aut = new ExecutionRunnable(serviceMock, 1, DEFAULT_BUILDNUMBER, null, new PrintStream("test.log"));
95    aut.setResultCollectingDelay(1);
96    
97    EasyMock.replay(serviceMock);
98    aut.run();
99    EasyMock.verify(serviceMock);
100  }
101  
102  private ExecutionResult createDummyResult() {
103    TestDefinitionResult cleanUp = new TestDefinitionResult(1, 0, 1, "test", "", 1, 1, 1, 1, 0);
104    TestDefinitionResult setup = new TestDefinitionResult(1, 0, 1, "test", "", 1, 1, 1, 1, 0);
105    TestDefinitionResult[] results = new TestDefinitionResult[] {
106        new TestDefinitionResult(1, 0, 1, "test", "", 1, 1, 1, 1, 0),
107        new TestDefinitionResult(1, 0, 1, "test", "", 1, 1, 1, 1, 0)
108    };
109    ExecutionResult result = new ExecutionResult("test", cleanUp, 10, "testExecDef", "unknown", new String[] {"unknown"}, "", setup, results);
110    return result;
111  }
112
113  private ISCTMService createServiceMock() throws SCTMException {
114    ISCTMService serviceMock = EasyMock.createStrictMock(ISCTMService.class);
115    Collection<ExecutionHandle> handles = new ArrayList<ExecutionHandle>();
116    handles.add(new ExecutionHandle(1, System.currentTimeMillis()));
117    
118    EasyMock.expect(serviceMock.getExecDefinitionName(EasyMock.anyInt())).andReturn("ExecDef");
119//    EasyMock.expect(serviceMock.buildNumberExists(EasyMock.eq(DEFAULT_BUILDNUMBER))).andReturn(false);
120//    serviceMock.addBuildNumber(EasyMock.eq(DEFAULT_BUILDNUMBER));
121    EasyMock.expect(serviceMock.start(EasyMock.gt(0))).andReturn(handles );
122    EasyMock.expect(serviceMock.isFinished((ExecutionHandle) EasyMock.notNull())).andReturn(false);
123    EasyMock.expectLastCall().andReturn(true);
124    return serviceMock;
125  }
126
127//  private ITestResultWriter createTestResultWriterMock(ExecutionResult result) throws SCTMException {
128//    ITestResultWriter resultWriterMock = EasyMock.createStrictMock(ITestResultWriter.class);
129//    resultWriterMock.write(result);
130//    return resultWriterMock;
131//  }
132
133}
134
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
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)