### Question:
OfPortStatsMapper { public PortStatsData toPostStatsData(List<OFPortStatsReply> data, SwitchId switchId) { try { List<PortStatsEntry> stats = data.stream() .flatMap(reply -> reply.getEntries().stream()) .map(this::toPortStatsEntry) .filter(Objects::nonNull) .collect(toList()); return new PortStatsData(switchId, stats); } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) { log.error(String.format("Could not convert port stats data %s on switch %s", data, switchId), e); return null; } }  PortStatsData toPostStatsData(List<OFPortStatsReply> data, SwitchId switchId); PortStatsEntry toPortStatsEntry(OFPortStatsEntry entry); static final OfPortStatsMapper INSTANCE; }### Answer:
@Test public void testToPortStatsDataV13() { OFFactoryVer13 ofFactoryVer13 = new OFFactoryVer13(); OFPortStatsEntry ofPortStatsEntry = prebuildPortStatsEntry(ofFactoryVer13.buildPortStatsEntry()) .setRxFrameErr(U64.of(rxFrameErr)) .setRxOverErr(U64.of(rxOverErr)) .setRxCrcErr(U64.of(rxCrcErr)) .setCollisions(U64.of(collisions)).build(); OFPortStatsReply ofPortStatsReply = ofFactoryVer13.buildPortStatsReply() .setXid(xId) .setEntries(Collections.singletonList(ofPortStatsEntry)) .build(); PortStatsData data = OfPortStatsMapper.INSTANCE.toPostStatsData( Collections.singletonList(ofPortStatsReply), switchId); assertPortStatsData(data); }
@Test public void testToPortStatsDataV14() { OFFactoryVer14 ofFactoryVer14 = new OFFactoryVer14(); OFPortStatsProp opticalProps = ofFactoryVer14.buildPortStatsPropOptical().setRxPwr(123).build(); OFPortStatsProp ethernetProps = ofFactoryVer14.buildPortStatsPropEthernet() .setRxFrameErr(U64.of(rxFrameErr)) .setRxOverErr(U64.of(rxOverErr)) .setRxCrcErr(U64.of(rxCrcErr)) .setCollisions(U64.of(collisions)) .build(); OFPortStatsEntry ofPortStatsEntry = prebuildPortStatsEntry(ofFactoryVer14.buildPortStatsEntry()) .setProperties(Lists.newArrayList(opticalProps, ethernetProps)) .build(); OFPortStatsReply ofPortStatsReply = ofFactoryVer14.buildPortStatsReply() .setXid(xId) .setEntries(Collections.singletonList(ofPortStatsEntry)) .build(); PortStatsData data = OfPortStatsMapper.INSTANCE.toPostStatsData( Collections.singletonList(ofPortStatsReply), switchId); assertPortStatsData(data); }