Extracted a TestUtils method mockChannelHandler

This commit is contained in:
andrea
2013-09-11 17:51:59 +02:00
parent 93859d1a63
commit 1baa16b8e3
2 changed files with 11 additions and 6 deletions
@@ -1,15 +1,12 @@
package org.dna.mqtt.moquette.parser.netty;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import org.dna.mqtt.moquette.proto.messages.ConnectMessage;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.dna.mqtt.moquette.parser.netty.TestUtils.*;
@@ -24,9 +21,7 @@ public class ConnectEncoderTest {
@Before
public void setUp() {
//mock the ChannelHandlerContext to return an UnpooledAllocator
m_mockedContext = mock(ChannelHandlerContext.class);
ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
when(m_mockedContext.alloc()).thenReturn(allocator);
m_mockedContext = mockChannelHandler();
}
@Test
@@ -1,10 +1,14 @@
package org.dna.mqtt.moquette.parser.netty;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import java.io.UnsupportedEncodingException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
/**
* Common test methods
@@ -46,4 +50,10 @@ public class TestUtils {
assertEquals(expected, found);
}
static ChannelHandlerContext mockChannelHandler() {
ChannelHandlerContext m_mockedContext = mock(ChannelHandlerContext.class);
ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
when(m_mockedContext.alloc()).thenReturn(allocator);
return m_mockedContext;
}
}