private void givenDelegateWillReturn(final String line) { EasyMock.expect(parsedLine.line()).andReturn(line).anyTimes(); EasyMock.expect(delegate.parse(anyObject(), anyInt(), anyObject())).andReturn(parsedLine); EasyMock.replay(delegate, parsedLine); }
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.emptyList()); EasyMock.replay(runner);
EasyMock.anyString(), EasyMock.anyObject(Interval.class), EasyMock.anyInt()
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.emptyList()); EasyMock.replay(runner);
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.emptyList()); EasyMock.replay(runner);
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.emptyList()); EasyMock.replay(runner);
@Test public void shouldMatchAvroFormatter() throws Exception { // Given: final Schema schema = parseAvroSchema( "{\n" + " \"fields\": [\n" + " { \"name\": \"str1\", \"type\": \"string\" }\n" + " ],\n" + " \"name\": \"myrecord\",\n" + " \"type\": \"record\"\n" + "}"); final GenericData.Record avroRecord = new GenericData.Record(schema); avroRecord.put("str1", "My first string"); expect(schemaRegistryClient.register(anyString(), anyObject())).andReturn(1); expect(schemaRegistryClient.getById(anyInt())).andReturn(schema).times(2); replay(schemaRegistryClient); final byte[] avroData = serializeAvroRecord(avroRecord); // When: final Result result = getFormatter(avroData); // Then: assertThat(result.format, is(Format.AVRO)); assertThat(result.formatted, endsWith(", key, {\"str1\": \"My first string\"}\n")); }
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.singletonList(new TestZkWorker(testTask).getWorker())); EasyMock.expect(runner.getLazyWorkers()).andReturn(new ArrayList<>());
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.singletonList(new TestZkWorker(testTask).getWorker())); EasyMock.expect(runner.getLazyWorkers()).andReturn(new ArrayList<>());
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.singletonList(new TestZkWorker(testTask).toImmutable().getWorker())); EasyMock.replay(runner);
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())) .andReturn(Collections.singletonList(new TestZkWorker(testTask).getWorker())); EasyMock.replay(runner);
private OffsetResponse mockOffsetResponse(List<MyMessage> myMessages) { OffsetResponse offsetResponse = EasyMock.createMock(OffsetResponse.class); mocks.add(offsetResponse); // The first call is getLatestOffset, we set the value to 1 EasyMock.expect(offsetResponse.offsets(EasyMock.anyString(), EasyMock.anyInt())).andReturn(new long[]{myMessages.size()}).times(1); // The second call is getEarliestOffset, we set the value to 0 EasyMock.expect(offsetResponse.offsets(EasyMock.anyString(), EasyMock.anyInt())).andReturn(new long[]{0}).times(1); EasyMock.expect(offsetResponse.hasError()).andReturn(false).times(2); return offsetResponse; }
private OffsetResponse mockOffsetResponseWithError(List<MyMessage> myMessages) { OffsetResponse offsetResponse = EasyMock.createMock(OffsetResponse.class); mocks.add(offsetResponse); EasyMock.expect(offsetResponse.offsets(EasyMock.anyString(), EasyMock.anyInt())).andReturn(new long[]{myMessages.size()}).times(1); EasyMock.expect(offsetResponse.offsets(EasyMock.anyString(), EasyMock.anyInt())).andReturn(new long[]{0}).times(1); EasyMock.expect(offsetResponse.hasError()).andReturn(true).times(3); return offsetResponse; }
private OffsetResponse mockOffsetResponseThirdTrySucceed(List<MyMessage> myMessages) { OffsetResponse offsetResponse = EasyMock.createMock(OffsetResponse.class); mocks.add(offsetResponse); EasyMock.expect(offsetResponse.offsets(EasyMock.anyString(), EasyMock.anyInt())).andReturn(new long[]{myMessages.size()}).times(1); EasyMock.expect(offsetResponse.offsets(EasyMock.anyString(), EasyMock.anyInt())).andReturn(new long[]{0}).times(1); EasyMock.expect(offsetResponse.hasError()).andReturn(true).times(2); EasyMock.expect(offsetResponse.hasError()).andReturn(false).times(2); return offsetResponse; }
private FetchResponse mockFetchResponse(List<MyMessage> myMessages) { FetchResponse fetchResponse = EasyMock.createMock(FetchResponse.class); EasyMock.expect(fetchResponse.hasError()).andReturn(false).times(1); List<Message> messages = new ArrayList<Message>(); for (MyMessage myMessage:myMessages) { String payload = gson.toJson(myMessage); String msgKey = Integer.toString(PARTITION_1_ID); Message message = new Message(payload.getBytes(), msgKey.getBytes()); messages.add(message); } ByteBufferMessageSet messageSet = new ByteBufferMessageSet(messages); EasyMock.expect(fetchResponse.messageSet(EasyMock.anyString(), EasyMock.anyInt())).andReturn(messageSet).times(1); mocks.add(fetchResponse); return fetchResponse; }
public void testActionStatusError() { ActionApi actionApi = EasyMock.createMock(ActionApi.class); DigitalOcean2Api api = EasyMock.createMock(DigitalOcean2Api.class); expect(actionApi.get(anyInt())).andReturn(action(Action.Status.ERRORED)); expect(api.actionApi()).andReturn(actionApi); replay(actionApi, api); ActionDonePredicate predicate = new ActionDonePredicate(api); try { predicate.apply(1); fail("Method should have thrown an IllegalStateException"); } catch (IllegalStateException ex) { assertEquals(ex.getMessage(), "Resource is in invalid status: ERRORED"); } }
/** * @deprecated since 5.6. */ @Deprecated public static void mockObservation(MockHierarchyManager hm) throws RepositoryException, UnsupportedRepositoryOperationException { // fake observation Workspace ws = createMock(Workspace.class); ObservationManager om = createMock(ObservationManager.class); om.addEventListener(isA(EventListener.class), anyInt(), isA(String.class), anyBoolean(), (String[]) anyObject(), (String[]) anyObject(), anyBoolean()); expect(ws.getObservationManager()).andStubReturn(om); hm.setWorkspace(ws); replay(ws, om); }
@Test(expected = ProcessingException.class) public void testGetProxyDataFail() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); new HttpResponse("response"); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andThrow( new GadgetException(Code.FAILED_TO_RETRIEVE_CONTENT)); replay(); gadgetHandler.getProxy(request); }
@Test(expected = ProcessingException.class) public void testGetProxyDataFail() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); new HttpResponse("response"); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andThrow( new GadgetException(Code.FAILED_TO_RETRIEVE_CONTENT)); replay(); gadgetHandler.getProxy(request); }
@Test public void testGetProxySimple() throws Exception { List<String> fields = ImmutableList.of("proxyurl"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertEquals(resUri, response.getProxyUrl()); assertNull(response.getProxyContent()); assertEquals(timeSource.currentTimeMillis() + HttpUtil.getDefaultTtl() * 1000, response .getExpireTimeMs().longValue()); verify(); }