@Test public void testNext() { boolean expected = true; EasyMock.expect(peekIterator.hasNext()).andReturn(expected).times(4); String defaultString = "S1"; String resString = "S2"; EasyMock.expect(peekIterator.next()).andReturn(defaultString); EasyMock.expect(binaryFn.apply(EasyMock.eq(defaultString), EasyMock.isNull())) .andReturn(resString); EasyMock.expect(peekIterator.next()).andReturn(defaultString); EasyMock.expect(comparator.compare(EasyMock.eq(resString), EasyMock.eq(defaultString))) .andReturn(0); EasyMock.expect(peekIterator.next()).andReturn(defaultString); EasyMock.expect(binaryFn.apply(EasyMock.eq(resString), EasyMock.eq(defaultString))) .andReturn(resString); EasyMock.expect(comparator.compare(EasyMock.eq(resString), EasyMock.eq(defaultString))) .andReturn(1); EasyMock.replay(peekIterator); EasyMock.replay(binaryFn); EasyMock.replay(comparator); String actual = testingIterator.next(); Assert.assertEquals(resString, actual); EasyMock.verify(peekIterator); EasyMock.verify(comparator); EasyMock.verify(binaryFn); }
@Before public void setUp() throws IOException { SERVICE_EMITTER.flush(); EVENT_EMITS.set(0L); EasyMock.reset(lookupNodeDiscovery); EasyMock.reset(configManager); EasyMock.expect( configManager.watch( EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull() ) ).andReturn( new AtomicReference<>(null) ).anyTimes(); EasyMock.expect( configManager.watch( EasyMock.eq(LookupCoordinatorManager.OLD_LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull() ) ).andReturn( new AtomicReference<>(null) ).anyTimes(); EasyMock.replay(configManager); }
EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull() )).andReturn( new AtomicReference<Map<String, Map<String, Map<String, Object>>>>(null)).once(); EasyMock.eq(LookupCoordinatorManager.OLD_LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull()
EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull()
EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull() )).andReturn(new AtomicReference<List<LookupExtractorFactoryMapContainer>>(null)).once(); EasyMock.eq(LookupCoordinatorManager.OLD_LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull() )).andReturn(new AtomicReference<List<Map<String, Object>>>(null)).once();
@Test public void testCreateSnapshotWithOptions() { Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance(); EasyMock.expect( computeRpcMock.createSnapshot( eq(DISK_ID.getZone()), eq(DISK_ID.getDisk()), eq(SNAPSHOT_ID.getSnapshot()), EasyMock.<String>isNull(), capture(capturedOptions))) .andReturn(zoneOperation.toPb()); EasyMock.replay(computeRpcMock); compute = options.getService(); Operation operation = compute.create(SNAPSHOT, OPERATION_OPTION_FIELDS); String selector = (String) capturedOptions.getValue().get(OPERATION_OPTION_FIELDS.getRpcOption()); assertTrue(selector.contains("selfLink")); assertTrue(selector.contains("id")); assertTrue(selector.contains("description")); assertEquals(23, selector.length()); assertEquals(zoneOperation, operation); }
final LoadQueuePeon mockPeon2 = createEmptyPeon(); mockPeon2.loadSegment(EasyMock.anyObject(), EasyMock.isNull()); EasyMock.expectLastCall().once();
EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull() )).andReturn( new AtomicReference<>(Collections.EMPTY_MAP)).anyTimes();
public final void testDispatchThruGuiceFilter() throws ServletException, IOException { //create mocks FilterConfig filterConfig = createMock(FilterConfig.class); ServletContext servletContext = createMock(ServletContext.class); HttpServletRequest request = createMock(HttpServletRequest.class); FilterChain proceedingFilterChain = createMock(FilterChain.class); //begin mock script *** expect(filterConfig.getServletContext()).andReturn(servletContext).once(); expect(request.getRequestURI()).andReturn("/public/login.jsp").anyTimes(); expect(request.getContextPath()).andReturn("").anyTimes(); //at the end, proceed down webapp's normal filter chain proceedingFilterChain.doFilter(isA(HttpServletRequest.class), (ServletResponse) isNull()); expectLastCall().once(); //run mock script *** replay(filterConfig, servletContext, request, proceedingFilterChain); final GuiceFilter webFilter = new GuiceFilter(); webFilter.init(filterConfig); webFilter.doFilter(request, null, proceedingFilterChain); webFilter.destroy(); //assert expectations verify(filterConfig, servletContext, request, proceedingFilterChain); }
/** * The {@link com.googlecode.jsonrpc4j.JsonRpcBasicServer} is able to have an instance of * {@link com.googlecode.jsonrpc4j.InvocationListener} configured for it. Prior to a * method being invoked, the lister is notified and after the method is invoked, the * listener is notified. This test checks that these two events are hit correctly * when a method is invoked. */ @SuppressWarnings("unchecked") @Test public void callMethodWithInvocationListener() throws Exception { final InvocationListener invocationListener = EasyMock.niceMock(InvocationListener.class); Method m = ServiceInterface.class.getMethod("throwsMethod", String.class); invocationListener.willInvoke(eq(m), anyObject(List.class)); invocationListener.didInvoke(eq(m), anyObject(List.class), EasyMock.notNull(), EasyMock.<Throwable>isNull(), EasyMock.geq(0L)); jsonRpcServer.setInvocationListener(invocationListener); EasyMock.expect(mockService.throwsMethod(param1)).andReturn(param1); EasyMock.replay(mockService, invocationListener); jsonRpcServer.handleRequest(messageWithListParamsStream(1, "throwsMethod", param1), byteArrayOutputStream); EasyMock.verify(invocationListener, mockService); JsonNode json = decodeAnswer(byteArrayOutputStream); assertEquals(param1, json.get(JsonRpcBasicServer.RESULT).textValue()); assertNull(json.get(JsonRpcBasicServer.ERROR)); }
/** * The {@link com.googlecode.jsonrpc4j.JsonRpcBasicServer} is able to have an instance of * {@link com.googlecode.jsonrpc4j.InvocationListener} configured for it. Prior to a * method being invoked, the lister is notified and after the method is invoked, the * listener is notified. This test checks that these two events are hit correctly in * the case that an exception is raised when the method is invoked. */ @Test @SuppressWarnings("unchecked") public void callMethodThrowingWithInvocationListener() throws Exception { final InvocationListener invocationListener = EasyMock.niceMock(InvocationListener.class); Method m = ServiceInterface.class.getMethod("throwsMethod", String.class); invocationListener.willInvoke(eq(m), anyObject(List.class)); invocationListener.didInvoke(eq(m), anyObject(List.class), EasyMock.isNull(), EasyMock.<Throwable>notNull(), EasyMock.geq(0L)); jsonRpcServer.setInvocationListener(invocationListener); EasyMock.expect(mockService.throwsMethod(param1)).andThrow(new CustomTestException(param1)); EasyMock.replay(mockService, invocationListener); jsonRpcServer.handleRequest(messageWithListParamsStream(1, "throwsMethod", param1), byteArrayOutputStream); EasyMock.verify(invocationListener, mockService); JsonNode json = decodeAnswer(byteArrayOutputStream); assertNull(json.get(JsonRpcBasicServer.RESULT)); assertNotNull(json.get(JsonRpcBasicServer.ERROR)); }
@Test public void conditionIsTrue() throws Exception { Document doc = documentProvider.createDocument(null, null, null); // Create a mock tag; the name doesn't truly matter Element tag = doc.createElement("if"); tag.setAttribute(IfTagHandler.CONDITION_ATTR, "fakeExpression"); processor.expressionResults = ImmutableMap.of("fakeExpression", true); processor.processChildNodes((Node) isNull(), same(tag)); replay(processor); handler.process(null, tag, processor); verify(processor); }
@Test public void conditionIsTrue() throws Exception { Document doc = documentProvider.createDocument(null, null, null); // Create a mock tag; the name doesn't truly matter Element tag = doc.createElement("if"); tag.setAttribute(IfTagHandler.CONDITION_ATTR, "fakeExpression"); processor.expressionResults = ImmutableMap.of("fakeExpression", true); processor.processChildNodes((Node) isNull(), same(tag)); replay(processor); handler.process(null, tag, processor); verify(processor); }
@SuppressWarnings("unchecked") private FeatureRegistry mockRegistry(LookupResult lookupMock) { FeatureRegistry result = createMock(FeatureRegistry.class); expect(result.getFeatureResources( isA(GadgetContext.class), isA(List.class), EasyMock.isNull(List.class))). andReturn(lookupMock).anyTimes(); replay(result); return result; }
private void expectReq(String feature, String content) { FeatureResource resource = new FeatureResource.Simple(content, "", "js"); Collection<String> libs = Lists.newArrayList(feature); List<String> loaded = ImmutableList.of(); List<FeatureResource> resources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(resources).anyTimes(); replay(lr); expect(registry.getFeatureResources(isA(GadgetContext.class), eq(libs), EasyMock.<List<String>>isNull())).andReturn(lr).anyTimes(); } }
@Test public void getValueFromTag() { Element element = document.createElement("test"); element.setAttribute("key", "expression"); expect(templateProcessor.evaluate(eq("expression"), eq(String.class), (String) isNull())) .andReturn("evaluated"); replay(templateProcessor); assertEquals("evaluated", handler.getValueFromTag(element, "key", templateProcessor, String.class)); verify(templateProcessor); }
@Test public void getValueFromTag() { Element element = document.createElement("test"); element.setAttribute("key", "expression"); expect(templateProcessor.evaluate(eq("expression"), eq(String.class), (String) isNull())) .andReturn("evaluated"); replay(templateProcessor); assertEquals("evaluated", handler.getValueFromTag(element, "key", templateProcessor, String.class)); verify(templateProcessor); }
@SuppressWarnings("unchecked") private void setupMockRegistry(List<String> features) { EasyMock.expect(mockRegistry.getFeatures(EasyMock.isA(Collection.class))) .andReturn(Lists.newArrayList(features)).anyTimes(); FeatureBundle featureBundle = createMockFeatureBundle(); FeatureRegistry.LookupResult lr = createMockLookupResult(ImmutableList.of(featureBundle)); EasyMock.expect( mockRegistry.getFeatureResources(isA(GadgetContext.class), eq(Lists.newArrayList(features)), EasyMock.<List<String>> isNull())) .andReturn(lr).anyTimes(); replay(); }
public void testExecuteOK() { ServerActionResultData results = encoder.createServerActionResult((Naked) eq(adapter), aryEq(new ObjectData[0]), aryEq(new ReferenceData[0]), (ObjectData) isNull(), aryEq(new ObjectData[0]), aryEq(new String[0]), aryEq(new String[0])); expectLastCall().andReturn(null); replay(encoder, action); ServerActionResultData result = server.executeServerAction(new NullSession(), NakedObjectAction.USER.getName(), Movie.class.getName() + "#action()", targetData, parameterData); verify(encoder, action); assertEquals(results, result); }