private void verifyError(Single<Boolean> single) { SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(isA(TestException.class)); inOrder.verifyNoMoreInteractions(); }
private void verifyError(Observable<Boolean> observable) { Observer<Boolean> observer = TestHelper.mockObserver(); observable.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(isA(TestException.class)); inOrder.verifyNoMoreInteractions(); }
private void verifyError(Single<Boolean> single) { SingleObserver<Boolean> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onError(isA(TestException.class)); inOrder.verifyNoMoreInteractions(); }
/** * Argument that is either <code>null</code> or of the given type. * * <p> * See examples in javadoc for {@link ArgumentMatchers} class * </p> * * @param clazz Type to avoid casting * @return <code>null</code>. */ public static <T> T nullable(Class<T> clazz) { AdditionalMatchers.or(isNull(), isA(clazz)); return (T) Primitives.defaultValue(clazz); }
private Response.ResponseBuilder mockResponseBuilder( Response response, final AtomicReference<StreamingOutput> ref ) { final Response.ResponseBuilder responseBuilder = mock( Response.ResponseBuilder.class ); when( responseBuilder.entity( ArgumentMatchers.isA( StreamingOutput.class ) ) ).thenAnswer( invocationOnMock -> { ref.set( invocationOnMock.getArgument( 0 ) ); return responseBuilder; } ); when( responseBuilder.type( ArgumentMatchers.<MediaType>any() ) ).thenReturn( responseBuilder ); when( responseBuilder.build() ).thenReturn( response ); return responseBuilder; }
private void verifyError(Flowable<Boolean> flowable) { Subscriber<Boolean> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onError(isA(TestException.class)); inOrder.verifyNoMoreInteractions(); }
@Test public void cannotProvideStreamingForOtherMediaTypes() throws Exception { final Response.ResponseBuilder responseBuilder = mock( Response.ResponseBuilder.class ); // no streaming when( responseBuilder.entity( any(byte[].class) ) ).thenReturn( responseBuilder ); Mockito.verify( responseBuilder, never() ).entity( isA( StreamingOutput.class ) ); when( responseBuilder.type( ArgumentMatchers.<MediaType>any() ) ).thenReturn( responseBuilder ); when( responseBuilder.build() ).thenReturn( null ); OutputFormat format = repository.outputFormat( asList( MediaType.TEXT_HTML_TYPE ), new URI( "http://some.host" ), streamingHeader() ); assertNotNull( format ); format.response( responseBuilder, new ExceptionRepresentation( new RuntimeException() ) ); }
@Test public void shouldDistributePersistentQuery() { // When: makeSingleRequest( "CREATE STREAM S AS SELECT * FROM test_stream;", CommandStatusEntity.class); // Then: verify(commandStore).enqueueCommand( eq("CREATE STREAM S AS SELECT * FROM test_stream;"), isA(CreateStreamAsSelect.class), any(), any()); }
@Test public void shouldDistributeAvoCreateStatementWithColumns() { // When: makeSingleRequest( "CREATE STREAM S (foo INT) WITH(VALUE_FORMAT='AVRO', KAFKA_TOPIC='orders-topic');", CommandStatusEntity.class); // Then: verify(commandStore).enqueueCommand( eq("CREATE STREAM S (foo INT) WITH(VALUE_FORMAT='AVRO', KAFKA_TOPIC='orders-topic');"), isA(CreateStream.class), any(), any()); }
@Before public void setup() { when(mockRequestContext.eventLoop()).thenReturn(eventLoop); when(mockRequestContext2.eventLoop()).thenReturn(eventLoop); when(eventLoop.inEventLoop()).thenReturn(true); when(mockRequestContext.attr(isA(AttributeKey.class))).thenAnswer( (Answer<Attribute>) invocation -> attrs1.attr(invocation.getArgument(0))); when(mockRequestContext2.attr(isA(AttributeKey.class))).thenAnswer( (Answer<Attribute>) invocation -> attrs2.attr(invocation.getArgument(0))); }
@Test public void onMessage_deframeError_errorListenerThrows() { doThrow(Status.INTERNAL.asRuntimeException()) .when(deframer).deframe(isA(HttpData.class), anyBoolean()); doThrow(new IllegalStateException()) .when(transportStatusListener).transportReportStatus(isA(Status.class)); reader.onSubscribe(subscription); assertThatThrownBy(() -> reader.onNext(DATA)).isInstanceOf(IllegalStateException.class); verify(deframer).close(); }
@Test public void shouldDistributeTerminateQuery() { // Given: final PersistentQueryMetadata queryMetadata = createQuery( "CREATE STREAM test_explain AS SELECT * FROM test_stream;", Collections.emptyMap()); final String terminateSql = "TERMINATE " + queryMetadata.getQueryId() + ";"; // When: final CommandStatusEntity result = makeSingleRequest(terminateSql, CommandStatusEntity.class); // Then: verify(commandStore).enqueueCommand(eq(terminateSql), isA(TerminateQuery.class), any(), any()); assertThat(result.getStatementText(), is(terminateSql)); }
@Test public void saveNewFlushModeOnSave() { verify(this.sessions, times(1)).addEntryListener(any(MapListener.class), anyBoolean()); HazelcastSession session = this.repository.createSession(); verifyZeroInteractions(this.sessions); this.repository.save(session); verify(this.sessions, times(1)).set(eq(session.getId()), eq(session.getDelegate()), isA(Long.class), eq(TimeUnit.SECONDS)); verifyZeroInteractions(this.sessions); }
public JmsAppenderTest() throws Exception { // this needs to set up before LoggerContextRule given(connectionFactory.createConnection()).willReturn(connection); given(connectionFactory.createConnection(anyString(), anyString())).willThrow(IllegalArgumentException.class); given(connection.createSession(eq(false), eq(Session.AUTO_ACKNOWLEDGE))).willReturn(session); given(session.createProducer(eq(destination))).willReturn(messageProducer); given(session.createTextMessage(anyString())).willReturn(textMessage); given(session.createObjectMessage(isA(Serializable.class))).willReturn(objectMessage); }
@Test public void saveNewWithoutTransaction() { this.repository = new JdbcOperationsSessionRepository(this.jdbcOperations); JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); this.repository.save(session); verify(this.jdbcOperations, times(1)).update( startsWith("INSERT INTO SPRING_SESSION"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); verifyZeroInteractions(this.transactionManager); }
@Test public void saveNewWithoutAttributes() { JdbcOperationsSessionRepository.JdbcSession session = this.repository .createSession(); this.repository.save(session); assertThat(session.isNew()).isFalse(); assertPropagationRequiresNew(); verify(this.jdbcOperations, times(1)).update(startsWith("INSERT"), isA(PreparedStatementSetter.class)); verifyZeroInteractions(this.jdbcOperations); }
@Test public void onMessage_deframeError() { doThrow(Status.INTERNAL.asRuntimeException()) .when(deframer).deframe(isA(HttpData.class), anyBoolean()); reader.onSubscribe(subscription); reader.onNext(DATA); verify(deframer).deframe(DATA, false); verify(transportStatusListener).transportReportStatus(Status.INTERNAL); verify(deframer).close(); }
@Test public void transferFailure_Exception() { @SuppressWarnings("unchecked") final AsyncMethodCallback<String> callback = mock(AsyncMethodCallback.class); AsyncMethodCallbacks.transfer(exceptionallyCompletedFuture(new AnticipatedException()), callback); verify(callback, only()).onError(isA(AnticipatedException.class)); }