import org.junit.Assert;import org.junit.Test;import com.mashibing.nettystudy.s13.TankMsg;import com.mashibing.nettystudy.s13.TankMsgDecoder;import com.mashibing.nettystudy.s13.TankMsgEncoder;import io.netty.buffer.ByteBuf;import io.netty.buffer.Unpooled;import io.netty.channel.embedded.EmbeddedChannel;public class TankMsgCodecTest {@Testpublic void testTankMsgEncoder() {TankMsg msg = new TankMsg(10, 10);EmbeddedChannel ch = new EmbeddedChannel(new TankMsgEncoder());ch.writeOutbound(msg);ByteBuf buf = (ByteBuf)ch.readOutbound();int x = buf.readInt();int y = buf.readInt();Assert.assertTrue(x == 10 && y == 10);buf.release();}@Testpublic void testTankMsgEncoder2() {ByteBuf buf = Unpooled.buffer();TankMsg msg = new TankMsg(10, 10);buf.writeInt(msg.x);buf.writeInt(msg.y);EmbeddedChannel ch = new EmbeddedChannel(new TankMsgEncoder(), new TankMsgDecoder());ch.writeInbound(buf.duplicate());TankMsg tm = (TankMsg)ch.readInbound();Assert.assertTrue(tm.x == 10 && tm.y == 10);}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。