package org.synyx.urlaubsverwaltung.web;


import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

class ErrorControllerTest {

    private ErrorController sut;

    @BeforeEach
    void setUp() {
        sut = new ErrorController(mock(ErrorAttributes.class));
    }

    @Test
    void errorHtml403() {
        final HttpServletRequest request = new MockHttpServletRequest();
        final HttpServletResponse response = new MockHttpServletResponse();
        response.setStatus(403);

        final ModelAndView modelAndView = sut.errorHtml(request, response);
        assertThat(modelAndView.getViewName()).isEqualTo("thymeleaf/error/403");
        assertThat(modelAndView.getModel()).containsEntry("status", 403);
    }

    @Test
    void errorHtml404() {
        final HttpServletRequest request = new MockHttpServletRequest();
        final HttpServletResponse response = new MockHttpServletResponse();
        response.setStatus(404);

        final ModelAndView modelAndView = sut.errorHtml(request, response);
        assertThat(modelAndView.getViewName()).isEqualTo("thymeleaf/error/404");
        assertThat(modelAndView.getModel()).containsEntry("status", 404);
    }

    @Test
    void errorHtml400() {
        final HttpServletRequest request = new MockHttpServletRequest();
        final HttpServletResponse response = new MockHttpServletResponse();
        response.setStatus(400);

        final ModelAndView modelAndView = sut.errorHtml(request, response);
        assertThat(modelAndView.getViewName()).isEqualTo("thymeleaf/error");
        assertThat(modelAndView.getModel()).containsEntry("status", 400);
    }

    @Test
    void errorHtml500() {
        final HttpServletRequest request = new MockHttpServletRequest();
        final HttpServletResponse response = new MockHttpServletResponse();
        response.setStatus(500);

        final ModelAndView modelAndView = sut.errorHtml(request, response);
        assertThat(modelAndView.getViewName()).isEqualTo("thymeleaf/error");
        assertThat(modelAndView.getModel()).containsEntry("status", 500);
    }
}

@@ -35,17 +35,16 @@
 g.web;%0A%0A
-%0A
 import o
@@ -105,16 +105,139 @@
 ter.
-api.Test
+params.ParameterizedTest;%0Aimport org.junit.jupiter.params.provider.Arguments;%0Aimport org.junit.jupiter.params.provider.MethodSource
 ;%0Aim
@@ -568,16 +568,48 @@
 esponse;
+%0Aimport java.util.stream.Stream;
 %0A%0Aimport
@@ -878,356 +878,270 @@
     
-@Test%0A    void errorHtml403() %7B%0A        final HttpServletRequest request = new MockHttpServletRequest();%0A        final HttpServletResponse response = new MockHttpServletResponse();%0A        response.setStatus(403);%0A%0A        final ModelAndView modelAndView = sut.errorHtml(request, response);%0A        assertThat(modelAndView.getViewName()).isEqualTo(
+private static Stream%3CArguments%3E errorCodes() %7B%0A        return Stream.of(%0A            Arguments.of(400, %22thymeleaf/error%22),%0A            Arguments.of(403, %22thymeleaf/error/403%22),%0A            Arguments.of(404, %22thymeleaf/error/404%22),%0A            Arguments.of(500, 
 %22thy
@@ -1156,129 +1156,133 @@
 rror
-/403%22
+%22)%0A        
 );%0A    
+%7D%0A%0A
     
-assertThat(modelAndView.getModel()).containsEntry(%22status%22, 403);%0A    %7D%0A%0A    @Test%0A    void errorHtml404(
+@ParameterizedTest%0A    @MethodSource(%22errorCodes%22)%0A    void errorHtml(int errorCode, String viewName
 ) %7B%0A
@@ -1457,19 +1457,25 @@
 tStatus(
-404
+errorCode
 );%0A%0A    
@@ -1607,1009 +1607,96 @@
 lTo(
-%22thymeleaf/error/404%22);%0A        assertThat(modelAndView.getModel()).containsEntry(%22status%22, 404);%0A    %7D%0A%0A    @Test%0A    void errorHtml400() %7B%0A        final HttpServletRequest request = new MockHttpServletRequest();%0A        final HttpServletResponse response = new MockHttpServletResponse();%0A        response.setStatus(400);%0A%0A        final ModelAndView modelAndView = sut.errorHtml(request, response);%0A        assertThat(modelAndView.getViewName()).isEqualTo(%22thymeleaf/error%22);%0A        assertThat(modelAndView.getModel()).containsEntry(%22status%22, 400);%0A    %7D%0A%0A    @Test%0A    void errorHtml500() %7B%0A        final HttpServletRequest request = new MockHttpServletRequest();%0A        final HttpServletResponse response = new MockHttpServletResponse();%0A        response.setStatus(500);%0A%0A        final ModelAndView modelAndView = sut.errorHtml(request, response);%0A        assertThat(modelAndView.getViewName()).isEqualTo(%22thymeleaf/error%22);%0A        assertThat(modelAndView.getModel()).containsEntry(%22status%22, 500
+viewName);%0A        assertThat(modelAndView.getModel()).containsEntry(%22status%22, errorCode
 );%0A 

unify tests into ParameterizedTest