package com.mattrixwv.cipherstream.controller; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException; @Tag("unit-test") @ExtendWith(MockitoExtension.class) public class ExceptionRestControllerTest{ private static final ObjectMapper mapper = new ObjectMapper(); @InjectMocks private ExceptionRestController controller; //Fields private static final String errorMessage = "Error message"; @Test public void testInvalidCipherParameterHandler(){ //Setup variables InvalidCipherParameterException error = new InvalidCipherParameterException(errorMessage); ObjectNode expectedJson = mapper.createObjectNode(); expectedJson.put("message", errorMessage); //Run the function ObjectNode returnJson = controller.invalidCipherParameterHandler(error); //Verify the data assertEquals(expectedJson, returnJson); } @Test public void testGenericExceptionHandler(){ //Setup variables Exception error = new Exception(errorMessage); ObjectNode expectedJson = mapper.createObjectNode(); expectedJson.put("message", errorMessage); //Run the function JsonNode returnJson = controller.genericExceptionHandler(error); //Verify the data assertEquals(expectedJson, returnJson); } }