forked from NewtonGluten/CS401-Group-Four-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package testSuite; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import commsProj.*; | ||
|
||
public class LoggerTest { | ||
|
||
@Test | ||
public void testConstructor() { | ||
//ensure construction was successful | ||
UserStorage userStorage = new UserStorage(); | ||
RoomStorage roomStorage = new RoomStorage(); | ||
Logger logger = new Logger(roomStorage, userStorage); | ||
assertNotNull(logger); | ||
} | ||
|
||
@Test | ||
public void testCreateRoom() { | ||
//setup | ||
UserStorage userStorage = new UserStorage(); | ||
RoomStorage roomStorage = new RoomStorage(); | ||
Logger logger = new Logger(roomStorage, userStorage); | ||
|
||
List<String> users = new ArrayList<String>(); | ||
users.add("user1"); | ||
users.add("user2"); | ||
Room room = new Room(users); | ||
//add the room by the logger | ||
logger.createRoom(room); | ||
//ensure the room storage has the room | ||
assertSame(roomStorage.getRoomById(room.getId()), room); | ||
//ensure the users have the room | ||
assertTrue(userStorage.getUserRooms("user1").contains(room.getId())); | ||
assertTrue(userStorage.getUserRooms("user2").contains(room.getId())); | ||
} | ||
|
||
@Test | ||
public void testAddUserToRoom() { | ||
//setup | ||
UserStorage userStorage = new UserStorage(); | ||
RoomStorage roomStorage = new RoomStorage(); | ||
Logger logger = new Logger(roomStorage, userStorage); | ||
|
||
List<String> users = new ArrayList<String>(); | ||
users.add("user1"); | ||
users.add("user2"); | ||
Room room = new Room(users); | ||
//add the room by the logger | ||
logger.createRoom(room); | ||
//ensure the room does not contain the user and vice versa | ||
assertFalse(userStorage.getUserRooms("user3").contains(room.getId())); | ||
assertFalse(roomStorage.getRoomById(room.getId()).getUsers().contains("user3")); | ||
//add the user to the room | ||
logger.addUserToRoom("user3", room.getId()); | ||
//ensure the users have the room and vice versa | ||
assertTrue(userStorage.getUserRooms("user3").contains(room.getId())); | ||
assertTrue(roomStorage.getRoomById(room.getId()).getUsers().contains("user3")); | ||
} | ||
|
||
@Test | ||
public void testRemoveUserFromRoom() { | ||
//setup | ||
UserStorage userStorage = new UserStorage(); | ||
RoomStorage roomStorage = new RoomStorage(); | ||
Logger logger = new Logger(roomStorage, userStorage); | ||
|
||
List<String> users = new ArrayList<String>(); | ||
users.add("user1"); | ||
users.add("user2"); | ||
Room room = new Room(users); | ||
//add the room by the logger | ||
logger.createRoom(room); | ||
//ensure the room does not contain the user and vice versa | ||
assertTrue(userStorage.getUserRooms("user2").contains(room.getId())); | ||
assertTrue(roomStorage.getRoomById(room.getId()).getUsers().contains("user2")); | ||
//remove the user from the room | ||
logger.removeUserFromRoom("user2", room.getId()); | ||
//ensure the users have the room and vice versa | ||
assertFalse(userStorage.getUserRooms("user2").contains(room.getId())); | ||
assertFalse(roomStorage.getRoomById(room.getId()).getUsers().contains("user2")); | ||
} | ||
|
||
|
||
} |
8 changes: 7 additions & 1 deletion
8
src/commsProj/RoomStorageTest.java → src/testSuite/RoomStorageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters