@Test public void alertedByRoom() { Individual i = builder.withAge(0).withReactionTime(7).build(); IndividualProperty ip = new IndividualProperty(i); Room room = mockRoom(i, true, 0); RoomCell cell = generateCell(room, i, ip); ReactionRuleCompleteRoom rule = generateReactionRule(); context.checking( new Expectations() { { allowing(es).propertyFor(i); will(returnValue(ip)); } }); rule.execute(cell); assertThat(ip.isAlarmed(), is(true)); }
@Test public void roomNotAlerted() { Individual i = builder.withAge(0).withReactionTime(7).buildAndReset(); IndividualProperty ip = new IndividualProperty(i); Room room = mockRoom(i, false, 0); RoomCell cell = generateCell(room, i, ip); ReactionRuleCompleteRoom rule = generateReactionRule(); context.checking( new Expectations() { { exactly(1).of(es).getTimeStep(); will(returnValue(0)); allowing(es).propertyFor(i); will(returnValue(ip)); } }); rule.execute(cell); assertThat(ip.isAlarmed(), is(false)); }
private RoomCell generateCell(Room room, Individual i, IndividualProperty ip) { RoomCell cell = new RoomCell(1, 0, 0, Objects.requireNonNull(room)); cell.getState().setIndividual(Objects.requireNonNull(i)); ip.setCell(cell); return cell; }