-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from SonarSource-Demos/features/bcipo-add-tests
Add unit tests
- Loading branch information
Showing
4 changed files
with
62 additions
and
4 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
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,34 @@ | ||
import demo.security.util.WebUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class WebUtilsTest { | ||
|
||
@Test | ||
public void getSessionId_withValidRequest() { | ||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | ||
when(request.getRequestedSessionId()).thenReturn("validSessionId"); | ||
|
||
WebUtils.getSessionId(request); | ||
} | ||
|
||
@Test | ||
public void getSessionId_withNullSessionId() { | ||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | ||
when(request.getRequestedSessionId()).thenReturn(null); | ||
|
||
WebUtils.getSessionId(request); | ||
} | ||
|
||
@Test | ||
public void getSessionId_withIOException() { | ||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | ||
when(request.getRequestedSessionId()).thenThrow(new RuntimeException()); | ||
|
||
assertThrows(RuntimeException.class, () -> WebUtils.getSessionId(request)); | ||
} | ||
} |