### Question:
MBMessageResolversImpl implements MBMessageResolvers { @Override public DataFetcher<MBMessage> deleteMBMessageDataFetcher() { return environment -> { long messageId = util.getLongArg(environment, "messageId"); return mbMessageLocalService.deleteMBMessage(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 deleteMBMessageDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("messageId", MESSAGE_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); MBMessage expectedResult = mock(MBMessage.class); expectedResult.setMessageId(MESSAGE_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteMBMessage(eq(MESSAGE_ID))) .thenReturn(expectedResult); MBMessage result = resolvers.deleteMBMessageDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchMessageException.class) public void deleteMBMessageDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); MBMessage expectedResult = mock(MBMessage.class); expectedResult.setMessageId(MESSAGE_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteMBMessage(eq(MESSAGE_ID))) .thenThrow(NoSuchMessageException.class); MBMessage result = resolvers.deleteMBMessageDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchMessageException.class) public void deleteMBMessageDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("messageId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); MBMessage expectedResult = mock(MBMessage.class); expectedResult.setMessageId(MESSAGE_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("messageId"))) .thenReturn(789456L); when(localService.deleteMBMessage(eq(789456L))) .thenThrow(NoSuchMessageException.class); MBMessage result = resolvers.deleteMBMessageDataFetcher() .get(environment); assertNull(result); }