AddRoleTask extends Task { @Override public void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer) throws AuthenticationException, UnknownHostException { printer.println("Adding role..."); final String user = args.get(ServerAPI.USER_PARAM).asList().get(0); final String roleParam = args.get(ServerAPI.USER_ROLE_PARAM).asList().get(0); final AvailableRoles role = DbCredential.getRole(roleParam); if(user == null || role == null){ printer.println("ERROR: Bad request! The provided credential are unhealthy or incomplete."); return; } repoHandler.addUserRole(user, role); printer.println("Task performed successfully."); } AddRoleTask(final RepositoryHandler repoHandler); @Override void execute(final ImmutableMultimap<String, String> args, final PrintWriter printer);  }
@Test public void testAddRole(){ final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class); final AddRoleTask task = new AddRoleTask(repositoryHandler); final ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<String, String>(); builder.put(ServerAPI.USER_PARAM, "user"); builder.put(ServerAPI.USER_ROLE_PARAM, "data_updater"); Exception exception = null; try { task.execute(builder.build(), mock(PrintWriter.class)); } catch (Exception e) { exception = e; } assertNull(exception); verify(repositoryHandler, times(1)).addUserRole("user", AvailableRoles.DATA_UPDATER); }