Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.reflections.Reflections;

import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -22,7 +21,6 @@
import java.util.Set;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


Expand All @@ -36,9 +34,6 @@ public class DateServletTest {
@Mock
private HttpServletResponse response;

@Mock
private ServletOutputStream outputStream;

private Object dateServletObject;
private Class<?> dateServletClass;

Expand All @@ -56,12 +51,14 @@ public void init() throws ClassNotFoundException, IllegalAccessException, Invoca

@Test
@Order(1)
@DisplayName("DateServlet class exists")
void dateServletClassExists() throws ClassNotFoundException {
Class.forName(SERVLET_PACKAGE + "." + DATE_SERVLET);
}

@Test
@Order(2)
@DisplayName("DateServlet class extends HttpServlet")
void dateServletExtendsHttpServlet() {

Set<Class<? extends HttpServlet>> httpServlets =
Expand All @@ -76,6 +73,7 @@ void dateServletExtendsHttpServlet() {

@Test
@Order(3)
@DisplayName("DateServlet class is marked as @WebServlet")
void dateServletIsMarkedAsWebServlet() {
Set<Class<?>> servlets =
reflections.getTypesAnnotatedWith(WebServlet.class);
Expand All @@ -88,6 +86,7 @@ void dateServletIsMarkedAsWebServlet() {

@Test
@Order(4)
@DisplayName("DateServlet is mapped with \"/date\" path")
void dateServletIsMarkedWithProperPath() throws ClassNotFoundException {
String[] value = Class.forName(SERVLET_PACKAGE + "." + DATE_SERVLET)
.getAnnotation(WebServlet.class).value();
Expand All @@ -96,7 +95,8 @@ void dateServletIsMarkedWithProperPath() throws ClassNotFoundException {

@Test
@Order(5)
void dateServletReturnsDateInResponse() throws IOException, NoSuchMethodException, InvocationTargetException,
@DisplayName("DateServlet returns current date in a response")
void dateServletReturnsDateInResponse() throws IOException, InvocationTargetException,
IllegalAccessException {
Method doGetMethod = getDoGetMethod();

Expand All @@ -108,7 +108,7 @@ void dateServletReturnsDateInResponse() throws IOException, NoSuchMethodExceptio
assertThat(stringWriter.getBuffer().toString()).contains(LocalDate.now().toString());
}

private Method getDoGetMethod() throws NoSuchMethodException {
private Method getDoGetMethod() {
var method = Arrays.stream(dateServletClass.getDeclaredMethods())
.filter(m -> m.getName().equals("doGet"))
.findAny()
Expand Down