@@ -37,36 +37,36 @@ public class CompositeCodecTests {
3737 @ Test
3838 void testWithCodecDelegates () throws IOException {
3939 Codec codec = getFullyQualifiedCodec ();
40- SomeClassWithNoDefaultConstructors foo = new SomeClassWithNoDefaultConstructors ("hello" , 123 );
41- SomeClassWithNoDefaultConstructors foo2 = codec .decode (
42- codec .encode (foo ),
40+ SomeClassWithNoDefaultConstructors inputInstance = new SomeClassWithNoDefaultConstructors ("hello" , 123 );
41+ SomeClassWithNoDefaultConstructors outputInstance = codec .decode (
42+ codec .encode (inputInstance ),
4343 SomeClassWithNoDefaultConstructors .class );
44- assertThat (foo2 ).isEqualTo (foo );
44+ assertThat (outputInstance ).isEqualTo (inputInstance );
4545 }
4646
4747 @ Test
4848 void testWithCodecDefault () throws IOException {
4949 Codec codec = getFullyQualifiedCodec ();
50- AnotherClassWithNoDefaultConstructors foo = new AnotherClassWithNoDefaultConstructors ("hello" , 123 );
51- AnotherClassWithNoDefaultConstructors foo2 = codec .decode (
52- codec .encode (foo ),
50+ AnotherClassWithNoDefaultConstructors inputInstance = new AnotherClassWithNoDefaultConstructors ("hello" , 123 );
51+ AnotherClassWithNoDefaultConstructors outputInstance = codec .decode (
52+ codec .encode (inputInstance ),
5353 AnotherClassWithNoDefaultConstructors .class );
54- assertThat (foo2 ).isEqualTo (foo );
54+ assertThat (outputInstance ).isEqualTo (inputInstance );
5555 }
5656
5757 @ Test
5858 void testWithUnRegisteredClass () throws IOException {
5959 // Verify that the default encodes and decodes properly
6060 Codec codec = onlyDefaultCodec ();
61- SomeClassWithNoDefaultConstructors foo = new SomeClassWithNoDefaultConstructors ("hello" , 123 );
62- SomeClassWithNoDefaultConstructors foo2 = codec .decode (
63- codec .encode (foo ),
61+ SomeClassWithNoDefaultConstructors inputInstance = new SomeClassWithNoDefaultConstructors ("hello" , 123 );
62+ SomeClassWithNoDefaultConstructors outputInstance = codec .decode (
63+ codec .encode (inputInstance ),
6464 SomeClassWithNoDefaultConstructors .class );
65- assertThat (foo2 ).isEqualTo (foo );
65+ assertThat (outputInstance ).isEqualTo (inputInstance );
6666
6767 // Verify that an exception is thrown if an unknown type is to be encoded.
6868 assertThatIllegalArgumentException ().isThrownBy (() -> codec .decode (
69- codec .encode (foo ),
69+ codec .encode (inputInstance ),
7070 AnotherClassWithNoDefaultConstructors .class ));
7171 }
7272
@@ -79,67 +79,13 @@ private static Codec getFullyQualifiedCodec() {
7979
8080 private static Codec onlyDefaultCodec () {
8181 PojoCodec pojoCodec = new PojoCodec ();
82- Map <Class <?>, Codec > codecs = Map .of (pojoCodec . getClass () , pojoCodec );
82+ Map <Class <?>, Codec > codecs = Map .of (java . util . Date . class , pojoCodec );
8383 return new CompositeCodec (codecs , new PojoCodec (
8484 new KryoClassListRegistrar (SomeClassWithNoDefaultConstructors .class )));
8585 }
8686
87- static class SomeClassWithNoDefaultConstructors {
87+ private record SomeClassWithNoDefaultConstructors ( String val1 , int val2 ) { }
8888
89- private String val1 ;
90-
91- private int val2 ;
92-
93- SomeClassWithNoDefaultConstructors (String val1 , int val2 ) {
94- this .val1 = val1 ;
95- this .val2 = val2 ;
96- }
97-
98- @ Override
99- public boolean equals (Object other ) {
100- if (!(other instanceof SomeClassWithNoDefaultConstructors )) {
101- return false ;
102- }
103- SomeClassWithNoDefaultConstructors that = (SomeClassWithNoDefaultConstructors ) other ;
104- return (this .val1 .equals (that .val1 ) && this .val2 == that .val2 );
105- }
106-
107- @ Override
108- public int hashCode () {
109- int result = this .val1 .hashCode ();
110- result = 31 * result + this .val2 ;
111- return result ;
112- }
113-
114- }
115-
116- static class AnotherClassWithNoDefaultConstructors {
117-
118- private String val1 ;
119-
120- private int val2 ;
121-
122- AnotherClassWithNoDefaultConstructors (String val1 , int val2 ) {
123- this .val1 = val1 ;
124- this .val2 = val2 ;
125- }
126-
127- @ Override
128- public boolean equals (Object other ) {
129- if (!(other instanceof AnotherClassWithNoDefaultConstructors )) {
130- return false ;
131- }
132- AnotherClassWithNoDefaultConstructors that = (AnotherClassWithNoDefaultConstructors ) other ;
133- return (this .val1 .equals (that .val1 ) && this .val2 == that .val2 );
134- }
135-
136- @ Override
137- public int hashCode () {
138- int result = this .val1 .hashCode ();
139- result = 31 * result + this .val2 ;
140- return result ;
141- }
142-
143- }
89+ private record AnotherClassWithNoDefaultConstructors (String val1 , int val2 ) { }
14490
14591}
0 commit comments