### Question:
OrganizationResolversImpl implements OrganizationResolvers { @Override public DataFetcher<Organization> deleteOrganizationDataFetcher() { return environment -> { long organizationId = util.getLongArg(environment, "organizationId"); return organizationLocalService.deleteOrganization(organizationId); }; }  @Reference(unbind = "-") void setOrganizationLocalService(OrganizationLocalService organizationLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Organization>> getOrganizationsDataFetcher(); @Override DataFetcher<CompletableFuture<Organization>> getOrganizationDataFetcher(); @Override DataFetcher<Organization> getOrganizationByNameDataFetcher(); @Override DataFetcher<Organization> createOrganizationDataFetcher(); @Override DataFetcher<Organization> updateOrganizationDataFetcher(); @Override DataFetcher<Organization> deleteOrganizationDataFetcher();  }### Answer:
@Test public void deleteOrganizationDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("organizationId", ORGANIZATION_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Organization expectedResult = mock(Organization.class); expectedResult.setOrganizationId(ORGANIZATION_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteOrganization(eq(ORGANIZATION_ID))) .thenReturn(expectedResult); Organization result = resolvers.deleteOrganizationDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchOrganizationException.class) public void deleteOrganizationDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); Organization expectedResult = mock(Organization.class); expectedResult.setOrganizationId(ORGANIZATION_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteOrganization(eq(ORGANIZATION_ID))) .thenThrow(NoSuchOrganizationException.class); Organization result = resolvers.deleteOrganizationDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchOrganizationException.class) public void deleteOrganizationDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("organizationId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); Organization expectedResult = mock(Organization.class); expectedResult.setOrganizationId(ORGANIZATION_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("organizationId"))) .thenReturn(789456L); when(localService.deleteOrganization(eq(789456L))) .thenThrow(NoSuchOrganizationException.class); Organization result = resolvers.deleteOrganizationDataFetcher() .get(environment); assertNull(result); }