Skip to content

Commit

Permalink
test: add test for updateDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
mastastny committed Sep 2, 2022
1 parent 2e59a11 commit f72ea54
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,33 @@ public void updateDeviceWrongClass() {
Exception exception = assertThrows(DifferentDeviceException.class, () -> {
house.updateDevice("fireplace", tv);
});
assertTrue(exception.getMessage().contains("Updating with different device"));
}

@Test
public void updateDeviceLabelNull() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
house.updateDevice(null, fireplace);
});
assertTrue(exception.getMessage().contains("Label of the device can't be null"));
}

@Test
public void updateDeviceNull() {
devices.put("fireplace", fireplace);
house.setDevices(devices);
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
house.updateDevice("fireplace", null);
});
assertTrue(exception.getMessage().contains("Device parameter can't be null"));
}

@Test
public void updateDeviceWhichIsNotInTheHouse() {
Exception exception = assertThrows(NoSuchElementException.class, () -> {
house.updateDevice("fireplace", fireplace);
});
assertTrue(exception.getMessage().contains("Device with label: fireplace is not present in the house"));

String expectedMessage = "Updating with different device";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
}
}

0 comments on commit f72ea54

Please sign in to comment.