convertToJson.java
package com.example.helloworld3.app.welcome;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonConverter {
public String convertToJson(Object object) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(object);
}
}
abcTest.java
package com.example.helloworld3.app.welcome;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
//import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.Assert.*;
import org.junit.Test;
public class abcTest {
@Test
public void testConvertToJsonThrowsException() {
JsonConverter jsonConverter = new JsonConverter();
// Test that calling convertToJson throws JsonProcessingException
assertThrows(JsonProcessingException.class, () -> jsonConverter.convertToJson(new Object()));
}
}