예제 #1
0
  @Test
  public void addWorkers() {

    Person worker1 = new Person(crs.getModel());
    Person worker2 = new Person(crs.getModel());

    assertEquals(crs.getWorkers().size(), 2); // it starts with two
    PlantListener fakeListener =
        mock(PlantListener.class); // addSalesDepartmentListener a fake listener
    crs.addListener(fakeListener);
    crs.addWorkers(worker1, worker2);
    worker1.hired(crs.getOwner(), 9999999);
    worker2.hired(crs.getOwner(), 9999999);
    assertEquals(crs.getWorkers().size(), 4);
    assertTrue(crs.getWorkers().contains(worker1));
    assertTrue(crs.getWorkers().contains(worker2));
    Mockito.verify(fakeListener, times(1))
        .changeInWorkforceEvent(
            any(Plant.class),
            any(Integer.class),
            any(
                Integer
                    .class)); // make sure it was called just once!!! That's the all point of this
                              // method
  }
예제 #2
0
  @Before
  public void setUp() throws Exception {

    Blueprint b =
        new Blueprint.Builder()
            .output(DifferentiatedGoodType.CAPITAL, 2)
            .build(); // create a simple output
    macro = new MacroII(1);
    macro.schedule =
        mock(Schedule.class); // put in a fake schedule so we avoid steppables firing at random

    Firm f = new Firm(macro);
    crs = new Plant(b, new Firm(macro));
    crs.setPlantMachinery(
        new CRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, crs, 1f, 1f));
    irs = new Plant(b, new Firm(macro));
    irs.setPlantMachinery(
        new IRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, irs, 1f, 1f));
    drs = new Plant(b, new Firm(macro));
    drs.setPlantMachinery(
        new DRSExponentialMachinery(DifferentiatedGoodType.CAPITAL, f, 0, drs, 1f, 1f));

    Person w1 = new Person(macro);
    Person w2 = new Person(macro);
    crs.addWorker(w1);
    crs.addWorker(w2);
    w1.hired(crs.getOwner(), 9999999);
    w2.hired(crs.getOwner(), 9999999);
    w1 = new Person(macro);
    w2 = new Person(macro);
    irs.addWorker(w1);
    irs.addWorker(w2);
    w1.hired(crs.getOwner(), 9999999);
    w2.hired(crs.getOwner(), 9999999);
    w1 = new Person(macro);
    w2 = new Person(macro);
    drs.addWorker(w1);
    drs.addWorker(w2);
    w1.hired(crs.getOwner(), 9999999);
    w2.hired(crs.getOwner(), 9999999);

    SalesDepartmentAllAtOnce stub = mock(SalesDepartmentAllAtOnce.class);
    crs.getOwner()
        .registerSaleDepartment(
            stub,
            DifferentiatedGoodType
                .CAPITAL); // fake sales department so that you don't sell the stuff you
                           // completeProductionRunNow
    irs.getOwner()
        .registerSaleDepartment(
            stub,
            DifferentiatedGoodType
                .CAPITAL); // fake sales department so that you don't sell the stuff you
                           // completeProductionRunNow
    drs.getOwner()
        .registerSaleDepartment(
            stub,
            DifferentiatedGoodType
                .CAPITAL); // fake sales department so that you don't sell the stuff you
                           // completeProductionRunNow
    when(stub.isSelling(any(Good.class))).thenReturn(Boolean.TRUE);

    crs.setCostStrategy(new EmptyCostStrategy());
    irs.setCostStrategy(new EmptyCostStrategy());
    drs.setCostStrategy(new EmptyCostStrategy());
  }