@SuppressWarnings("unchecked") public T answer(InvocationOnMock invocation) throws Throwable { return answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1), (C)invocation.getArgument(2), (D)invocation.getArgument(3), (E)invocation.getArgument(4)); } };
@SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) throws Throwable { answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1), (C)invocation.getArgument(2), (D)invocation.getArgument(3), (E)invocation.getArgument(4)); return null; } };
@SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) throws Throwable { answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1), (C)invocation.getArgument(2), (D)invocation.getArgument(3)); return null; } };
@SuppressWarnings("unchecked") public T answer(InvocationOnMock invocation) throws Throwable { return answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1), (C)invocation.getArgument(2), (D)invocation.getArgument(3)); } };
@SuppressWarnings("unchecked") public T answer(InvocationOnMock invocation) throws Throwable { return answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1), (C)invocation.getArgument(2)); } };
@SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) throws Throwable { answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1), (C)invocation.getArgument(2)); return null; } };
@SuppressWarnings("unchecked") public T answer(InvocationOnMock invocation) throws Throwable { return answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1)); } };
@SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) throws Throwable { answer.answer( (A)invocation.getArgument(0), (B)invocation.getArgument(1)); return null; } };
@SuppressWarnings("unchecked") public T answer(InvocationOnMock invocation) throws Throwable { return answer.answer((A)invocation.getArgument(0)); } };
@SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) throws Throwable { answer.answer((A)invocation.getArgument(0)); return null; } };
@Override public Object answer(InvocationOnMock a) throws Throwable { Subscription s = a.getArgument(0); s.request(Long.MAX_VALUE); return null; } }).when(w).onSubscribe((Subscription)any());
private Answer<Integer> putByte(int b) { return invocation -> { ByteBuffer buffer = invocation.getArgument(0); buffer.put((byte) b); return 1; }; }
@Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { pendingCallbacks.add(invocationOnMock.getArgument(1)); return null; } });
@Override public Object answer(InvocationOnMock invocation) throws Throwable { SubtaskState subtaskState = invocation.getArgument(4); checkpointResult.add(subtaskState); checkpointCompletedLatch.trigger(); return null; } }).when(checkpointResponder).acknowledgeCheckpoint(
@Test public void readByteChannelError() throws Exception { ReadableByteChannel channel = mock(ReadableByteChannel.class); when(channel.read(any())) .thenAnswer(invocation -> { ByteBuffer buffer = invocation.getArgument(0); buffer.put("foo".getBytes(StandardCharsets.UTF_8)); buffer.flip(); return 3; }) .thenThrow(new IOException()); Flux<DataBuffer> result = DataBufferUtils.readByteChannel(() -> channel, this.bufferFactory, 3); StepVerifier.create(result) .consumeNextWith(stringConsumer("foo")) .expectError(IOException.class) .verify(Duration.ofSeconds(3)); }
@Override public Object answer(InvocationOnMock invocation) throws Throwable { int argumentPosition = inferWantedArgumentPosition(invocation); validateIndexWithinInvocationRange(invocation, argumentPosition); if (wantedArgIndexIsVarargAndSameTypeAsReturnType(invocation.getMethod(), argumentPosition)) { // answer raw vararg array argument return ((Invocation) invocation).getRawArguments()[argumentPosition]; } // answer expanded argument at wanted position return invocation.getArgument(argumentPosition); }
@Test(expected = InvalidReceiveException.class) public void testOversizeRequest() throws IOException { TransportLayer transportLayer = mock(TransportLayer.class); Map<String, ?> configs = Collections.singletonMap(BrokerSecurityConfigs.SASL_ENABLED_MECHANISMS_CONFIG, Collections.singletonList(SCRAM_SHA_256.mechanismName())); SaslServerAuthenticator authenticator = setupAuthenticator(configs, transportLayer, SCRAM_SHA_256.mechanismName()); when(transportLayer.read(any(ByteBuffer.class))).then(invocation -> { invocation.<ByteBuffer>getArgument(0).putInt(SaslServerAuthenticator.MAX_RECEIVE_SIZE + 1); return 4; }); authenticator.authenticate(); verify(transportLayer).read(any(ByteBuffer.class)); }
@Override public Void answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Collector<String> out = invocation.getArgument(4); out.collect("Hallo"); out.collect("Ciao"); return null; } }).when(mockWindowFunction).process(eq(0), eq(new TimeWindow(0, 2)), anyInternalWindowContext(), intIterable(0), WindowOperatorContractTest.<String>anyCollector());
@Override public Void answer(InvocationOnMock invocation) throws Exception { @SuppressWarnings("unchecked") Collector<String> out = invocation.getArgument(4); out.collect("Hallo"); out.collect("Ciao"); return null; } }).when(mockWindowFunction).process(eq(0), eq(new TimeWindow(0, 2)), anyInternalWindowContext(), intIterable(0), WindowOperatorContractTest.<String>anyCollector());
@Test public void resourceHandlerMapping() throws Exception { delegatingConfig.setConfigurers(Collections.singletonList(webFluxConfigurer)); doAnswer(invocation -> { ResourceHandlerRegistry registry = invocation.getArgument(0); registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static"); return null; }).when(webFluxConfigurer).addResourceHandlers(any(ResourceHandlerRegistry.class)); delegatingConfig.resourceHandlerMapping(); verify(webFluxConfigurer).addResourceHandlers(any(ResourceHandlerRegistry.class)); verify(webFluxConfigurer).configurePathMatching(any(PathMatchConfigurer.class)); }