jaroslav@52
|
1 |
/*
|
jaroslav@52
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jaroslav@52
|
3 |
*
|
jaroslav@52
|
4 |
* The contents of this file are subject to the terms of either the GNU
|
jaroslav@52
|
5 |
* General Public License Version 2 only ("GPL") or the Common
|
jaroslav@52
|
6 |
* Development and Distribution License("CDDL") (collectively, the
|
jaroslav@52
|
7 |
* "License"). You may not use this file except in compliance with the
|
jaroslav@52
|
8 |
* License. You can obtain a copy of the License at
|
jaroslav@52
|
9 |
* http://www.netbeans.org/cddl-gplv2.html
|
jaroslav@52
|
10 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jaroslav@52
|
11 |
* specific language governing permissions and limitations under the
|
jaroslav@52
|
12 |
* License. When distributing the software, include this License Header
|
jaroslav@52
|
13 |
* Notice in each file and include the License file at
|
jaroslav@52
|
14 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
jaroslav@52
|
15 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@52
|
16 |
* by Sun in the GPL Version 2 section of the License file that
|
jaroslav@52
|
17 |
* accompanied this code. If applicable, add the following below the
|
jaroslav@52
|
18 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jaroslav@52
|
19 |
* your own identifying information:
|
jaroslav@52
|
20 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jaroslav@52
|
21 |
*
|
jaroslav@52
|
22 |
* Contributor(s):
|
jaroslav@52
|
23 |
*
|
jaroslav@52
|
24 |
* Portions Copyrighted 2009 Jaroslav Tulach
|
jaroslav@52
|
25 |
*/
|
jaroslav@52
|
26 |
|
jaroslav@52
|
27 |
package cz.xelfi.quoridor.webidor;
|
jaroslav@52
|
28 |
|
jaroslav@52
|
29 |
import cz.xelfi.quoridor.webidor.resources.Games;
|
jaroslav@52
|
30 |
import java.io.File;
|
jaroslav@52
|
31 |
import java.io.FileOutputStream;
|
jaroslav@52
|
32 |
import java.io.IOException;
|
jaroslav@52
|
33 |
import org.junit.After;
|
jaroslav@52
|
34 |
import org.junit.Before;
|
jaroslav@52
|
35 |
import org.junit.Test;
|
jaroslav@52
|
36 |
import static org.junit.Assert.*;
|
jaroslav@52
|
37 |
|
jaroslav@52
|
38 |
/**
|
jaroslav@52
|
39 |
*
|
jaroslav@52
|
40 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@52
|
41 |
*/
|
jaroslav@52
|
42 |
public class GamesTest extends Object {
|
jaroslav@52
|
43 |
private File dir;
|
jaroslav@52
|
44 |
|
jaroslav@52
|
45 |
@Before
|
jaroslav@52
|
46 |
public void setUp() throws Exception {
|
jaroslav@52
|
47 |
dir = File.createTempFile("quoridor", ".dir");
|
jaroslav@52
|
48 |
dir.delete();
|
jaroslav@52
|
49 |
System.setProperty("quoridor.dir", dir.getPath());
|
jaroslav@52
|
50 |
}
|
jaroslav@52
|
51 |
|
jaroslav@52
|
52 |
@After
|
jaroslav@52
|
53 |
public void tearDown() throws Exception {
|
jaroslav@52
|
54 |
deleteRec(dir);
|
jaroslav@52
|
55 |
}
|
jaroslav@52
|
56 |
|
jaroslav@52
|
57 |
static void deleteRec(File dir) throws IOException {
|
jaroslav@52
|
58 |
if (dir == null) {
|
jaroslav@52
|
59 |
return;
|
jaroslav@52
|
60 |
}
|
jaroslav@52
|
61 |
File[] arr = dir.listFiles();
|
jaroslav@52
|
62 |
if (arr != null) {
|
jaroslav@52
|
63 |
for (File f : arr) {
|
jaroslav@52
|
64 |
deleteRec(f);
|
jaroslav@52
|
65 |
}
|
jaroslav@52
|
66 |
}
|
jaroslav@52
|
67 |
dir.delete();
|
jaroslav@52
|
68 |
}
|
jaroslav@52
|
69 |
|
jaroslav@52
|
70 |
@Test public void testCreateAGame() throws Exception {
|
jaroslav@52
|
71 |
File f = new File(dir, "x");
|
jaroslav@52
|
72 |
f.getParentFile().mkdirs();
|
jaroslav@52
|
73 |
FileOutputStream os = new FileOutputStream(f);
|
jtulach@79
|
74 |
os.write("# white: W\n# black: B\n# status: IN_PROGRESS\nN S\n\n".getBytes("UTF-8"));
|
jaroslav@52
|
75 |
os.close();
|
jaroslav@52
|
76 |
|
jtulach@79
|
77 |
Thread.sleep(1000);
|
jtulach@79
|
78 |
|
jtulach@79
|
79 |
long middle = f.lastModified();
|
jtulach@79
|
80 |
|
jtulach@79
|
81 |
Thread.sleep(1000);
|
jtulach@79
|
82 |
|
jaroslav@52
|
83 |
Games games = new Games(dir);
|
jaroslav@52
|
84 |
Game g = games.getBoardInfo("x");
|
jaroslav@52
|
85 |
assertNotNull("Game found", g);
|
jaroslav@52
|
86 |
assertNotNull("Board found", g.getBoard());
|
jtulach@79
|
87 |
assertEquals("List of moves has two", 2, g.getMoves().size());
|
jtulach@79
|
88 |
|
jtulach@79
|
89 |
assertEquals("Last move is last touch of the file", middle, g.getId().getModified());
|
jaroslav@52
|
90 |
}
|
jaroslav@52
|
91 |
|
jaroslav@52
|
92 |
}
|