Package org.darkhelm.dragonchess.test

Source Code of org.darkhelm.dragonchess.test.BoardTest

package org.darkhelm.dragonchess.test;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URL;

import org.darkhelm.dragonchess.server.board.BoardDef;
import org.darkhelm.dragonchess.shared.enums.Boards;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IUnmarshallingContext;
import org.jibx.runtime.JiBXException;

import org.junit.Test;

public class BoardTest {
  @Test
  public void testAir() {
    try {
      BoardDef board = loadBoard("air.xml");

      assertTrue(board.getType() == Boards.AIR);

    } catch (JiBXException e) {
      fail(e.getMessage());
      e.printStackTrace();

    } catch (IOException e) {
      fail(e.getMessage());
      e.printStackTrace();
    }
  }

  @Test
  public void testLand() {
    try {
      BoardDef board = loadBoard("land.xml");

      assertTrue(board.getType() == Boards.LAND);

    } catch (JiBXException e) {
      fail(e.getMessage());
      e.printStackTrace();

    } catch (IOException e) {
      fail(e.getMessage());
      e.printStackTrace();
    }
  }

  @Test
  public void testUnder() {
    try {
      BoardDef board = loadBoard("under.xml");

      assertTrue(board.getType() == Boards.UNDER);

    } catch (JiBXException e) {
      fail(e.getMessage());
      e.printStackTrace();

    } catch (IOException e) {
      fail(e.getMessage());
      e.printStackTrace();
    }
  }

  private BoardDef loadBoard(String pieceFile) throws JiBXException, IOException {
    URL boardPath = Boards.class.getResource("/xml/boards/" + pieceFile);

    IBindingFactory bfact = BindingDirectory.getFactory(BoardDef.class);

    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
    return (BoardDef) uctx.unmarshalDocument(new BufferedReader(
        new InputStreamReader(boardPath.openStream())), null);
  }
}
TOP

Related Classes of org.darkhelm.dragonchess.test.BoardTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.