PhabricatorDiffInfoCommand extends Command { String getUsernameForAuthorEmail(String email) { String username = null; if (email != null) { username = email.replaceFirst("(.*)@.*$", "$1"); } return username; }  @Override void execute();  }
@Test public void testGetUsernameForAuthorEmailNull() { PhabricatorDiffInfoCommand phabricatorDiffInfoCommand = new PhabricatorDiffInfoCommand(); String usernameForAuthorEmail = phabricatorDiffInfoCommand.getUsernameForAuthorEmail(null); assertEquals(null, usernameForAuthorEmail); }
@Test public void testGetUsernameForAuthorEmail() { PhabricatorDiffInfoCommand phabricatorDiffInfoCommand = new PhabricatorDiffInfoCommand(); String usernameForAuthorEmail = phabricatorDiffInfoCommand.getUsernameForAuthorEmail("username@test.com"); assertEquals("username", usernameForAuthorEmail); }
@Test public void testGetUsernameForAuthorInvalid() { PhabricatorDiffInfoCommand phabricatorDiffInfoCommand = new PhabricatorDiffInfoCommand(); String usernameForAuthorEmail = phabricatorDiffInfoCommand.getUsernameForAuthorEmail("notanemail"); assertEquals("notanemail", usernameForAuthorEmail); }