webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java
changeset 52 45fb5f885591
child 79 89bca098e14e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/webidor/src/test/java/cz/xelfi/quoridor/webidor/GamesTest.java	Sun Aug 30 16:04:27 2009 +0200
     1.3 @@ -0,0 +1,84 @@
     1.4 +/*
     1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 + *
     1.7 + * The contents of this file are subject to the terms of either the GNU
     1.8 + * General Public License Version 2 only ("GPL") or the Common
     1.9 + * Development and Distribution License("CDDL") (collectively, the
    1.10 + * "License"). You may not use this file except in compliance with the
    1.11 + * License. You can obtain a copy of the License at
    1.12 + * http://www.netbeans.org/cddl-gplv2.html
    1.13 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.14 + * specific language governing permissions and limitations under the
    1.15 + * License.  When distributing the software, include this License Header
    1.16 + * Notice in each file and include the License file at
    1.17 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    1.18 + * particular file as subject to the "Classpath" exception as provided
    1.19 + * by Sun in the GPL Version 2 section of the License file that
    1.20 + * accompanied this code. If applicable, add the following below the
    1.21 + * License Header, with the fields enclosed by brackets [] replaced by
    1.22 + * your own identifying information:
    1.23 + * "Portions Copyrighted [year] [name of copyright owner]"
    1.24 + *
    1.25 + * Contributor(s):
    1.26 + *
    1.27 + * Portions Copyrighted 2009 Jaroslav Tulach
    1.28 + */
    1.29 +
    1.30 +package cz.xelfi.quoridor.webidor;
    1.31 +
    1.32 +import cz.xelfi.quoridor.webidor.resources.Games;
    1.33 +import java.io.File;
    1.34 +import java.io.FileOutputStream;
    1.35 +import java.io.IOException;
    1.36 +import org.junit.After;
    1.37 +import org.junit.Before;
    1.38 +import org.junit.Test;
    1.39 +import static org.junit.Assert.*;
    1.40 +
    1.41 +/**
    1.42 + *
    1.43 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.44 + */
    1.45 +public class GamesTest extends Object {
    1.46 +    private File dir;
    1.47 +
    1.48 +    @Before
    1.49 +    public void setUp() throws Exception {
    1.50 +        dir = File.createTempFile("quoridor", ".dir");
    1.51 +        dir.delete();
    1.52 +        System.setProperty("quoridor.dir", dir.getPath());
    1.53 +    }
    1.54 +
    1.55 +    @After
    1.56 +    public void tearDown() throws Exception {
    1.57 +        deleteRec(dir);
    1.58 +    }
    1.59 +
    1.60 +    static void deleteRec(File dir) throws IOException {
    1.61 +        if (dir == null) {
    1.62 +            return;
    1.63 +        }
    1.64 +        File[] arr = dir.listFiles();
    1.65 +        if (arr != null) {
    1.66 +            for (File f : arr) {
    1.67 +                deleteRec(f);
    1.68 +            }
    1.69 +        }
    1.70 +        dir.delete();
    1.71 +    }
    1.72 +
    1.73 +    @Test public void testCreateAGame() throws Exception {
    1.74 +        File f = new File(dir, "x");
    1.75 +        f.getParentFile().mkdirs();
    1.76 +        FileOutputStream os = new FileOutputStream(f);
    1.77 +        os.write("# white: W\n# black: B\n# status: IN_PROGRESS\n\n\n".getBytes("UTF-8"));
    1.78 +        os.close();
    1.79 +
    1.80 +        Games games = new Games(dir);
    1.81 +        Game g = games.getBoardInfo("x");
    1.82 +        assertNotNull("Game found", g);
    1.83 +        assertNotNull("Board found", g.getBoard());
    1.84 +        assertEquals("List of moves is empty", 0, g.getMoves().size());
    1.85 +    }
    1.86 +
    1.87 +}