fix double invocation of listeners implementing intf

DATAREDIS-92
This commit is contained in:
Costin Leau
2012-06-21 20:58:26 +03:00
parent e7d7519ae8
commit a440291c6a
2 changed files with 32 additions and 11 deletions

View File

@@ -42,8 +42,7 @@ public class MessageListenerTest {
private static final byte[] RAW_CHANNEL = serializer.serialize(CHANNEL);
private static final String PAYLOAD = "do re mi";
private static final byte[] RAW_PAYLOAD = serializer.serialize(PAYLOAD);
private static final Message STRING_MSG = new DefaultMessage(RAW_CHANNEL,
RAW_PAYLOAD);
private static final Message STRING_MSG = new DefaultMessage(RAW_CHANNEL, RAW_PAYLOAD);
private MessageListenerAdapter adapter;
@@ -71,21 +70,14 @@ public class MessageListenerTest {
}
@Test
public void testThatTheDefaultMessageHandlingMethodNameIsTheConstantDefault()
throws Exception {
assertEquals(MessageListenerAdapter.ORIGINAL_DEFAULT_LISTENER_METHOD,
adapter.getDefaultListenerMethod());
public void testThatTheDefaultMessageHandlingMethodNameIsTheConstantDefault() throws Exception {
assertEquals(MessageListenerAdapter.ORIGINAL_DEFAULT_LISTENER_METHOD, adapter.getDefaultListenerMethod());
}
@Test(expected = IllegalStateException.class)
// TODO: revisit the exception/method discovery during invocation
// TODO: potentially move the discovery early on
public void testAdapterWithListenerAndDefaultMessage() throws Exception {
MessageListener mock = mock(MessageListener.class);
MessageListenerAdapter adapter = new MessageListenerAdapter(mock) {
protected void handleListenerException(Throwable ex) {
throw new IllegalStateException(ex);
}
@@ -125,4 +117,32 @@ public class MessageListenerTest {
verify(target).customMethodWithChannel(PAYLOAD, CHANNEL);
}
/**
* @see DATAREDIS-92
*/
@Test
public void triggersListenerImplementingInterfaceCorrectly() {
SampleListener listener = new SampleListener();
MessageListener listenerAdapter = new MessageListenerAdapter(listener) {
@Override
public void setDefaultListenerMethod(String defaultListenerMethod) {
throw new RuntimeException("Boom!");
}
};
listenerAdapter.onMessage(STRING_MSG, RAW_CHANNEL);
assertEquals(1, listener.count);
}
class SampleListener implements MessageListener {
int count;
public void onMessage(Message message, byte[] pattern) {
count++;
}
}
}