# HG changeset patch # User Jaroslav Tulach # Date 1262902086 -3600 # Node ID e3fb438103e01beca97af4ca417e389c91be4041 # Parent c92831d4812c721d1a22066c4f001d885d0b7751 Test to verify behaviour of getCode and valueOf diff -r c92831d4812c -r e3fb438103e0 quoridor/src/test/java/cz/xelfi/quoridor/SerializeCodeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/quoridor/src/test/java/cz/xelfi/quoridor/SerializeCodeTest.java Thu Jan 07 23:08:06 2010 +0100 @@ -0,0 +1,73 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * Portions Copyrighted 2009 Jaroslav Tulach + */ +package cz.xelfi.quoridor; + +import cz.xelfi.quoridor.Player.Direction; +import java.io.IOException; + +/** Basic tests in simple configuration. + * + * @author Jaroslav Tulach + */ +public class SerializeCodeTest extends BoardCase { + public SerializeCodeTest (String testName) { + super (testName); + } + + @Override + protected Board move(Board b, int player, Direction... where) throws IllegalPositionException { + try { + Board read = reread(b); + return read.move(read.getPlayers().get(player), where); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + protected Board fence(Board b, int player, char x, int y, Fence.Orientation orie) + throws IllegalPositionException { + try { + Board read = reread(b); + return read.fence(read.getPlayers().get(player), x, y, orie); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + + @Override + protected Board apply(Board b, Move move) throws IllegalPositionException { + try { + Board read = reread(b); + return read.apply(move); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + } + + private Board reread(Board b) throws IOException, IllegalPositionException { + return Board.valueOf(b.getCode()); + } + +}