### Question:
DefaultEventStoreService implements EventStoreService { @Override public Optional<ContractEventDetails> getLatestContractEvent( String eventSignature, String contractAddress) { int page = eventStore.isPagingZeroIndexed() ? 0 : 1; final PageRequest pagination = new PageRequest(page, 1, new Sort(Sort.Direction.DESC, "blockNumber")); final Page<ContractEventDetails> eventsPage = eventStore.getContractEventsForSignature(eventSignature, contractAddress, pagination); if (eventsPage == null) { return Optional.empty(); } final List<ContractEventDetails> events = eventsPage.getContent(); if (events == null || events.isEmpty()) { return Optional.empty(); } return Optional.of(events.get(0)); } DefaultEventStoreService(EventStore eventStore); @Override Optional<ContractEventDetails> getLatestContractEvent(
            String eventSignature, String contractAddress); @Override Optional<LatestBlock> getLatestBlock(String nodeName);  }### Answer:
@Test public void testGetLatestContractEvent() { when(mockPage.getContent()).thenReturn(Arrays.asList(mockEventDetails1, mockEventDetails2)); when(mockEventStore.getContractEventsForSignature( eq(EVENT_SIGNATURE), eq(CONTRACT_ADDRESS), any(PageRequest.class))).thenReturn(mockPage); assertEquals(mockEventDetails1, underTest.getLatestContractEvent(EVENT_SIGNATURE, CONTRACT_ADDRESS).get()); }
@Test public void testGetLatestContractEventNullEvents() { when(mockPage.getContent()).thenReturn(null); when(mockEventStore.getContractEventsForSignature( eq(EVENT_SIGNATURE), eq(CONTRACT_ADDRESS), any(PageRequest.class))).thenReturn(mockPage); assertEquals(false, underTest.getLatestContractEvent(EVENT_SIGNATURE, CONTRACT_ADDRESS).isPresent()); }
@Test public void testGetLatestContractEventEmptyEvents() { when(mockPage.getContent()).thenReturn(new ArrayList<>()); when(mockEventStore.getContractEventsForSignature( eq(EVENT_SIGNATURE), eq(CONTRACT_ADDRESS), any(PageRequest.class))).thenReturn(mockPage); assertEquals(false, underTest.getLatestContractEvent(EVENT_SIGNATURE, CONTRACT_ADDRESS).isPresent()); }