Skip to content

Commit

Permalink
Test exception in handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneider committed Jan 3, 2019
1 parent 11619d5 commit 56efda4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Expand Up @@ -99,6 +99,7 @@ private void poll() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Ignore
}
}
}
Expand Down
Expand Up @@ -2,8 +2,9 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
Expand All @@ -29,6 +30,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;

public class MessagingTest {

Expand Down Expand Up @@ -56,7 +58,8 @@ public void after() {
@Test
public void testPositionFromString() {
Position pos = messaging.positionFromString("1");
assertEquals(0, pos.compareTo(new MemoryPosition(1)));
assertThat(pos.compareTo(new MemoryPosition(1)), equalTo(0));
assertThat(pos.positionToString(), equalTo("1"));
}

@Test
Expand All @@ -73,9 +76,17 @@ public void testSend() {
}

@Test(expected=IllegalArgumentException.class)
public void testInvalid() {
public void testInvalidSubscribe() {
messaging.subscribe("test", null, null, callback);
}

@Test
public void testExceptionInHandler() {
doThrow(new RuntimeException("Expected exception")).when(callback).accept(Mockito.any(Received.class));
subscriptions.add(messaging.subscribe("test", null, Seek.earliest, callback));
send("test", "testcontent");
verify(callback, timeout(1000)).accept(messageCaptor.capture());
}

@Test
public void testEarliestBefore() {
Expand Down

0 comments on commit 56efda4

Please sign in to comment.