Add RestExceptionHandler test

This commit is contained in:
cugurlu
2019-03-18 00:35:29 +01:00
parent d7960103ee
commit 711b16449c
2 changed files with 18 additions and 1 deletions

View File

@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
public class RestExceptionHandler {
@ExceptionHandler(ApplicationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse applicationException(ApplicationException ex) {
public static ErrorResponse applicationException(ApplicationException ex) {
return new ErrorResponse(ex.getMessage());
}
}

View File

@@ -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());
}
}