### Question:
LayoutResolversImpl implements LayoutResolvers { @Override public DataFetcher<Layout> deleteLayoutDataFetcher() { return environment -> { long layoutId = util.getLongArg(environment, "layoutId"); return layoutLocalService.deleteLayout(layoutId); }; }  @Reference(unbind = "-") void setLayoutLocalService(LayoutLocalService layoutLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<Layout>> getLayoutsDataFetcher(); @Override DataFetcher<List<Layout>> getLayoutsForGroupDataFetcher(); @Override DataFetcher<CompletableFuture<Layout>> getLayoutDataFetcher(); @Override DataFetcher<Layout> createLayoutDataFetcher(); @Override DataFetcher<Layout> updateLayoutDataFetcher(); @Override DataFetcher<Layout> deleteLayoutDataFetcher();  }### Answer:
@Test public void deleteLayoutDataFetcher_should_return_deleted_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("layoutId", LAYOUT_ID); DataFetchingEnvironment environment = getTestEnvironment(arguments); Layout expectedResult = mock(Layout.class); expectedResult.setLayoutId(LAYOUT_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteLayout(eq(LAYOUT_ID))) .thenReturn(expectedResult); Layout result = resolvers.deleteLayoutDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchLayoutException.class) public void deleteLayoutDataFetcher_without_args_should_return_null_with_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); Layout expectedResult = mock(Layout.class); expectedResult.setLayoutId(LAYOUT_ID); useMockGraphQLUtil(environment, USER_ID, true); when(localService.deleteLayout(eq(LAYOUT_ID))) .thenThrow(NoSuchLayoutException.class); Layout result = resolvers.deleteLayoutDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchLayoutException.class) public void deleteLayoutDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("layoutId", 789456L); DataFetchingEnvironment environment = getTestEnvironment(arguments); Layout expectedResult = mock(Layout.class); expectedResult.setLayoutId(LAYOUT_ID); useMockGraphQLUtil(environment, USER_ID, false); when(graphQLUtil.getLongArg(eq(environment), eq("layoutId"))) .thenReturn(789456L); when(localService.deleteLayout(eq(789456L))) .thenThrow(NoSuchLayoutException.class); Layout result = resolvers.deleteLayoutDataFetcher() .get(environment); assertNull(result); }