### Question:
LayoutResolversImpl implements LayoutResolvers { @Override public DataFetcher<CompletableFuture<Layout>> getLayoutDataFetcher() { return environment -> { long layoutId = util.getLongArg(environment, "layoutId"); if (layoutId <= 0) { return null; } DataLoader<Long, Layout> dataLoader = environment.getDataLoader(LayoutBatchLoader.KEY); return dataLoader.load(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 getLayoutDataFetcher_should_return_the_searched_object() throws Exception { Layout expectedResult = mock(Layout.class); expectedResult.setLayoutId(LAYOUT_ID); useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("layoutId")) .thenReturn(LAYOUT_ID); when(dataLoader.load(LAYOUT_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> expectedResult)); CompletableFuture<Layout> asyncResult = resolvers.getLayoutDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Layout result = asyncResult.get(); assertNotNull(result); assertEquals(expectedResult, result); }
@Test public void getLayoutDataFetcher_no_specified_id_should_return_null() throws Exception { when(mockEnvironment.getArgument("layoutId")) .thenReturn(0L); CompletableFuture<Layout> asyncResult = resolvers.getLayoutDataFetcher() .get(mockEnvironment); assertNull(asyncResult); }
@Test public void getLayoutDataFetcher_with_unknown_id_should_return_null() throws Exception { useSimpleGraphQLUtil(); when(mockEnvironment.getArgument("layoutId")) .thenReturn(LAYOUT_ID); when(dataLoader.load(LAYOUT_ID)) .thenReturn(CompletableFuture.supplyAsync(() -> null)); CompletableFuture<Layout> asyncResult = resolvers.getLayoutDataFetcher() .get(mockEnvironment); assertNotNull(asyncResult); Layout result = asyncResult.get(); assertNull(result); }