-
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.
* Adding unit tests for controllers * Update pom.xml version bump * Update README.md * Adding screenshots * Update README.md
- Loading branch information
1 parent
34a17fd
commit 9d76a73
Showing
9 changed files
with
88 additions
and
38 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
src/test/java/com/ironoc/portfolio/controller/CustomErrorControllerTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.ironoc.portfolio.controller; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.web.servlet.view.RedirectView; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CustomErrorControllerTest { | ||
|
||
@InjectMocks | ||
private CustomErrorController customErrorController; | ||
|
||
@Mock | ||
private HttpServletRequest httpServletRequestMock; | ||
|
||
@Mock | ||
private HttpServletResponse httpServletResponseMock; | ||
|
||
@Test | ||
public void test_error_view_success() { | ||
// when | ||
RedirectView result = customErrorController.error(httpServletRequestMock, httpServletResponseMock); | ||
|
||
// then | ||
assertThat(result, is(notNullValue())); | ||
assertThat(result, isA(RedirectView.class)); | ||
} | ||
|
||
@Test | ||
public void test_getErrorPath_success() { | ||
// when | ||
String result = customErrorController.getErrorPath(); | ||
|
||
// then | ||
assertThat(result, is("/error")); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/com/ironoc/portfolio/controller/HomeControllerTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.ironoc.portfolio.controller; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class HomeControllerTest { | ||
|
||
@InjectMocks | ||
private HomeController homeController; | ||
|
||
@Mock | ||
private HttpServletRequest httpServletRequestMock; | ||
|
||
@Test | ||
public void test_index_success() { | ||
// when | ||
String result = homeController.index(httpServletRequestMock); | ||
|
||
// then | ||
verify(httpServletRequestMock).getRequestURI(); | ||
|
||
assertThat(result, is("index")); | ||
} | ||
} |