-
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
1 parent
91812d8
commit a9d9b0d
Showing
7 changed files
with
127 additions
and
16 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
3 changes: 1 addition & 2 deletions
3
.../service/PasswordHashingServiceTests.java → .../service/PasswordHashingServiceTests.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package server; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import server.model.Command; | ||
|
||
/** | ||
* Tests for the Command interface. | ||
*/ | ||
public class CommandTests { | ||
|
||
private final Command command = mock(Command.class); | ||
|
||
|
||
|
||
@Test | ||
@DisplayName(" can correctly send a response") | ||
public void testSendResponse() { | ||
|
||
// TODO | ||
} | ||
|
||
@Test | ||
@DisplayName(" throws an exception when the response cannot be sent") | ||
public void testSendResponseThrowsException() { | ||
// TODO | ||
} | ||
} |
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
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,87 @@ | ||
package server.service; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.io.ObjectOutputStream; | ||
import java.util.Optional; | ||
import model.User; | ||
import model.UserRequest; | ||
import model.enums.Request; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import server.model.Command; | ||
|
||
/** | ||
* Tests for the LoginCommand. | ||
*/ | ||
@DisplayName("The LoginCommand tests ") | ||
public class LoginCommandTests { | ||
|
||
@Mock | ||
private static final Command command = mock(Command.class); | ||
private static UserRequest userRequest; | ||
private static LoginCommand loginCommand; | ||
private static ObjectOutputStream out; | ||
@Mock | ||
private static AuthenticationService authenticationService; | ||
private static User user; | ||
|
||
/** | ||
* Sets up the test suite. | ||
* | ||
* @throws IOException if an I/O error occurs when closing resources. | ||
*/ | ||
@BeforeAll | ||
public static void setUp() throws IOException { | ||
authenticationService = mock(AuthenticationService.class); | ||
out = new ObjectOutputStream(System.out); | ||
loginCommand = new LoginCommand(authenticationService, out); | ||
user = new User("testUser", "testPassword"); | ||
userRequest = new UserRequest(Request.LOGIN, user); | ||
when(command.sendResponse(any(), any())).thenReturn(true); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName(" can correctly handle a login command") | ||
public void testHandle() { | ||
assertTrue(loginCommand.handle(userRequest)); | ||
} | ||
|
||
@Test | ||
@DisplayName(" successfully writes the response when the user is not registered") | ||
public void testHandleNotRegisteredUser() { | ||
when(authenticationService.getUserByUsername(any())).thenReturn(Optional.empty()); | ||
assertTrue(loginCommand.handle(userRequest)); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName(" successfully writes the response when the user is registered") | ||
public void testHandleRegisteredUser() { | ||
when(authenticationService.getUserByUsername(any())).thenReturn(Optional.of(user)); | ||
assertTrue(loginCommand.handle(userRequest)); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName(" successfully writes the response " | ||
+ "when the user is registered but the password is wrong") | ||
public void testHandleRegisteredUserWrongPassword() { | ||
final User wrongUser = new User("testUser", "wrongPassword"); | ||
when(authenticationService.getUserByUsername(any())).thenReturn(Optional.of(wrongUser)); | ||
assertTrue(loginCommand.handle(userRequest)); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} |