### Question:
MBMessageResolversImpl implements MBMessageResolvers { @Override public DataFetcher<CompletableFuture<MBMessage>> getMBMessageDataFetcher() { return environment -> { long messageId = getMessageId(environment); if (messageId <= 0) { return null; } DataLoader<Long, MBMessage> dataLoader = environment.getDataLoader(MBMessageBatchLoader.KEY); return dataLoader.load(messageId); }; }  @Reference(unbind = "-") void setMBMessageLocalService(MBMessageLocalService mbMessageLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<MBMessage>> getMBMessagesDataFetcher(); @Override DataFetcher<CompletableFuture<MBMessage>> getMBMessageDataFetcher(); @Override DataFetcher<MBMessage> createMBMessageDataFetcher(); @Override DataFetcher<MBMessage> updateMBMessageDataFetcher(); @Override DataFetcher<MBMessage> deleteMBMessageDataFetcher();  }### Answer:
@Test public void getMBMessageDataFetcher_should_return_the_searched_object() throws Exception { MBMessage expectedResult = mock(MBMessage.class); expectedResult.setMessageId(MESSAGE_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("messageId")) .thenReturn(MESSAGE_ID); when(dataLoader.load(MESSAGE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<MBMessage> asyncResult = resolvers.getMBMessageDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); MBMessage result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getMBMessageDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("messageId")) .thenReturn(0L); CompletableFuture<MBMessage> asyncResult = resolvers.getMBMessageDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getMBMessageDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("messageId")) .thenReturn(MESSAGE_ID); when(dataLoader.load(MESSAGE_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<MBMessage> asyncResult = resolvers.getMBMessageDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); MBMessage result = asyncResult.get(); assertNull(result); }