-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from danieladams456/objectmapper
Objectmapper
- Loading branch information
Showing
4 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[versions] | ||
assertj = '3.27.1' | ||
jackson = '2.18.2' | ||
junit = '5.10.0' | ||
lombok = '1.18.36' | ||
|
||
[libraries] | ||
assertj-core = { group = 'org.assertj', name = 'assertj-core', version.ref = 'assertj' } | ||
jackson-databind = { group = 'com.fasterxml.jackson.core', name = 'jackson-databind', version.ref = 'jackson' } | ||
junit-jupiter = { group = 'org.junit.jupiter', name = 'junit-jupiter', version.ref = 'junit' } | ||
lombok = { group = 'org.projectlombok', name = 'lombok', version.ref = 'lombok' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/com/github/danieladams456/statusvoter/IntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.github.danieladams456.statusvoter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Data; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class IntegrationTest { | ||
@Test | ||
void testSerializeObject() throws IOException { | ||
TestObject data = new TestObject(); | ||
data.setA("test1"); | ||
data.setB("test2"); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
mapper.writeValue(outputStream, data); | ||
assertThat(outputStream.toString()).isEqualTo(""" | ||
{"a":"test1","b":"test2","voter":"INITIAL"}"""); | ||
} | ||
|
||
@Test | ||
void testSerializeRecord() throws IOException { | ||
TestRecord record = new TestRecord("test1", "test2", new StatusVoter()); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
mapper.writeValue(outputStream, record); | ||
assertThat(outputStream.toString()).isEqualTo(""" | ||
{"a":"test1","b":"test2","voter":"INITIAL"}"""); | ||
} | ||
|
||
@Data | ||
private static class TestObject { | ||
private String a; | ||
private String b; | ||
private StatusVoter voter = new StatusVoter(); | ||
} | ||
|
||
private record TestRecord( | ||
String a, | ||
String b, | ||
StatusVoter voter | ||
) { | ||
} | ||
} |