### Question:
RoomServiceImpl implements RoomService { @Override public List<Room> findRoomsByType(String type) { if (roomTypes.contains(type)) { return roomRepo.findRoomsByRoomType(type); } else { throw new RoomServiceException("Room type: " + type + " not found!"); } } RoomServiceImpl(RoomRepo roomRepo, List<String> roomTypes); @Override List<Room> findRoomsByType(String type); @Override List<Room> findRoomsByFloor(String floor); Room addRoom(Room room);  }### Answer:
@Test public void testFindByValidRoomType() { RoomRepo repo = mock(RoomRepo.class); RoomServiceImpl service = new RoomServiceImpl(repo, roomTypes); when(repo.findRoomsByRoomType("Single")).thenReturn(Arrays.asList( new Room(1L, "100", "Single", new BigDecimal(145.99)))); List<Room> rooms = service.findRoomsByType("Single"); assertEquals(1, rooms.size()); }
@Test public void testFindByInvalidRoomType() { RoomRepo repo = mock(RoomRepo.class); RoomServiceImpl service = new RoomServiceImpl(repo, roomTypes); verify(repo, times(0)).findRoomsByRoomType(any()); expectedException.expect(RoomServiceException.class); expectedException.expectMessage("Room type: NOT FOUND not found!"); service.findRoomsByType("NOT FOUND"); }
@Test public void testFindByNullRoomType() { RoomRepo repo = mock(RoomRepo.class); RoomServiceImpl service = new RoomServiceImpl(repo, roomTypes); verify(repo, times(0)).findRoomsByRoomType(any()); RoomServiceException e = assertThrows(RoomServiceException.class, () -> service.findRoomsByType(null)); assertEquals("Room type: null not found!", e.getMessage()); }