Package org.darkhelm.dragonchess.test

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

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.piece.PieceDef;
import org.darkhelm.dragonchess.shared.enums.Pieces;

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 PieceTest {
  @Test
  public void testBasilisk() {
    try {
      PieceDef piece = loadPiece("basilisk.xml");

      assertTrue(piece.getName() == Pieces.BASILISK);

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

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

  @Test
  public void testCleric() {
    try {
      PieceDef piece = loadPiece("cleric.xml");

      assertTrue(piece.getName() == Pieces.CLERIC);

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

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

  @Test
  public void testDragon() {
    try {
      PieceDef piece = loadPiece("dragon.xml");

      assertTrue(piece.getName() == Pieces.DRAGON);

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

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

  @Test
  public void testDwarf() {
    try {
      PieceDef piece = loadPiece("dwarf.xml");

      assertTrue(piece.getName() == Pieces.DWARF);

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

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

  @Test
  public void testElemental() {
    try {
      PieceDef piece = loadPiece("elemental.xml");

      assertTrue(piece.getName() == Pieces.ELEMENTAL);

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

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

  @Test
  public void testGriffin() {
    try {
      PieceDef piece = loadPiece("griffin.xml");

      assertTrue(piece.getName() == Pieces.GRIFFIN);

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

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

  @Test
  public void testHero() {
    try {
      PieceDef piece = loadPiece("hero.xml");

      assertTrue(piece.getName() == Pieces.HERO);

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

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

  @Test
  public void testKing() {
    try {
      PieceDef piece = loadPiece("king.xml");

      assertTrue(piece.getName() == Pieces.KING);

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

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

  @Test
  public void testMage() {
    try {
      PieceDef piece = loadPiece("mage.xml");

      assertTrue(piece.getName() == Pieces.MAGE);

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

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

  @Test
  public void testOliphant() {
    try {
      PieceDef piece = loadPiece("oliphant.xml");

      assertTrue(piece.getName() == Pieces.OLIPHANT);

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

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

  @Test
  public void testPaladin() {
    try {
      PieceDef piece = loadPiece("paladin.xml");

      assertTrue(piece.getName() == Pieces.PALADIN);

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

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

  @Test
  public void testSylph() {
    try {
      PieceDef piece = loadPiece("sylph.xml");

      assertTrue(piece.getName() == Pieces.SYLPH);

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

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

  @Test
  public void testThief() {
    try {
      PieceDef piece = loadPiece("thief.xml");

      assertTrue(piece.getName() == Pieces.THIEF);

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

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

  @Test
  public void testUnicorn() {
    try {
      PieceDef piece = loadPiece("unicorn.xml");

      assertTrue(piece.getName() == Pieces.UNICORN);

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

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

  @Test
  public void testWarrior() {
    try {
      PieceDef piece = loadPiece("warrior.xml");

      assertTrue(piece.getName() == Pieces.WARRIOR);

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

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

  private PieceDef loadPiece(String pieceFile) throws JiBXException, IOException {
    URL piecePath = Pieces.class.getResource("/xml/pieces/" + pieceFile);

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

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

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

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.