Skip to content

Commit 763aa05

Browse files
committed
refactor: Replace string concatenation with text blocks in test
Update AvroSchemaParserDuplicateReferencesTest to use Java text blocks for better readability of Avro schema JSON definitions.
1 parent d85dbed commit 763aa05

File tree

1 file changed

+92
-76
lines changed

1 file changed

+92
-76
lines changed

serdes/generic/serde-common-avro/src/test/java/io/apicurio/registry/serde/avro/AvroSchemaParserDuplicateReferencesTest.java

Lines changed: 92 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,36 @@ public void setup() {
3939
@Test
4040
public void testDuplicateReferencesAreDeduplicated() {
4141
// Create a nested Point schema (similar to io.debezium.data.geometry.Point)
42-
String pointSchemaJson = "{"
43-
+ "\"type\":\"record\","
44-
+ "\"name\":\"Point\","
45-
+ "\"namespace\":\"io.debezium.data.geometry\","
46-
+ "\"fields\":["
47-
+ " {\"name\":\"x\",\"type\":\"double\"},"
48-
+ " {\"name\":\"y\",\"type\":\"double\"}"
49-
+ "]"
50-
+ "}";
42+
String pointSchemaJson = """
43+
{
44+
"type": "record",
45+
"name": "Point",
46+
"namespace": "io.debezium.data.geometry",
47+
"fields": [
48+
{"name": "x", "type": "double"},
49+
{"name": "y", "type": "double"}
50+
]
51+
}
52+
""";
5153

5254
// Use a single Schema.Parser instance to resolve references
5355
Schema.Parser schemaParser = new Schema.Parser();
5456
Schema pointSchema = schemaParser.parse(pointSchemaJson);
5557

5658
// Create a main schema with MULTIPLE fields referencing the same Point schema
5759
// This is what causes duplicate references
58-
String mainSchemaJson = "{"
59-
+ "\"type\":\"record\","
60-
+ "\"name\":\"TableValue\","
61-
+ "\"namespace\":\"io.example\","
62-
+ "\"fields\":["
63-
+ " {\"name\":\"id\",\"type\":\"int\"},"
64-
+ " {\"name\":\"start_point\",\"type\":\"io.debezium.data.geometry.Point\"},"
65-
+ " {\"name\":\"end_point\",\"type\":\"io.debezium.data.geometry.Point\"}"
66-
+ "]"
67-
+ "}";
60+
String mainSchemaJson = """
61+
{
62+
"type": "record",
63+
"name": "TableValue",
64+
"namespace": "io.example",
65+
"fields": [
66+
{"name": "id", "type": "int"},
67+
{"name": "start_point", "type": "io.debezium.data.geometry.Point"},
68+
{"name": "end_point", "type": "io.debezium.data.geometry.Point"}
69+
]
70+
}
71+
""";
6872
Schema mainSchema = schemaParser.parse(mainSchemaJson);
6973

7074
// Create sample data
@@ -140,40 +144,46 @@ public void testNestedDuplicateReferencesAreDeduplicated() {
140144
Schema.Parser schemaParser = new Schema.Parser();
141145

142146
// Create a Coordinate schema
143-
String coordinateSchemaJson = "{"
144-
+ "\"type\":\"record\","
145-
+ "\"name\":\"Coordinate\","
146-
+ "\"namespace\":\"io.example.geo\","
147-
+ "\"fields\":["
148-
+ " {\"name\":\"lat\",\"type\":\"double\"},"
149-
+ " {\"name\":\"lon\",\"type\":\"double\"}"
150-
+ "]"
151-
+ "}";
147+
String coordinateSchemaJson = """
148+
{
149+
"type": "record",
150+
"name": "Coordinate",
151+
"namespace": "io.example.geo",
152+
"fields": [
153+
{"name": "lat", "type": "double"},
154+
{"name": "lon", "type": "double"}
155+
]
156+
}
157+
""";
152158
Schema coordinateSchema = schemaParser.parse(coordinateSchemaJson);
153159

154160
// Create a Location schema that references Coordinate
155-
String locationSchemaJson = "{"
156-
+ "\"type\":\"record\","
157-
+ "\"name\":\"Location\","
158-
+ "\"namespace\":\"io.example.geo\","
159-
+ "\"fields\":["
160-
+ " {\"name\":\"name\",\"type\":\"string\"},"
161-
+ " {\"name\":\"position\",\"type\":\"io.example.geo.Coordinate\"}"
162-
+ "]"
163-
+ "}";
161+
String locationSchemaJson = """
162+
{
163+
"type": "record",
164+
"name": "Location",
165+
"namespace": "io.example.geo",
166+
"fields": [
167+
{"name": "name", "type": "string"},
168+
{"name": "position", "type": "io.example.geo.Coordinate"}
169+
]
170+
}
171+
""";
164172
Schema locationSchema = schemaParser.parse(locationSchemaJson);
165173

166174
// Create a Journey schema with multiple Location fields (which themselves reference Coordinate)
167-
String journeySchemaJson = "{"
168-
+ "\"type\":\"record\","
169-
+ "\"name\":\"Journey\","
170-
+ "\"namespace\":\"io.example\","
171-
+ "\"fields\":["
172-
+ " {\"name\":\"id\",\"type\":\"int\"},"
173-
+ " {\"name\":\"start\",\"type\":\"io.example.geo.Location\"},"
174-
+ " {\"name\":\"end\",\"type\":\"io.example.geo.Location\"}"
175-
+ "]"
176-
+ "}";
175+
String journeySchemaJson = """
176+
{
177+
"type": "record",
178+
"name": "Journey",
179+
"namespace": "io.example",
180+
"fields": [
181+
{"name": "id", "type": "int"},
182+
{"name": "start", "type": "io.example.geo.Location"},
183+
{"name": "end", "type": "io.example.geo.Location"}
184+
]
185+
}
186+
""";
177187
Schema journeySchema = schemaParser.parse(journeySchemaJson);
178188

179189
// Create sample data
@@ -241,40 +251,46 @@ public void testDistinctReferencesArePreserved() {
241251
Schema.Parser schemaParser = new Schema.Parser();
242252

243253
// Create two different nested schemas
244-
String pointSchemaJson = "{"
245-
+ "\"type\":\"record\","
246-
+ "\"name\":\"Point\","
247-
+ "\"namespace\":\"io.example\","
248-
+ "\"fields\":["
249-
+ " {\"name\":\"x\",\"type\":\"double\"},"
250-
+ " {\"name\":\"y\",\"type\":\"double\"}"
251-
+ "]"
252-
+ "}";
253-
254-
String addressSchemaJson = "{"
255-
+ "\"type\":\"record\","
256-
+ "\"name\":\"Address\","
257-
+ "\"namespace\":\"io.example\","
258-
+ "\"fields\":["
259-
+ " {\"name\":\"street\",\"type\":\"string\"},"
260-
+ " {\"name\":\"city\",\"type\":\"string\"}"
261-
+ "]"
262-
+ "}";
254+
String pointSchemaJson = """
255+
{
256+
"type": "record",
257+
"name": "Point",
258+
"namespace": "io.example",
259+
"fields": [
260+
{"name": "x", "type": "double"},
261+
{"name": "y", "type": "double"}
262+
]
263+
}
264+
""";
265+
266+
String addressSchemaJson = """
267+
{
268+
"type": "record",
269+
"name": "Address",
270+
"namespace": "io.example",
271+
"fields": [
272+
{"name": "street", "type": "string"},
273+
{"name": "city", "type": "string"}
274+
]
275+
}
276+
""";
263277

264278
Schema pointSchema = schemaParser.parse(pointSchemaJson);
265279
Schema addressSchema = schemaParser.parse(addressSchemaJson);
266280

267281
// Create main schema referencing both different schemas
268-
String mainSchemaJson = "{"
269-
+ "\"type\":\"record\","
270-
+ "\"name\":\"Location\","
271-
+ "\"namespace\":\"io.example\","
272-
+ "\"fields\":["
273-
+ " {\"name\":\"id\",\"type\":\"int\"},"
274-
+ " {\"name\":\"position\",\"type\":\"io.example.Point\"},"
275-
+ " {\"name\":\"address\",\"type\":\"io.example.Address\"}"
276-
+ "]"
277-
+ "}";
282+
String mainSchemaJson = """
283+
{
284+
"type": "record",
285+
"name": "Location",
286+
"namespace": "io.example",
287+
"fields": [
288+
{"name": "id", "type": "int"},
289+
{"name": "position", "type": "io.example.Point"},
290+
{"name": "address", "type": "io.example.Address"}
291+
]
292+
}
293+
""";
278294
Schema mainSchema = schemaParser.parse(mainSchemaJson);
279295

280296
// Create sample data

0 commit comments

Comments
 (0)