### Question:
GetPortStatisticsAction extends Action { protected static SwitchPortStatistics generateSwitchPortStatistics(Map<String, SwitchPortStatistics> switchesStatistics, BiMap<String, DevicePortId> networkDevicePortIdsMap) throws Exception { Map<String, PortStatistics> stats = new HashMap<String, PortStatistics>(); for (Entry<String, DevicePortId> entry : networkDevicePortIdsMap.entrySet()) { String networkElementId = entry.getValue().getDeviceId(); String networkElementPortId = entry.getValue().getDevicePortId(); if (!switchesStatistics.containsKey(networkElementId) || switchesStatistics.get(networkElementId).getStatistics() == null || !switchesStatistics .get(networkElementId).getStatistics().containsKey(entry.getKey())) { throw new Exception( "Could not find statistics for network element with ID = " + networkElementId + " and port ID = " + networkElementPortId + "!"); } PortStatistics portStatistics = switchesStatistics.get(networkElementId).getStatistics() .get(entry.getKey()); stats.put(entry.getKey(), portStatistics); } SwitchPortStatistics switchPortStatistics = new SwitchPortStatistics(); switchPortStatistics.setStatistics(stats); return switchPortStatistics; }  @Override ActionResponse execute(IProtocolSessionManager protocolSessionManager); @Override boolean checkParams(Object params);  }### Answer:
@Test public void generateSwitchPortStatisticsTest() throws Exception { Map<String, SwitchPortStatistics> switchesStatistics = generateSwitchesStatistics(); BiMap<String, DevicePortId> networkDevicePortIdsMap = generateNetworkDevicePortIdsMap(); SwitchPortStatistics switchPortStatistics = GetPortStatisticsAction.generateSwitchPortStatistics(switchesStatistics, networkDevicePortIdsMap); Assert.assertEquals(10, switchPortStatistics.getStatistics().get(SW1 + "." + "1").getCollisions()); Assert.assertEquals(20, switchPortStatistics.getStatistics().get(SW1 + "." + "2").getCollisions()); Assert.assertEquals(3000, switchPortStatistics.getStatistics().get(NET1 + "." + "3").getCollisions()); Assert.assertEquals(4000, switchPortStatistics.getStatistics().get(NET1 + "." + "4").getCollisions()); }