e2f5012 unit test cleanup

Motivation:
e2f5012 added unit tests which did not verify the buffer was released as it was intended to.

Modification:
- Unit tests must verify release is called

Result:
Unit tests enforce that ByteBufs are released.
This commit is contained in:
Scott Mitchell 2016-03-07 09:33:42 -08:00
parent e2f5012f3b
commit d0f7f98d22

View File

@ -22,6 +22,7 @@ import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -38,19 +39,29 @@ public class DefaultChannelHandlerInvokerTest {
MockitoAnnotations.initMocks(this);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void writeWithInvalidPromiseStillReleasesMessage() {
when(promise.isDone()).thenReturn(true);
DefaultChannelHandlerInvoker invoker = new DefaultChannelHandlerInvoker(ImmediateEventExecutor.INSTANCE);
invoker.invokeWrite(ctx, msg, promise);
verify(msg).release();
try {
invoker.invokeWrite(ctx, msg, promise);
} catch (IllegalArgumentException e) {
verify(msg).release();
return;
}
fail();
}
@Test(expected = NullPointerException.class)
@Test
public void writeWithNullPromiseStillReleasesMessage() {
when(promise.isDone()).thenReturn(true);
DefaultChannelHandlerInvoker invoker = new DefaultChannelHandlerInvoker(ImmediateEventExecutor.INSTANCE);
invoker.invokeWrite(ctx, msg, null);
verify(msg).release();
try {
invoker.invokeWrite(ctx, msg, null);
} catch (NullPointerException e) {
verify(msg).release();
return;
}
fail();
}
}