Skip to content

Commit 0da1ab9

Browse files
Add files via upload
1 parent c49eaed commit 0da1ab9

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.customannotations;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class JsonSerializerUnitTest {
9+
10+
@Test
11+
public void givenObjectNotSerializedThenExceptionThrown() throws JsonSerializationException {
12+
Object object = new Object();
13+
ObjectToJsonConverter serializer = new ObjectToJsonConverter();
14+
serializer.convertToJson(object);
15+
assertThrows(JsonSerializationException.class, () -> {
16+
serializer.convertToJson(object);
17+
});
18+
}
19+
20+
@Test
21+
public void givenObjectSerializedThenTrueReturned() throws JsonSerializationException {
22+
Person person = new Person("soufiane", "cheouati", "34");
23+
ObjectToJsonConverter serializer = new ObjectToJsonConverter();
24+
String jsonString = serializer.convertToJson(person);
25+
assertEquals("{\"personAge\":\"34\",\"firstName\":\"Soufiane\",\"lastName\":\"Cheouati\"}", jsonString);
26+
}
27+
}

0 commit comments

Comments
 (0)