# HG changeset patch # User Jaroslav Tulach # Date 1290875567 -3600 # Node ID f0a4e8c414197c0aff22a4df5c6f18d1075c0092 # Parent 0897f0832eb552a0ffa66da1e9e9d0acea9c52b6 We have more games and we need to select the new one diff -r 0897f0832eb5 -r f0a4e8c41419 freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java --- a/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Sat Nov 27 09:10:44 2010 +0100 +++ b/freemarkerdor/src/test/java/cz/xelfi/quoridor/freemarkerdor/UITest.java Sat Nov 27 17:32:47 2010 +0100 @@ -17,6 +17,8 @@ */ package cz.xelfi.quoridor.freemarkerdor; +import java.util.Collection; +import java.util.Arrays; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; @@ -29,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.util.HashSet; import java.util.Locale; import java.util.concurrent.Callable; import java.util.regex.Matcher; @@ -194,8 +197,8 @@ } @Test public void testCreateGameOK() throws Exception { - int origGames = new File(dir, "games").list().length; - + Collection origGamesNames= Arrays.asList(new File(dir, "games").list()); + int origGames = origGamesNames.size(); String logTest = apiResource.path("login"). queryParam("name", "test"). @@ -217,14 +220,24 @@ final String txt = res.getEntity(String.class); assertEquals("OK\n" + txt, ClientResponse.Status.OK, res.getClientResponseStatus()); - String[] games = new File(dir, "games").list(); - assertEquals("One new game", origGames + 1, games.length); - - if (txt.indexOf(games[0]) == -1) { - fail(games[0] + " expected inside of:\n" + txt); + + String myGame; + { + String[] games = new File(dir, "games").list(); + assertEquals("One new game", origGames + 1, games.length); + + HashSet newNames = new HashSet(); + newNames.addAll(Arrays.asList(games)); + newNames.removeAll(origGamesNames); + assertEquals("Just one name left: " + newNames, 1, newNames.size()); + myGame = newNames.iterator().next(); } - ClientResponse page = webResource.path("games/" + games[0]). + if (txt.indexOf(myGame) == -1) { + fail(myGame + " expected inside of:\n" + txt); + } + + ClientResponse page = webResource.path("games/" + myGame). cookie(Cookie.valueOf("login=" + logJarda)). get(ClientResponse.class); String ptxt = page.getEntity(String.class); @@ -237,7 +250,7 @@ InputStream img1 = webResource.path(m.group(1)).get(InputStream.class); assertNotNull("image found", img1); - ClientResponse move = apiResource.path("games/" + games[0]). + ClientResponse move = apiResource.path("games/" + myGame). queryParam("loginID", logJarda). queryParam("player", "Jarda").queryParam("move", "N").put(ClientResponse.class); assertEquals("Move OK:\n" + move.getEntity(String.class), ClientResponse.Status.OK, move.getClientResponseStatus()); @@ -245,7 +258,7 @@ InputStream img2 = webResource.path(m.group(1)).get(InputStream.class); assertNotNull("image found", img2); - ClientResponse page2 = webResource.path("games/" + games[0]). + ClientResponse page2 = webResource.path("games/" + myGame). cookie(Cookie.valueOf("login=" + logJarda)). get(ClientResponse.class); String ptxt2 = page2.getEntity(String.class);