Example #1
0
  /** Test that an petty criminal becomes an indentured servant */
  public void testTeachPettyCriminals() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);

    teacher.setLocation(university);
    assertEquals(teacher.getNeededTurnsOfTraining(), 4);
    assertTrue(criminal.canBeStudent(teacher));
    assertEquals(criminal, teacher.getStudent());

    // PETTY_CRIMINALS become INDENTURED_SERVANTS
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(indenturedServantType, criminal.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
Example #2
0
  /**
   * Test that free colonists are trained before indentured servants, which are preferred to petty
   * criminals.
   */
  public void testTeachingOrder() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit indenturedServant = units.next();
    indenturedServant.setType(indenturedServantType);
    indenturedServant.setLocation(colony.getBuilding(townHallType));

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);
    teacher.setLocation(university);

    assertTrue(colonist.canBeStudent(teacher));
    assertTrue(indenturedServant.canBeStudent(teacher));
    assertTrue(criminal.canBeStudent(teacher));

    // Criminal training
    assertEquals(teacher, criminal.getTeacher());
    assertEquals(criminal, teacher.getStudent());
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());

    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(indenturedServantType, criminal.getType());
    criminal.setLocation(getGame().getMap().getTile(10, 8));

    // Servant training
    assertNull(teacher.getStudent());
    ServerTestHelper.newTurn();
    assertEquals(teacher, indenturedServant.getTeacher());
    assertEquals(indenturedServant, teacher.getStudent());
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());

    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(2, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(freeColonistType, indenturedServant.getType());

    // Colonist(former servant) training continues
    assertEquals(teacher, indenturedServant.getTeacher());
    assertEquals(indenturedServant, teacher.getStudent());
    assertEquals(colonist.getTeacher(), null);

    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());
    assertEquals(expertOreMinerType, indenturedServant.getType());
    assertEquals(indenturedServant.getTeacher(), null);

    FreeColTestUtils.setStudentSelection(selection);
  }