FlowUtils implements AutoCloseable { private byte[] createArpPacket(Ethernet ethernet, ARP arp) { try { ethernet.setRawPayload(arp.serialize()); } catch ( PacketException exception ) { LOG.error("Failed to encode the arp packet, smac: {}, sip: {}, dmac: {}, dip: {}.", convertByteArray6ToMacAddress(arp.getSenderHardwareAddress()).getValue(), convertByteArray4ToIpAddress(arp.getSenderProtocolAddress()).getIpv4Address().getValue(), convertByteArray6ToMacAddress(arp.getTargetHardwareAddress()).getValue(), convertByteArray4ToIpAddress(arp.getTargetProtocolAddress()).getIpv4Address().getValue()); return null; } byte[] arpPacket; try { arpPacket = ethernet.serialize(); } catch ( PacketException exception ) { LOG.error("Failed to encode the ethernet packet, smac: {}, dmac: {}.", convertByteArray6ToMacAddress(ethernet.getSourceMACAddress()).getValue(), convertByteArray6ToMacAddress(ethernet.getDestinationMACAddress()).getValue()); return null; } return arpPacket; } FlowUtils(DataBroker dataBroker,
                     PacketProcessingService packetProcessingService,
                     PhyConfigLoader phyConfigLoader); void init(List<PhysicalNode> physicalNodes); void handleArp(PacketReceived packetReceived, NodeConnectorRef ingress); @Override void close(); void assignMPLSLabelForPPath(PhysicalPath physicalPath,
                  List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink> physicalLinksList);  }
@Test public void testCreateArpPacket() throws Exception{ Class<FlowUtils> class1 = FlowUtils.class; Method method = class1.getDeclaredMethod("createArpPacket",new Class[]{Ethernet.class,ARP.class}); method.setAccessible(true); Ethernet ethernet = mock(Ethernet.class); ARP arp = mock(ARP.class); byte[] byteArray = "192.168.1.1".getBytes(); byte[] result; doNothing().when(ethernet).setRawPayload(any(byte[].class)); when(ethernet.serialize()).thenReturn(byteArray); when(arp.serialize()).thenReturn(byteArray); result = (byte[]) method.invoke(flowUtils,ethernet,arp); Assert.assertTrue(result.equals(byteArray)); }