'Junit Test Cases to add to solve missing code

I want to add few test cases in this code to run the code successfully.Please find the main class and Testclass below and help to resolve this issue.

Main Class: 
```
/**
 * Allow booking of rooms (by name)
 */
public class BookingSystem {
    private AtomicInteger nextUserIdCounter = new AtomicInteger();
    private Map<String, String> userIds = new HashMap<>();
    /**
     * @return new unique userId for user
     */
    public String registerUser(String name) {
        return userIds.computeIfAbsent(name, ignored -> ("user_"+nextUserIdCounter.incrementAndGet()));
    }
    /**
     * @return meetingId
     */
    public String bookRoom(String roomName, int hour, List<String> userIds) {       
        
        
        
        throw new RuntimeException("Not implemented");
    }
    /**
     * @return true if cancel actually cancelled something
     */
    public boolean cancelBooking(String meetingId) {
        throw new RuntimeException("Not implemented");
    }
    /**
     * @return null or the room name the user should be in at the given hour
     */
    public String whatRoomAtTimeForUser(int hour, String userId) {
        throw new RuntimeException("Not implemented");
    }
}


Below is my Test Class and that we need to make it running.

Test Class :

public class BookingSystemTest {
    static class Fixture {
        BookingSystem system = new BookingSystem();
        String bob = system.registerUser("Bob");
        String fred = system.registerUser("Fred");
        String jane = system.registerUser("Jane");
        String chris = system.registerUser("Chris");
        String zach = system.registerUser("Zach");
    }
    private final String room1 = "room1";
    private final String room2 = "room2";
    private List<String> listOf(String ... v) {
        return Arrays.stream(v).collect(Collectors.toList());
    }
    @Test
    public void testRegisterUsers() {
        Fixture f = new Fixture();
        Assert.assertNotEquals(f.bob, f.fred);
        Assert.assertNotEquals(f.bob, f.jane);
        Assert.assertNotEquals(f.zach, f.jane);
    }
    @Test
    public void makeBookings() {
        Fixture f = new Fixture();
        // Book a room at a time with some users
        f.system.bookRoom(room1, 16, listOf(f.bob, f.fred));
      
        // Book another room at a different time with some users
        f.system.bookRoom(room2, 17, listOf(f.chris, f.zach, f.jane));
    }
    @Test
    public void makeConflictingBookings() {
        Fixture f = new Fixture();
        // Book a room at a time with some users
        f.system.bookRoom(room1, 16, listOf(f.bob, f.fred));
        // Book another room at a different time with some users
        f.system.bookRoom(room2, 17, listOf(f.chris, f.zach, f.jane));
        // Book another meeting in same room with different users
        try {
            f.system.bookRoom(room1, 16, listOf(f.bob, f.fred));
            fail("Should not allow booking");
        } catch (RoomTakenException ex) {
            // good
        }
    }
    @Test
    public void cancelBookingsAllowsNewBooking() {
        Fixture f = new Fixture();
        // Book a room at a time with some users
        String b1 = f.system.bookRoom(room1, 16, listOf(f.bob, f.fred));
        // Book another room at a different time with some users
        f.system.bookRoom(room2, 17, listOf(f.chris, f.zach, f.jane));
        boolean cxld = f.system.cancelBooking(b1);
        Assert.assertTrue(cxld);
        // Re-use room, should now be ok
        f.system.bookRoom(room1, 16, listOf(f.bob, f.fred));
    }
    @Test
    public void discoverMeetingsForUser() {
        Fixture f = new Fixture();
        // Book a room at a time with some users
        f.system.bookRoom(room1, 16, listOf(f.bob, f.fred));
        // Book another room at a different time with some users
        f.system.bookRoom(room2, 17, listOf(f.bob, f.zach, f.jane));
        // Discover
        Assert.assertNull(f.system.whatRoomAtTimeForUser(14, f.bob));
        Assert.assertEquals(room1, f.system.whatRoomAtTimeForUser(16, f.bob));
        Assert.assertEquals(room2, f.system.whatRoomAtTimeForUser(17, f.bob));
        Assert.assertNull(f.system.whatRoomAtTimeForUser(16, f.zach));
        Assert.assertEquals(room2, f.system.whatRoomAtTimeForUser(17, f.zach));
    }
}

I want to add missing TestCases in test class.I am using Java 8 and Junit, this is a hackerrank question where we need to add some missing test cases.This is a normal question where all the Testcase need to be passed.The issue is that testregister() is working successfully.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source