LoginDelegator extends BaseDelegator implements ILoginDelegator { @Override public String getLoginStatus() throws P4JavaException { String statusStr = EMPTY; List<Map<String, Object>> resultMaps = execMapCmdList(LOGIN, new String[] { "-s" }, null); if (nonNull(resultMaps) && !resultMaps.isEmpty()) { Map<String, Object> firstResultMap = resultMaps.get(0); IServerMessage message = ResultMapParser.getErrorOrInfoStr(firstResultMap); if (nonNull(message)) { statusStr = message.getErrorOrInfoStr(); } } return isBlank(statusStr) ? EMPTY : statusStr; } LoginDelegator(final IOptionsServer server); @Override String getLoginStatus(); @Override void login(final String password); @Override void login(final String password, final boolean allHosts); @Override boolean isDontWriteTicket(final String cmd, final String[] cmdArgs); @Override void login(final String password, final LoginOptions opts); @Override void login(final String password, final StringBuffer ticket, final LoginOptions opts); @Override void login(@Nonnull final IUser user, final StringBuffer ticket, final LoginOptions opts);  }
@Test public void testLoginStatus() throws P4JavaException { when(server.execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null))) .thenReturn(buildStatusLoggedInResultMap()); String status = loginDelegator.getLoginStatus(); verify(server).execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null)); assertTrue(status.startsWith("User " + TEST_USER + " ticket")); }
@Test public void testLoginStatusNotLoggedIn() throws P4JavaException { when(server.execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null))) .thenReturn(buildStatusNotLoggedInResultMap()); String status = loginDelegator.getLoginStatus(); verify(server).execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null)); assertTrue(status.startsWith("Perforce password")); }
@Test public void testLoginStatusNull() throws P4JavaException { when(server.execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null))) .thenReturn(null); String status = loginDelegator.getLoginStatus(); verify(server).execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null)); assertTrue(isBlank(status)); }
@Test public void testLoginStatusEmpty() throws P4JavaException { when(server.execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null))) .thenReturn(new ArrayList<>()); String status = loginDelegator.getLoginStatus(); verify(server).execMapCmdList(eq(LOGIN.toString()), argThat(STATUS_MATCHER), eq(null)); assertTrue(isBlank(status)); }