### Question:
PermissionManager { public Person createNewUserFromOptions(String login, CommandLine cmdl) { String forename = cmdl.getOptionValue("n"); String surname = cmdl.getOptionValue("s"); String pwd = cmdl.getOptionValue("p"); String affiliation = cmdl.getOptionValue("f"); String addr = cmdl.getOptionValue("a"); String email = cmdl.getOptionValue("e"); String dates = cmdl.getOptionValue("d"); Date date = null; if (dates != null) { try { date = DateUtils.parseDate(dates, VALID_DATE_FORMATS); } catch (ParseException ex) { throw new TabInvalidValueException("Date '" + dates + "' is invalid"); } } String role = cmdl.getOptionValue("r"); if (role != null && !"submitter".equalsIgnoreCase(role) && !"curator".equalsIgnoreCase(role)) { throw new TabInvalidValueException("role value: '" + role + "' is invalid"); } Person result = new Person(); result.setUserName(login); result.setFirstName(forename); result.setLastName(surname); if (pwd != null) { result.setPassword(StringEncryption.getInstance().encrypt(pwd)); } result.setAffiliation(affiliation); result.setAddress(addr); result.setEmail(email); result.setJoinDate(date); if ("submitter".equalsIgnoreCase(role)) { result.setRole(UserRole.SUBMITTER); } else if ("curator".equalsIgnoreCase(role)) { result.setRole(UserRole.CURATOR); } return result; } PermissionManager(EntityManager entityManager); static Options createUserDefOptions(); @SuppressWarnings("static-access") static Options createUserDefOptions(Options baseOptions); @SuppressWarnings("static-access") static Options createPermModOptions(Options baseOptions); static Options createPermModOptions(); Person createNewUserFromOptions(String login, CommandLine cmdl); void validateUser(Person user); long addUser(Person user); void updateUser(Person user); void deleteUser(String login); void setStudyOwners(CommandLine cmdl); void setStudyOwners(String spec); void setStudyOwners(String studyAcc, String operation, String... logins); void setStatus(CommandLine cmdl, VisibilityStatus status); void setVisibility(CommandLine cmdl); void setPrivate(String spec); void setPrivate(String... studyAccs); void setStatus(VisibilityStatus status, String... studyAccs); void setPublic(String spec); void setPublic(String... studyAccs); @SuppressWarnings("unchecked") List<Study> getStudies(); @SuppressWarnings("unchecked") List<Person> getUsers(); Person getUserByLogin(String login); Study getStudyByAcc(String acc); static String formatUser(Person user); static String formatStudy(Study study); final static String[] VALID_DATE_FORMATS; }### Answer:
@Test public void testCreateNewUserFromOptions() throws ParseException { PermissionManager permMgr = new PermissionManager(entityManager); String[] args = new String[]{ "--name", "Marco", "--surename", "Brandizi", "-p", "secret", "--date", "10/09/1973", "-r", "submitter" }; CommandLineParser clparser = new GnuParser(); CommandLine cmdl = clparser.parse(permMgr.createUserDefOptions(), args); Person user = permMgr.createNewUserFromOptions("zakmck", cmdl); out.println(user); assertEquals("Wrong created user!", "zakmck", user.getUserName()); assertEquals("Wrong created user!", "Marco", user.getFirstName()); assertEquals("Wrong created user!", StringEncryption.getInstance().encrypt("secret"), user.getPassword()); assertEquals("Wrong created user!", UserRole.SUBMITTER, user.getRole()); assertEquals("Wrong created user!", new GregorianCalendar(1973, Calendar.SEPTEMBER, 10).getTime(), user.getJoinDate()); }