### Question:
G2Client { public void loginToGallery(String galleryUrl, String user, String password) throws ImpossibleToLoginException { sessionCookies.clear(); sessionCookies.add(new BasicClientCookie("", "")); List<NameValuePair> sb = new ArrayList<NameValuePair>(); sb.add(LOGIN_CMD_NAME_VALUE_PAIR); sb.add(new BasicNameValuePair("g2_form[uname]", "" + user)); sb.add(new BasicNameValuePair("g2_form[password]", "" + password)); HashMap<String, String> properties; try { properties = sendCommandToGallery(galleryUrl, sb, null); } catch (GalleryConnectionException e) { throw new ImpossibleToLoginException(e); } authToken = null; if (properties.get("status") != null) { if (properties.get("status").equals(GR_STAT_SUCCESS)) { authToken = properties.get("auth_token"); } else { throw new ImpossibleToLoginException( properties.get("status_text")); } } if(properties.isEmpty()){ throw new ImpossibleToLoginException("The Gallery did not return login properties; check your gallery installation and/or your settings" ); } } G2Client(String userAgent); HashMap<String, String> fetchImages(String galleryUrl, int albumName); HashMap<String, String> fetchAlbums(String galleryUrl); void loginToGallery(String galleryUrl, String user, String password); InputStream getInputStreamFromUrl(String url); int createNewAlbum(String galleryUrl, int parentAlbumName,
			String albumName, String albumTitle, String albumDescription); int sendImageToGallery(String galleryUrl, int albumName,
			File imageFile, String imageName, String summary, String description); String getAuthToken(); void setAuthToken(String authToken); List<Cookie> getSessionCookies(); Collection<G2Picture> extractG2PicturesFromProperties(
			HashMap<String, String> fetchImages); Map<Integer, Album> getAllAlbums(String galleryUrl); Map<Integer, G2Album> extractAlbumFromProperties(
			HashMap<String, String> albumsProperties); Album organizeAlbumsHierarchy(Map<Integer, G2Album> albums); void setRootAlbum(G2Album rootAlbum); G2Album getRootAlbum();  }### Answer:
@Test(expected = ImpossibleToLoginException.class) public void loginToGalleryTestFailBecauseUrlIsWrong() throws GalleryConnectionException { g2ConnectionUtils.loginToGallery("http: "hackerPassword"); }
@Test public void loginToGalleryTest() throws GalleryConnectionException { g2ConnectionUtils .loginToGallery(galleryUrl, user, password); HashMap<String, String> fetchAlbums = g2ConnectionUtils .fetchAlbums(galleryUrl); boolean found = false; for (Entry<String, String> entry : fetchAlbums.entrySet()) { if (entry.getValue().equals("G2AndroidSecretAlbum")) { found = true; } } assertEquals(true, found); }
@Test(expected=ImpossibleToLoginException.class) public void loginToGalleryTest__badPassword() throws GalleryConnectionException { g2ConnectionUtils.loginToGallery(galleryUrl, "hacker", "hackerPassword"); }
@Test(expected=ImpossibleToLoginException.class) public void loginToGalleryTest__galleryDoesNotAnswerWithProperties__issue24() throws GalleryConnectionException { g2ConnectionUtils.loginToGallery("http: "g2android", "g2android"); }