-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Implementation + Groovy and Java Tests
- Loading branch information
Showing
5 changed files
with
112 additions
and
2 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
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,59 @@ | ||
import com.fasterxml.jackson.jr.ob.JSON | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
/** | ||
* A minor note on running/debugging this test on local, if you are using intellij, please | ||
* change `<packaging>pom</packaging>` to `<packaging>bundle</packaging>`. this is causing | ||
* some issue with the IDE. | ||
*/ | ||
class GroovyRecordsTest { | ||
|
||
@Test | ||
void testRecord() throws Exception { | ||
def json = JSON.std.asString(new Cow("foo", Map<String, String>.of("foo", "bar"))) | ||
def expected = """{"message":"foo","object":{"foo":"bar"}}""" | ||
Assert.assertEquals(expected, json) | ||
} | ||
|
||
@Test | ||
void testRecordEquivalentObjects() throws Exception { | ||
def expected = """{"message":"foo","object":{"foo":"bar"}}""" | ||
|
||
def json = JSON.std.asString(new SimpleGroovyObject("foo", Map<String, String>.of("foo", "bar"))) | ||
Assert.assertEquals(expected, json) | ||
|
||
def json2 = JSON.std.asString(new GroovyObjectWithNamedGetters("foo", Map<String, String>.of("foo", "bar"))) | ||
Assert.assertEquals(expected, json2) | ||
} | ||
} | ||
|
||
class SimpleGroovyObject { | ||
public final String message | ||
public final Map<String, String> object | ||
|
||
SimpleGroovyObject(String message, Map<String, String> object) { | ||
this.message = message | ||
this.object = object | ||
} | ||
} | ||
|
||
class GroovyObjectWithNamedGetters { | ||
private final String message | ||
private final Map<String, String> object | ||
|
||
GroovyObjectWithNamedGetters(String message, Map<String, String> object) { | ||
this.message = message | ||
this.object = object | ||
} | ||
|
||
String message() { | ||
return message | ||
} | ||
|
||
Map<String, String> object() { | ||
return object | ||
} | ||
} | ||
|
||
record Cow(String message, Map<String, String> object) {} |
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,22 @@ | ||
import com.fasterxml.jackson.jr.ob.JSON; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* This test is in test module since the JDK version to be tested is higher than other, and hence supports Records. | ||
*/ | ||
public class Java14RecordTest { | ||
|
||
@Test | ||
public void testJava14RecordSupport() throws IOException { | ||
var expectedString = "{\"message\":\"MOO\",\"object\":{\"Foo\":\"Bar\"}}"; | ||
var json = JSON.std.asString(new Cow("MOO", Map.of("Foo", "Bar"))); | ||
Assert.assertEquals(expectedString, json); | ||
} | ||
|
||
record Cow(String message, Map<String, String> object) { | ||
} | ||
} |