RoomsResource { @GET @Produces(MediaType.APPLICATION_JSON) public Map<String, Room> getRooms() { LOG.debug("Got a call to get rooms"); return chatApiDao.getRooms().values().stream() .collect(Collectors.toMap(Room::getName, Function.identity())); } RoomsResource(ChatAlyticsConfig config); @VisibleForTesting protected  RoomsResource(IChatApiDAO chatApiDao); @GET @Produces(MediaType.APPLICATION_JSON) Map<String, Room> getRooms(); @GET @Path("room") @Produces(MediaType.APPLICATION_JSON) Room getRoom(@QueryParam(ROOM) String roomName); static final String ROOM_ENDPOINT; }
@Test public void testGetRooms() { Room room1 = new Room("r1", "r1channel", "r1topic", null ,null, "owner1", false, false, null, null); Room room2 = new Room("r2", "r2channel", "r2topic", null ,null, "owner2", false, false, null, null); Map<String, Room> rooms = ImmutableMap.of("r1", room1, "r2", room2); when(chatApiDao.getRooms()).thenReturn(rooms); Map<String, Room> expectedResult = ImmutableMap.of(room1.getName(), room1, room2.getName(), room2); Map<String, Room> result = underTest.getRooms(); assertEquals(expectedResult, result); }