### Question:
ExpandoTableResolversImpl implements ExpandoTableResolvers { @Override public DataFetcher<ExpandoTable> updateExpandoTableDataFetcher() { return environment -> { long tableId = util.getLongArg(environment, "tableId"); String name = util.getStringArg(environment, "name"); return expandoTableLocalService.updateTable( tableId, name); }; }  @Reference(unbind = "-") void setExpandoTableLocalService(ExpandoTableLocalService expandoTableLocalService); @Reference void setUtil(GraphQLUtil util); @Override DataFetcher<List<ExpandoTable>> getExpandoTablesDataFetcher(); @Override DataFetcher<CompletableFuture<ExpandoTable>> getExpandoTableDataFetcher(); @Override DataFetcher<ExpandoTable> createExpandoTableDataFetcher(); @Override DataFetcher<ExpandoTable> updateExpandoTableDataFetcher(); @Override DataFetcher<ExpandoTable> deleteExpandoTableDataFetcher();  }### Answer:
@Test public void updateExpandoTableDataFetcher_should_return_updated_object() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("tableId", TABLE_ID); arguments.put("name", NAME); DataFetchingEnvironment environment = getTestEnvironment(arguments); ExpandoTable expectedResult = mock(ExpandoTable.class); expectedResult.setTableId(TABLE_ID); expectedResult.setName(NAME); useMockGraphQLUtil(environment, true); when(localService.updateTable(eq(TABLE_ID), eq(NAME))) .thenReturn(expectedResult); ExpandoTable result = resolvers.updateExpandoTableDataFetcher() .get(environment); assertNotNull(result); assertEquals(expectedResult, result); }
@Test(expected = NoSuchTableException.class) public void updateExpandoTableDataFetcher_with_no_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("name", NAME); DataFetchingEnvironment environment = getTestEnvironment(arguments); useMockGraphQLUtil(environment, true); when(graphQLUtil.getLongArg(eq(environment), eq("tableId"))) .thenReturn(0L); when(localService.updateTable(eq(0L), eq(NAME))) .thenThrow(NoSuchTableException.class); ExpandoTable result = resolvers.updateExpandoTableDataFetcher() .get(environment); assertNull(result); }
@Test(expected = NoSuchTableException.class) public void updateExpandoTableDataFetcher_with_invalid_id_should_return_null_with_exception() throws Exception { Map<String, Object> arguments = new HashMap<>(); arguments.put("tableId", 789456L); arguments.put("name", NAME); DataFetchingEnvironment environment = getTestEnvironment(arguments); useMockGraphQLUtil(environment, true); when(graphQLUtil.getLongArg(eq(environment), eq("tableId"))) .thenReturn(789456L); when(localService.updateTable(eq(789456L), eq(NAME))) .thenThrow(NoSuchTableException.class); ExpandoTable result = resolvers.updateExpandoTableDataFetcher() .get(environment); assertNull(result); }
@Test(expected = PortalException.class) public void updateExpandoTableDataFetcher_without_args_should_throw_validation_exception() throws Exception { DataFetchingEnvironment environment = getTestEnvironment(null); useMockGraphQLUtil(environment, false); when(graphQLUtil.getLongArg(eq(environment), eq("tableId"))) .thenReturn(TABLE_ID); when(localService.updateTable(anyLong(), anyString())) .thenThrow(PortalException.class); ExpandoTable result = resolvers.updateExpandoTableDataFetcher() .get(environment); assertNull(result); }