View Javadoc
1   package org.oxerr.commons.ws.rs.exceptionmapper;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   import static org.junit.jupiter.api.Assertions.assertNull;
5   import static org.junit.jupiter.api.Assertions.assertTrue;
6   
7   import org.junit.jupiter.api.Test;
8   
9   import com.fasterxml.jackson.core.JsonProcessingException;
10  import com.fasterxml.jackson.databind.ObjectMapper;
11  
12  class ErrorEntityTest {
13  
14  	@Test
15  	void testErrorEntity() throws JsonProcessingException {
16  		ErrorEntity errorEntity = new ErrorEntity();
17  		assertNull(errorEntity.getCode());
18  
19  		errorEntity = new ErrorEntity(10001, "The error message");
20  		assertNull(errorEntity.getException());
21  
22  		errorEntity = new ErrorEntity(10001, "The error message.", new Exception());
23  
24  		errorEntity.setCode(10002);
25  		assertEquals(10002, errorEntity.getCode());
26  
27  		errorEntity.setMessage("some error occurred");
28  		assertEquals("some error occurred", errorEntity.getMessage());
29  
30  		errorEntity.setException(new RuntimeException("some runtime exception"));
31  		assertEquals("some runtime exception", errorEntity.getException().getMessage());
32  
33  		ObjectMapper mapper = new ObjectMapper();
34  		String json = mapper.writeValueAsString(errorEntity);
35  		assertTrue(json.contains("\"exception\":"));
36  	}
37  
38  }