webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java
branchstatistics-and-elo
changeset 179 c5fbddc4c590
parent 178 4b78d4f028b3
child 258 935118a5831a
     1.1 --- a/webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java	Thu Jan 07 22:34:17 2010 +0100
     1.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/QuoridorTest.java	Thu Jan 07 22:51:17 2010 +0100
     1.3 @@ -26,6 +26,8 @@
     1.4  
     1.5  package cz.xelfi.quoridor.webidor;
     1.6  
     1.7 +import cz.xelfi.quoridor.IllegalPositionException;
     1.8 +import java.io.StringWriter;
     1.9  import com.sun.jersey.api.client.GenericType;
    1.10  import com.sun.jersey.api.client.UniformInterfaceException;
    1.11  import com.sun.jersey.core.header.MediaTypes;
    1.12 @@ -38,6 +40,7 @@
    1.13  import java.io.FileOutputStream;
    1.14  import java.io.FileReader;
    1.15  import java.io.IOException;
    1.16 +import java.io.StringReader;
    1.17  import java.util.List;
    1.18  import java.util.Map;
    1.19  import javax.ws.rs.core.MediaType;
    1.20 @@ -201,7 +204,7 @@
    1.21  
    1.22          class GMap extends GenericType<Map<String,Object>>{}
    1.23          String text = webResource.path("games").path(s.getId()).accept(MediaType.TEXT_PLAIN).get(String.class);
    1.24 -        text = (new Board(text)).boardToPicture();
    1.25 +        text = (boardToPicture(Board.valueOf(text)));
    1.26          if (text.indexOf("-----") == -1) {
    1.27              fail("Expecting board:\n" + text);
    1.28          }
    1.29 @@ -209,12 +212,25 @@
    1.30          String sGame = webResource.path("games").path(s.getId()).accept(MediaType.TEXT_XML).get(String.class);
    1.31          assertNotNull("Game really returned", readGame);
    1.32  //        assertEquals("Same game as in text representation", readGame.getBoard(), Board.valueOf(text));
    1.33 -        assertEquals("Same game as in text representation", readGame.getBoard(), Board.picture2board(text));
    1.34 +        assertEquals("Same game as in text representation", readGame.getBoard(), picture2board(text));
    1.35  //        assertEquals("It is same as text of our game", readGame.getBoard().toString(), text);
    1.36 -        assertEquals("It is same as text of our game", readGame.getBoard().boardToPicture(), text);
    1.37 +        assertEquals("It is same as text of our game", boardToPicture(readGame.getBoard()), text);
    1.38  
    1.39          assertEquals(Move.NORTH, readGame.getMoves().get(0).getMove());
    1.40          assertEquals(Move.SOUTH, readGame.getMoves().get(1).getMove());
    1.41      }
    1.42 +    private static String boardToPicture(Board b) {
    1.43 +        StringWriter w = new StringWriter();
    1.44 +        try {
    1.45 +            b.write(w);
    1.46 +        } catch (IOException ex) {
    1.47 +            return ex.toString();
    1.48 +        }
    1.49 +        return w.toString();
    1.50 +    }
    1.51  
    1.52 +    private static Board picture2board(String text) throws IOException, IllegalPositionException {
    1.53 +        StringReader sr = new StringReader(text);
    1.54 +        return Board.read(sr);
    1.55 +    }
    1.56  }