### Question:
BdpImportPortlet extends Sw360Portlet { void setNewImportSource(RemoteCredentials newCredentials, PortletSession session, JSONObject responseData, LoginState loginState) { String serverUrl = nullToEmpty(newCredentials.getServerUrl()); if (serverUrl.isEmpty()) { loginState.logout(); responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__DB_URL_NOT_SET); } else { putRemoteCredentialsIntoSession(session, newCredentials); responseData.put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__DB_CHANGED); responseData.put(ProjectImportConstants.RESPONSE__DB_URL, serverUrl); loginState.login(serverUrl); } }  @Override void doView(RenderRequest request, RenderResponse response); @Override void serveResource(ResourceRequest request, ResourceResponse response); JSONObject handleRequestedAjaxAction(String requestedAction, ResourceRequest request, ResourceResponse response, LoginState loginState);  }### Answer:
@Test public void testUpdateInputSourceWithoutUrl() throws Exception { BdpImportPortlet.LoginState loginState = new BdpImportPortlet.LoginState(); RemoteCredentials remoteCredentials = new RemoteCredentials(); new BdpImportPortlet().setNewImportSource( remoteCredentials, session, responseData, loginState); verify(responseData).put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__DB_URL_NOT_SET); }
@Test public void testUpdateInputSourceWithUrlUpdatesResponse() throws Exception { BdpImportPortlet.LoginState loginState = new BdpImportPortlet.LoginState(); RemoteCredentials remoteCredentials = new RemoteCredentials(); remoteCredentials.setUsername(name); remoteCredentials.setPassword(password); remoteCredentials.setServerUrl(newURL); new BdpImportPortlet().setNewImportSource( remoteCredentials, session, responseData, loginState); verify(responseData).put(ProjectImportConstants.RESPONSE__STATUS, ProjectImportConstants.RESPONSE__DB_CHANGED); verify(responseData).put(ProjectImportConstants.RESPONSE__DB_URL, newURL); }
@Test public void testUpdateInputSourceWithUrlUpdatesSession() throws Exception { BdpImportPortlet.LoginState loginState = new BdpImportPortlet.LoginState(); RemoteCredentials remoteCredentials = new RemoteCredentials(); remoteCredentials.setUsername(name); remoteCredentials.setPassword(password); remoteCredentials.setServerUrl(newURL); new BdpImportPortlet().setNewImportSource( remoteCredentials, session, responseData, loginState); verify(session).setAttribute(ProjectImportConstants.USERNAME, name); verify(session).setAttribute(ProjectImportConstants.PASSWORD, password); verify(session).setAttribute(ProjectImportConstants.SERVER_URL, newURL); }