2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * The contents of this file are subject to the terms of either the GNU
5 * General Public License Version 2 only ("GPL") or the Common
6 * Development and Distribution License("CDDL") (collectively, the
7 * "License"). You may not use this file except in compliance with the
8 * License. You can obtain a copy of the License at
9 * http://www.netbeans.org/cddl-gplv2.html
10 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11 * specific language governing permissions and limitations under the
12 * License. When distributing the software, include this License Header
13 * Notice in each file and include the License file at
14 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
15 * particular file as subject to the "Classpath" exception as provided
16 * by Sun in the GPL Version 2 section of the License file that
17 * accompanied this code. If applicable, add the following below the
18 * License Header, with the fields enclosed by brackets [] replaced by
19 * your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Portions Copyrighted 2009 Jaroslav Tulach
27 package cz.xelfi.quoridor.webidor;
29 import cz.xelfi.quoridor.webidor.resources.Games;
30 import cz.xelfi.quoridor.webidor.resources.Quoridor;
32 import java.io.FileOutputStream;
33 import java.io.IOException;
34 import java.util.ResourceBundle;
35 import org.junit.After;
36 import org.junit.Before;
37 import org.junit.Test;
38 import static org.junit.Assert.*;
42 * @author Jaroslav Tulach <jtulach@netbeans.org>
44 public class GamesTest extends Object {
48 public void setUp() throws Exception {
49 dir = File.createTempFile("quoridor", ".dir");
51 System.setProperty("quoridor.dir", dir.getPath());
55 public void tearDown() throws Exception {
59 static void deleteRec(File dir) throws IOException {
63 File[] arr = dir.listFiles();
72 @Test public void testCreateAGame() throws Exception {
73 File f = new File(dir, "x");
74 f.getParentFile().mkdirs();
75 FileOutputStream os = new FileOutputStream(f);
76 os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN S\n\n".getBytes("UTF-8"));
81 long middle = f.lastModified();
85 Games games = new Games(dir, new Quoridor());
86 Game g = games.getBoardInfo("x", -1);
87 assertNotNull("Game found", g);
88 assertNotNull("Board found", g.getBoard());
89 assertEquals("List of moves has two", 2, g.getMoves().size());
91 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
94 @Test public void testLoadGameWithComments() throws Exception {
95 File f = new File(dir, "x");
96 f.getParentFile().mkdirs();
97 FileOutputStream os = new FileOutputStream(f);
98 os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN #good move\n... S # ok move\n\n".getBytes("UTF-8"));
103 long middle = f.lastModified();
107 Games games = new Games(dir, new Quoridor());
108 Game g = games.getBoardInfo("x", -1);
109 assertNotNull("Game found", g);
110 assertNotNull("Board found", g.getBoard());
111 assertEquals("List of moves has two", 2, g.getMoves().size());
113 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
116 @Test public void testLoadGameWithInternationalComments() throws Exception {
117 File f = new File(dir, "x");
118 f.getParentFile().mkdirs();
119 FileOutputStream os = new FileOutputStream(f);
120 ResourceBundle b = ResourceBundle.getBundle("cz/xelfi/quoridor/webidor/TestBundle");
121 String comment = b.getString("COMMENT");
122 os.write(("# white: W\n# black: B\n# status: IN_PROGRESS\nN\n#" +
123 comment + "\n... S # ok move\n\n").getBytes("UTF-8"));
128 long middle = f.lastModified();
132 Games games = new Games(dir, new Quoridor());
133 Game g = games.getBoardInfo("x", -1);
134 assertNotNull("Game found", g);
135 assertNotNull("Board found", g.getBoard());
136 assertEquals("List of moves has two", 2, g.getMoves().size());
137 String commentRead = g.getMoves().get(0).getComments().get(0).getComment();
138 assertEquals(comment, commentRead);
140 assertEquals("Last move is last touch of the file", middle, g.getId().getModified());