@Test public void testCouldNotClose() throws Exception { SQLException sqlException = new SQLException("bar"); given(this.connection.createStatement()).willReturn(this.statement); given(this.resultSet.next()).willReturn(false); willThrow(sqlException).given(this.resultSet).close(); willThrow(sqlException).given(this.statement).close(); willThrow(sqlException).given(this.connection).close(); RowCountCallbackHandler rcch = new RowCountCallbackHandler(); this.template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch); verify(this.connection).close(); }
@Test public void handleTransportError() throws Exception { Exception exception = new Exception("transport error"); willThrow(new IllegalStateException("error")) .given(this.delegate).handleTransportError(this.session, exception); this.decorator.handleTransportError(this.session, exception); assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus()); }
@Test public void putFailProperException() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); willThrow(exception).given(this.cache).put(0L, 0L); this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler()); this.thrown.expect(is(exception)); this.simpleService.put(0L); }
@Test public void getFailProperException() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); willThrow(exception).given(this.cache).get(0L); this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler()); this.thrown.expect(is(exception)); this.simpleService.get(0L); }
@Test public void evictFailProperException() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); willThrow(exception).given(this.cache).evict(0L); this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler()); this.thrown.expect(is(exception)); this.simpleService.evict(0L); }
@Test public void clearFailProperException() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); willThrow(exception).given(this.cache).clear(); this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler()); this.thrown.expect(is(exception)); this.simpleService.clear(); }
@Test public void afterConnectionClosed() throws Exception { CloseStatus closeStatus = CloseStatus.NORMAL; willThrow(new IllegalStateException("error")) .given(this.delegate).afterConnectionClosed(this.session, closeStatus); this.decorator.afterConnectionClosed(this.session, closeStatus); assertNull(this.session.getCloseStatus()); }
@Test public void putFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); willThrow(exception).given(this.cache).put(0L, 0L); this.simpleService.put(0L); verify(this.errorHandler).handleCachePutError(exception, cache, 0L, 0L); }
@Test public void clearFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); willThrow(exception).given(this.cache).clear(); this.simpleService.clear(); verify(this.errorHandler).handleCacheClearError(exception, cache); }
@Test public void handleFrameOpenWithWebSocketHandlerException() throws Exception { willThrow(new IllegalStateException("Fake error")).given(this.handler).afterConnectionEstablished(this.session); this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThat(this.session.isOpen(), is(true)); }
@Test public void convertDestinationResolutionExceptionOnReceive() { Destination destination = new Destination() {}; willThrow(DestinationResolutionException.class).given(this.jmsTemplate).receive(destination); this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class); this.messagingTemplate.receive(destination); }
@Test public void handleMessage() throws Exception { TextMessage message = new TextMessage("payload"); willThrow(new IllegalStateException("error")) .given(this.delegate).handleMessage(this.session, message); this.decorator.handleMessage(this.session, message); assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus()); }
@Test public void evictFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).evict(key); this.simpleService.evict(0L); verify(this.errorHandler).handleCacheEvictError(exception, this.cache, key); }
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).get(key); this.simpleService.get(0L); verify(this.errorHandler).handleCacheGetError(exception, this.cache, key); }
@Test public void putFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); willThrow(exception).given(this.cache).put(key, 234L); this.simpleService.put(0L, 234L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 234L); }
@Test public void getPutNewElementFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put"); Object key = SimpleKeyGenerator.generateKey(0L); given(this.cache.get(key)).willReturn(null); willThrow(exception).given(this.cache).put(key, 0L); this.simpleService.get(0L); verify(this.errorHandler).handleCachePutError(exception, this.cache, key, 0L); }
@Test public void getFail() { UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get"); willThrow(exception).given(this.cache).get(0L); Object result = this.simpleService.get(0L); verify(this.errorHandler).handleCacheGetError(exception, cache, 0L); verify(this.cache).get(0L); verify(this.cache).put(0L, result); // result of the invocation }
@Test public void simpleApplicationEventMulticasterWithErrorHandler() { @SuppressWarnings("unchecked") ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class); ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext()); SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster(); smc.setErrorHandler(TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER); smc.addApplicationListener(listener); willThrow(new RuntimeException()).given(listener).onApplicationEvent(evt); smc.multicastEvent(evt); }
@Test public void convertInvalidDestinationExceptionOnSendAndReceiveWithName() { willThrow(InvalidDestinationException.class).given(this.jmsTemplate).sendAndReceive(eq("unknownQueue"), any()); this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class); this.messagingTemplate.sendAndReceive("unknownQueue", createTextMessage()); }
@Test public void convertInvalidDestinationExceptionOnSendAndReceive() { Destination destination = new Destination() {}; willThrow(InvalidDestinationException.class).given(this.jmsTemplate).sendAndReceive(eq(destination), any()); this.thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class); this.messagingTemplate.sendAndReceive(destination, createTextMessage()); }