### Question:
GroupModInputMessageFactory implements OFSerializer<GroupMod>, SerializerRegistryInjector { @Override public void serialize(GroupMod message, ByteBuf outBuffer) { int index = outBuffer.writerIndex(); ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(message.getCommand().getIntValue()); outBuffer.writeByte(message.getType().getIntValue()); outBuffer.writeZero(PADDING_IN_GROUP_MOD_MESSAGE); outBuffer.writeInt(message.getGroupId().getValue().intValue()); serializerBuckets(message.getBucketsList(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer, index); }  @Override void serialize(GroupMod message, ByteBuf outBuffer); @Override void injectSerializerRegistry(SerializerRegistry serializerRegistry);  }### Answer:
@Test public void testGroupModInputMessage() throws Exception { GroupModInputBuilder builder = new GroupModInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setCommand(GroupModCommand.forValue(2)); builder.setType(GroupType.forValue(3)); builder.setGroupId(new GroupId(256L)); List<BucketsList> exp = createBucketsList(); builder.setBucketsList(exp); GroupModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); out.writeInt(1); out.writeZero(2); out.writeShort(3); groupModFactory.serialize(message, out); out.readInt(); out.skipBytes(2); out.readShort(); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 32); Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte()); out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE); Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt()); List<BucketsList> rec = createBucketsListFromBufer(out); Assert.assertArrayEquals("Wrong bucketList", exp.toArray(), rec.toArray()); }
@Test public void testGroupModInputWithNoBuckets() throws Exception { GroupModInputBuilder builder = new GroupModInputBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID); builder.setCommand(GroupModCommand.forValue(2)); builder.setType(GroupType.forValue(3)); builder.setGroupId(new GroupId(256L)); GroupModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); groupModFactory.serialize(message, out); BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16); Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedShort()); Assert.assertEquals("Wrong type", message.getType().getIntValue(), out.readUnsignedByte()); out.skipBytes(PADDING_IN_GROUP_MOD_MESSAGE); Assert.assertEquals("Wrong groupId", message.getGroupId().getValue().intValue(), out.readUnsignedInt()); Assert.assertTrue("Unexpected data", out.readableBytes() == 0); }