Add files via upload
This commit is contained in:
parent
c49eaed0e5
commit
0da1ab969a
|
@ -0,0 +1,27 @@
|
||||||
|
package com.baeldung.customannotations;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class JsonSerializerUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenObjectNotSerializedThenExceptionThrown() throws JsonSerializationException {
|
||||||
|
Object object = new Object();
|
||||||
|
ObjectToJsonConverter serializer = new ObjectToJsonConverter();
|
||||||
|
serializer.convertToJson(object);
|
||||||
|
assertThrows(JsonSerializationException.class, () -> {
|
||||||
|
serializer.convertToJson(object);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenObjectSerializedThenTrueReturned() throws JsonSerializationException {
|
||||||
|
Person person = new Person("soufiane", "cheouati", "34");
|
||||||
|
ObjectToJsonConverter serializer = new ObjectToJsonConverter();
|
||||||
|
String jsonString = serializer.convertToJson(person);
|
||||||
|
assertEquals("{\"personAge\":\"34\",\"firstName\":\"Soufiane\",\"lastName\":\"Cheouati\"}", jsonString);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue