@@ -37,36 +37,36 @@ public class CompositeCodecTests {
37
37
@ Test
38
38
void testWithCodecDelegates () throws IOException {
39
39
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 ),
43
43
SomeClassWithNoDefaultConstructors .class );
44
- assertThat (foo2 ).isEqualTo (foo );
44
+ assertThat (outputInstance ).isEqualTo (inputInstance );
45
45
}
46
46
47
47
@ Test
48
48
void testWithCodecDefault () throws IOException {
49
49
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 ),
53
53
AnotherClassWithNoDefaultConstructors .class );
54
- assertThat (foo2 ).isEqualTo (foo );
54
+ assertThat (outputInstance ).isEqualTo (inputInstance );
55
55
}
56
56
57
57
@ Test
58
58
void testWithUnRegisteredClass () throws IOException {
59
59
// Verify that the default encodes and decodes properly
60
60
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 ),
64
64
SomeClassWithNoDefaultConstructors .class );
65
- assertThat (foo2 ).isEqualTo (foo );
65
+ assertThat (outputInstance ).isEqualTo (inputInstance );
66
66
67
67
// Verify that an exception is thrown if an unknown type is to be encoded.
68
68
assertThatIllegalArgumentException ().isThrownBy (() -> codec .decode (
69
- codec .encode (foo ),
69
+ codec .encode (inputInstance ),
70
70
AnotherClassWithNoDefaultConstructors .class ));
71
71
}
72
72
@@ -79,67 +79,13 @@ private static Codec getFullyQualifiedCodec() {
79
79
80
80
private static Codec onlyDefaultCodec () {
81
81
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 );
83
83
return new CompositeCodec (codecs , new PojoCodec (
84
84
new KryoClassListRegistrar (SomeClassWithNoDefaultConstructors .class )));
85
85
}
86
86
87
- static class SomeClassWithNoDefaultConstructors {
87
+ private record SomeClassWithNoDefaultConstructors ( String val1 , int val2 ) { }
88
88
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 ) { }
144
90
145
91
}
0 commit comments