Example #1
0
  @Test
  public void testTurnOffLigt() {
    TurnCommand turnOff = new TurnOffCommand();
    Light light = new Light();
    turnOff.setLight(light);
    Switcher switcher = new Switcher(null, turnOff);
    switcher.flipDown();
    assertFalse(light.isTurnedOn());

    try {
      turnOff.setLight(null);
      turnOff.execute();
      fail();
    } catch (NullPointerException e) {
    }
  }
Example #2
0
  @Test
  public void testTurnOnLight() {
    TurnCommand turnOn = new TurnOnCommand();
    Light light = new Light();
    turnOn.setLight(light);
    Switcher switcher = new Switcher(turnOn, null);
    switcher.flipUp();
    assertTrue(light.isTurnedOn());

    try {
      turnOn.setLight(null);
      turnOn.execute();
      fail();
    } catch (NullPointerException e) {
    }
  }