Add RestExceptionHandler test
This commit is contained in:
@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|||||||
public class RestExceptionHandler {
|
public class RestExceptionHandler {
|
||||||
@ExceptionHandler(ApplicationException.class)
|
@ExceptionHandler(ApplicationException.class)
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
public ErrorResponse applicationException(ApplicationException ex) {
|
public static ErrorResponse applicationException(ApplicationException ex) {
|
||||||
return new ErrorResponse(ex.getMessage());
|
return new ErrorResponse(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package greenify.server.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import greenify.common.ApplicationException;
|
||||||
|
import greenify.common.ErrorResponse;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RestExceptionHandlerTest {
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
ApplicationException ex = new ApplicationException("testing");
|
||||||
|
ErrorResponse response = new ErrorResponse("testing");
|
||||||
|
assertEquals(RestExceptionHandler.applicationException(ex)
|
||||||
|
.getMessage(), response.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user