Пример #1
0
  @Test
  public void testFindTroopByName() {
    Troop troopE = new Troop();
    troopE.setName("E");
    troopE.setMoney(BigDecimal.ZERO);
    troopE.setMission("mise E");
    troopDao.createTroop(troopE);
    Troop t1 = troopDao.findTroopById(troopE.getId());

    Assert.assertEquals(t1.getName(), "E");
    Assert.assertEquals(t1.getMission(), "mise E");
  }
Пример #2
0
  // Tests for wrong parameters
  @Test
  public void testCreateTroopWithWrongParameters() {

    Troop troopC = new Troop();
    Troop troopD = null;

    try {
      troopDao.createTroop(troopC); // no name assigned
      troopDao.createTroop(troopD); // null argument
      Assert.fail();
    } catch (IllegalArgumentException ex) {
      // OK
    }
  }
Пример #3
0
  @Test
  public void testCreateTroop() {
    EntityManager entityManager = emf.createEntityManager();
    entityManager.getTransaction().begin();
    Troop troopC = new Troop();
    troopC.setName("Testers");
    troopC.setMoney(new BigDecimal("30"));
    troopC.setMission("mise C");
    entityManager.getTransaction().commit();
    entityManager.close();

    troopDao.createTroop(troopC);

    Troop t1 = troopDao.findTroopById(troopC.getId());
    Assert.assertEquals(t1.getName(), "Testers");
    Assert.assertEquals(t1.getMoney().compareTo(new BigDecimal("30")), 0);
    Assert.assertEquals(t1.getMission(), "mise C");
  }
Пример #4
0
  @Test
  public void testFindAllTroops() {
    List<Troop> list = troopDao.findAllTroops();

    for (Iterator<Troop> i = list.iterator(); i.hasNext(); ) {
      Troop t = i.next();
      troopDao.deleteTroop(t);
    }

    troopDao.createTroop(troopA);
    troopDao.createTroop(troopB);

    list = troopDao.findAllTroops();

    Assert.assertEquals(list.size(), 2);

    Assert.assertTrue(list.contains(troopA));
    Assert.assertTrue(list.contains(troopB));
  }