### Question:
FermaFlowMeterRepository extends FermaGenericRepository<FlowMeter, FlowMeterData, FlowMeterFrame> implements FlowMeterRepository { @Override public Collection<FlowMeter> findAll() { return framedGraph().traverse(g -> g.V() .hasLabel(FlowMeterFrame.FRAME_LABEL)) .toListExplicit(FlowMeterFrame.class).stream() .map(FlowMeter::new) .collect(Collectors.toList()); } FermaFlowMeterRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override Collection<FlowMeter> findAll(); @Override Optional<FlowMeter> findByPathId(PathId pathId); @Override boolean exists(SwitchId switchId, MeterId meterId); @Override Optional<MeterId> findFirstUnassignedMeter(SwitchId switchId, MeterId lowestMeterId,
                                                      MeterId highestMeterId);  }### Answer:
@Test public void shouldCreateFlowMeter() { createFlowMeter(); Collection<FlowMeter> allMeters = flowMeterRepository.findAll(); FlowMeter foundMeter = allMeters.iterator().next(); assertEquals(theSwitch.getSwitchId(), foundMeter.getSwitchId()); assertEquals(TEST_FLOW_ID, foundMeter.getFlowId()); }
@Test public void shouldDeleteFlowMeter() { FlowMeter meter = createFlowMeter(); transactionManager.doInTransaction(() -> flowMeterRepository.remove(meter)); assertEquals(0, flowMeterRepository.findAll().size()); }
@Test public void shouldDeleteFoundFlowMeter() { createFlowMeter(); transactionManager.doInTransaction(() -> { Collection<FlowMeter> allMeters = flowMeterRepository.findAll(); FlowMeter foundMeter = allMeters.iterator().next(); flowMeterRepository.remove(foundMeter); }); assertEquals(0, flowMeterRepository.findAll().size()); }
@Test public void shouldSelectNextInOrderResourceWhenFindUnassignedMeter() { long first = findUnassignedMeterAndCreate("flow_1"); assertEquals(5, first); long second = findUnassignedMeterAndCreate("flow_2"); assertEquals(6, second); long third = findUnassignedMeterAndCreate("flow_3"); assertEquals(7, third); transactionManager.doInTransaction(() -> { flowMeterRepository.findAll().stream() .filter(flowMeter -> flowMeter.getMeterId().getValue() == second) .forEach(flowMeterRepository::remove); }); long fourth = findUnassignedMeterAndCreate("flow_4"); assertEquals(6, fourth); long fifth = findUnassignedMeterAndCreate("flow_5"); assertEquals(8, fifth); }