// Path: src/main/java/com/behase/relumin/model/ErrorResponse.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class ErrorResponse {
//     private Error error;
// 
//     public ErrorResponse(String code, String message) {
//         this.error = new Error();
//         this.error.code = code;
//         this.error.message = message;
//     }
// 
//     @Data
//     public static class Error {
//         private String code;
//         private String message;
//     }
// }


import com.behase.relumin.model.ErrorResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import javax.servlet.http.HttpServletRequest;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
package com.behase.relumin.controller;




@RunWith(MockitoJUnitRunner.class)
public class MyErrorControllerTest {
    @InjectMocks
    @Spy
    private MyErrorController controller = new MyErrorController();

    @Test
    public void handleError_status_code_is_404_or_url_is_error_path_then_return_404_not_found() throws Exception {
        HttpServletRequest request;
        ResponseEntity<ErrorResponse> result;

        request = mock(HttpServletRequest.class);
        doReturn(404).when(request).getAttribute("javax.servlet.error.status_code");

        result = controller.handleError(request);
        assertThat(result.getBody().getError().getCode(), is("404"));
        assertThat(result.getBody().getError().getMessage(), is("Not Found."));

        request = mock(HttpServletRequest.class);
        doReturn("/error").when(request).getRequestURI();

        result = controller.handleError(request);
        assertThat(result.getBody().getError().getCode(), is("404"));
        assertThat(result.getBody().getError().getMessage(), is("Not Found."));
    }

    @Test
    public void handleError() throws Exception {
        HttpServletRequest request = mock(HttpServletRequest.class);
        doReturn(500).when(request).getAttribute("javax.servlet.error.status_code");
        doReturn("error").when(request).getAttribute("javax.servlet.error.message");

// Path: src/main/java/com/behase/relumin/model/ErrorResponse.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class ErrorResponse {
//     private Error error;
// 
//     public ErrorResponse(String code, String message) {
//         this.error = new Error();
//         this.error.code = code;
//         this.error.message = message;
//     }
// 
//     @Data
//     public static class Error {
//         private String code;
//         private String message;
//     }
// }


// Path: src/test/java/com/behase/relumin/controller/MyErrorControllerTest.java
import com.behase.relumin.model.ErrorResponse;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import javax.servlet.http.HttpServletRequest;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

package com.behase.relumin.controller;




@RunWith(MockitoJUnitRunner.class)
public class MyErrorControllerTest {
    @InjectMocks
    @Spy
    private MyErrorController controller = new MyErrorController();

    @Test
    public void handleError_status_code_is_404_or_url_is_error_path_then_return_404_not_found() throws Exception {
        HttpServletRequest request;
        ResponseEntity<ErrorResponse> result;

        request = mock(HttpServletRequest.class);
        doReturn(404).when(request).getAttribute("javax.servlet.error.status_code");

        result = controller.handleError(request);
        assertThat(result.getBody().getError().getCode(), is("404"));
        assertThat(result.getBody().getError().getMessage(), is("Not Found."));

        request = mock(HttpServletRequest.class);
        doReturn("/error").when(request).getRequestURI();

        result = controller.handleError(request);
        assertThat(result.getBody().getError().getCode(), is("404"));
        assertThat(result.getBody().getError().getMessage(), is("Not Found."));
    }

    @Test
    public void handleError() throws Exception {
        HttpServletRequest request = mock(HttpServletRequest.class);
        doReturn(500).when(request).getAttribute("javax.servlet.error.status_code");
        doReturn("error").when(request).getAttribute("javax.servlet.error.message");

        ResponseEntity<ErrorResponse> result = controller.handleError(request);