[#2454] Correctly return null when DefaultChannelPipeline.firstContext() is called on empty pipeline

Motivation:
DefaultChannelPipeline.firstContext() should return null when the ipeline is empty. This is not the case atm.

Modification:
Fix incorrect check in DefaultChannelPipeline.firstContext() and add unit tests.

Result:
Correctly return null when DefaultChannelPipeline.firstContext() is called on empty pipeline.
This commit is contained in:
Norman Maurer 2014-05-04 21:09:58 +02:00
parent c09d85f699
commit aba9c552cd
2 changed files with 25 additions and 1 deletions

View File

@ -675,7 +675,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
@Override
public ChannelHandlerContext firstContext() {
DefaultChannelHandlerContext first = head.next;
if (first == head) {
if (first == tail) {
return null;
}
return head.next;

View File

@ -524,6 +524,30 @@ public class DefaultChannelPipelineTest {
assertEquals(0, buffer.refCnt());
}
@Test
public void testFirstContextEmptyPipeline() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.firstContext());
}
@Test
public void testLastContextEmptyPipeline() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.lastContext());
}
@Test
public void testFirstHandlerEmptyPipeline() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.first());
}
@Test
public void testLastHandlerEmptyPipeline() throws Exception {
ChannelPipeline pipeline = new LocalChannel().pipeline();
assertNull(pipeline.last());
}
private static int next(DefaultChannelHandlerContext ctx) {
DefaultChannelHandlerContext next = ctx.next;
if (next == null) {