Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects

Release 1.1.0

Merged Lorenzo Gandino requested to merge release into main
package eu.europa.ec.simpl.tlsgateway.exceptions;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
import eu.europa.ec.simpl.common.exceptions.StatusException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
class GlobalExceptionHandlerTest {
private GlobalExceptionHandler handler;
@BeforeEach
public void init() {
handler = new GlobalExceptionHandler();
}
@Test
void handleExceptionTest() {
var exception = mock(
StatusException.class,
withSettings()
.useConstructor(HttpStatus.NOT_FOUND, "junit error message")
.defaultAnswer(CALLS_REAL_METHODS));
var result = handler.handleException(exception);
assertThat(result.getStatusCode().value()).isEqualTo(404);
assertThat(result.getBody().getError()).isEqualTo("junit error message");
}
}
Loading