@Test @DisplayName("A really cool name!") public void testAddRoom() { RoomRepo repo = mock(RoomRepo.class); when(repo.save(any())).thenReturn(new Room(1L, "100", "Single", new BigDecimal(149.99))); RoomServiceImpl service = new RoomServiceImpl(repo, roomTypes); Room newRoom = service.addRoom(new Room()); assertAll( () ->assertEquals(2L, newRoom.getId()), () ->assertEquals("200", newRoom.getRoomNumber()), () ->assertEquals("Dingle", newRoom.getRoomType()), () ->assertEquals(new BigDecimal(249.99), newRoom.getRoomRate()) ); }
public Room addRoom(Room room) { List<String> errorMessages = new ArrayList<>(); if(roomRepo.findByRoomNumber(room.getRoomNumber()) != null) { errorMessages.add("Duplicated room number!"); } return roomRepo.save(room); }
RoomServiceImpl implements RoomService { public Room addRoom(Room room) { List<String> errorMessages = new ArrayList<>(); if(roomRepo.findByRoomNumber(room.getRoomNumber()) != null) { errorMessages.add("Duplicated room number!"); } return roomRepo.save(room); } }
RoomServiceImpl implements RoomService { public Room addRoom(Room room) { List<String> errorMessages = new ArrayList<>(); if(roomRepo.findByRoomNumber(room.getRoomNumber()) != null) { errorMessages.add("Duplicated room number!"); } return roomRepo.save(room); } RoomServiceImpl(RoomRepo roomRepo, List<String> roomTypes); }
RoomServiceImpl implements RoomService { public Room addRoom(Room room) { List<String> errorMessages = new ArrayList<>(); if(roomRepo.findByRoomNumber(room.getRoomNumber()) != null) { errorMessages.add("Duplicated room number!"); } return roomRepo.save(room); } RoomServiceImpl(RoomRepo roomRepo, List<String> roomTypes); @Override List<Room> findRoomsByType(String type); @Override List<Room> findRoomsByFloor(String floor); Room addRoom(Room room); }
RoomServiceImpl implements RoomService { public Room addRoom(Room room) { List<String> errorMessages = new ArrayList<>(); if(roomRepo.findByRoomNumber(room.getRoomNumber()) != null) { errorMessages.add("Duplicated room number!"); } return roomRepo.save(room); } RoomServiceImpl(RoomRepo roomRepo, List<String> roomTypes); @Override List<Room> findRoomsByType(String type); @Override List<Room> findRoomsByFloor(String floor); Room addRoom(Room room);  }