### Question:
FlowChainLogService { public boolean hasEventInFlowChainQueue(List<FlowChainLog> flowChains) { Map<String, List<FlowChainLog>> byFlowChainId = flowChains.stream() .collect(Collectors.groupingBy(FlowChainLog::getFlowChainId, toList())); return byFlowChainId.entrySet().stream().anyMatch(entry -> { FlowChainLog latestFlowChain = entry.getValue() .stream() .sorted(comparing(FlowChainLog::getCreated).reversed()) .findFirst() .get(); LOGGER.debug("Checking if chain with id {} has any event in it's queue", latestFlowChain.getFlowChainId()); Queue<Selectable> chain = (Queue<Selectable>) JsonReader.jsonToJava(latestFlowChain.getChain()); return !chain.isEmpty(); }); }  Optional<FlowChainLog> findFirstByFlowChainIdOrderByCreatedDesc(String flowChainId); List<FlowChainLog> findByFlowChainIdOrderByCreatedDesc(String flowChainId); List<FlowChainLog> collectRelatedFlowChains(FlowChainLog flowChain); boolean hasEventInFlowChainQueue(List<FlowChainLog> flowChains); int purgeOrphanFLowChainLogs(); FlowChainLog save(FlowChainLog chainLog);  }### Answer:
@Test public void testCheckIfThereIsEventInQueues() { List<FlowChainLog> flowChains = List.of( flowChainLog("1", true, 1L), flowChainLog("1", true, 2L), flowChainLog("2", true, 1L), flowChainLog("2", false, 2L) ); assertTrue(underTest.hasEventInFlowChainQueue(flowChains)); }
@Test public void testCheckIfThereIsNoEventInQueues() { List<FlowChainLog> flowChains = List.of( flowChainLog("1", true, 1L), flowChainLog("1", false, 2L), flowChainLog("2", true, 1L), flowChainLog("2", false, 2L) ); assertFalse(underTest.hasEventInFlowChainQueue(flowChains)); }
@Test public void testCheckIfThereIsEventInQueuesBasedOnlatestChains() { List<FlowChainLog> flowChains = List.of( flowChainLog("1", false, 1L), flowChainLog("1", true, 2L), flowChainLog("2", false, 1L), flowChainLog("2", true, 2L) ); assertTrue(underTest.hasEventInFlowChainQueue(flowChains)); }