// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
// 
//     @Getter
//     private final ErrorInfo errors;
// 
//     public InvalidRequestException(BindingResult bindingResultErrors) {
//         super(bindingResultErrors.toString());
//         this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
//     }
// 
// }
// 
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
// 
//     public NotFoundException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
// 
//     private static final long serialVersionUID = 673514291953827696L;
// 
//     @Getter
//     @Setter
//     private String url;
// 
//     @Getter
//     private List<ErrorItem> errors = new ArrayList<>();
// 
//     public ErrorInfo addError(String field, String message) {
//         errors.add(new ErrorItem().setField(field).setMessage(message));
//         return this;
//     }
// 
//     public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
//         ErrorInfo errorInfo = new ErrorInfo();
//         errors.getFieldErrors()
//                 .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
// 
//         return errorInfo;
//     }
// }


import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
    private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";

    private RestExceptionProcessor restExceptionProcessor;

    private MockHttpServletRequest request;

    @Mock
    private BindingResult errors;

    @Before
    public void setUp() {
        this.request = new MockHttpServletRequest();
        RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
        this.restExceptionProcessor = new RestExceptionProcessor();
    }

    @Test
    public void testEntityNotFound() {
        NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1);

        ErrorInfo errorInfo = restExceptionProcessor.entityNotFound(request, exception);

        assertThat(errorInfo).isNotNull();
        assertThat(errorInfo.getUrl()).isEqualTo(request.getRequestURL().toString());
        assertThat(errorInfo.getErrors()).hasSize(ONE_ITEM);
    }

    @Test
    public void testInvalidPostData() {
        when(errors.getFieldErrors()).thenReturn(createMockListFieldErrors());
// Path: src/main/java/com/edwise/completespring/exceptions/InvalidRequestException.java
// public class InvalidRequestException extends RuntimeException {
// 
//     @Getter
//     private final ErrorInfo errors;
// 
//     public InvalidRequestException(BindingResult bindingResultErrors) {
//         super(bindingResultErrors.toString());
//         this.errors = ErrorInfo.generateErrorInfoFromBindingResult(bindingResultErrors);
//     }
// 
// }
// 
// Path: src/main/java/com/edwise/completespring/exceptions/NotFoundException.java
// public class NotFoundException extends RuntimeException {
// 
//     public NotFoundException(String msg) {
//         super(msg);
//     }
// }
// 
// Path: src/main/java/com/edwise/completespring/exceptions/helpers/ErrorInfo.java
// @Accessors(chain = true)
// @EqualsAndHashCode(doNotUseGetters = true)
// @ToString(doNotUseGetters = true)
// public class ErrorInfo implements Serializable {
// 
//     private static final long serialVersionUID = 673514291953827696L;
// 
//     @Getter
//     @Setter
//     private String url;
// 
//     @Getter
//     private List<ErrorItem> errors = new ArrayList<>();
// 
//     public ErrorInfo addError(String field, String message) {
//         errors.add(new ErrorItem().setField(field).setMessage(message));
//         return this;
//     }
// 
//     public static ErrorInfo generateErrorInfoFromBindingResult(BindingResult errors) {
//         ErrorInfo errorInfo = new ErrorInfo();
//         errors.getFieldErrors()
//                 .forEach(fieldError -> errorInfo.addError(fieldError.getField(), fieldError.getDefaultMessage()));
// 
//         return errorInfo;
//     }
// }


// Path: src/test/java/com/edwise/completespring/controllers/RestExceptionProcessorTest.java
import com.edwise.completespring.exceptions.InvalidRequestException;
import com.edwise.completespring.exceptions.NotFoundException;
import com.edwise.completespring.exceptions.helpers.ErrorInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

    private static final String EXCEPTION_MESSAGE_TEST1 = "No existe la entidad";

    private RestExceptionProcessor restExceptionProcessor;

    private MockHttpServletRequest request;

    @Mock
    private BindingResult errors;

    @Before
    public void setUp() {
        this.request = new MockHttpServletRequest();
        RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.request));
        this.restExceptionProcessor = new RestExceptionProcessor();
    }

    @Test
    public void testEntityNotFound() {
        NotFoundException exception = new NotFoundException(EXCEPTION_MESSAGE_TEST1);

        ErrorInfo errorInfo = restExceptionProcessor.entityNotFound(request, exception);

        assertThat(errorInfo).isNotNull();
        assertThat(errorInfo.getUrl()).isEqualTo(request.getRequestURL().toString());
        assertThat(errorInfo.getErrors()).hasSize(ONE_ITEM);
    }

    @Test
    public void testInvalidPostData() {
        when(errors.getFieldErrors()).thenReturn(createMockListFieldErrors());
        InvalidRequestException exception = new InvalidRequestException(errors);