chaokunyang commented on code in PR #3062:
URL: https://github.com/apache/fory/pull/3062#discussion_r2639192255


##########
java/fory-core/src/test/java/org/apache/fory/serializer/UnionSerializerTest.java:
##########
@@ -0,0 +1,418 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.serializer;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.fory.Fory;
+import org.apache.fory.ForyTestBase;
+import org.apache.fory.config.Language;
+import org.apache.fory.type.union.Union;
+import org.apache.fory.type.union.Union2;
+import org.apache.fory.type.union.Union3;
+import org.apache.fory.type.union.Union4;
+import org.apache.fory.type.union.Union5;
+import org.apache.fory.type.union.Union6;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for {@link UnionSerializer}. Union serialization is only used for 
xlang mode. Union types
+ * are serialized as part of struct fields, where the declared field type 
determines which Union
+ * serializer is used.
+ */
+public class UnionSerializerTest extends ForyTestBase {
+
+  private Fory createXlangFory() {
+    Fory fory = 
Fory.builder().withLanguage(Language.XLANG).requireClassRegistration(true).build();
+    fory.register(StructWithUnion.class);
+    fory.register(StructWithUnion2.class);
+    fory.register(StructWithUnion3.class);
+    fory.register(StructWithUnion4.class);
+    fory.register(StructWithUnion5.class);
+    fory.register(StructWithUnion6.class);
+    return fory;
+  }
+
+  // Test struct classes with Union fields
+  public static class StructWithUnion {
+    public Union union;
+
+    public StructWithUnion() {}
+
+    public StructWithUnion(Union union) {
+      this.union = union;
+    }
+  }
+
+  public static class StructWithUnion2 {
+    public Union2<String, Long> union;
+
+    public StructWithUnion2() {}
+
+    public StructWithUnion2(Union2<String, Long> union) {
+      this.union = union;
+    }
+  }
+
+  public static class StructWithUnion3 {
+    public Union3<Integer, String, Double> union;
+
+    public StructWithUnion3() {}
+
+    public StructWithUnion3(Union3<Integer, String, Double> union) {
+      this.union = union;
+    }
+  }
+
+  public static class StructWithUnion4 {
+    public Union4<Integer, String, Double, Boolean> union;
+
+    public StructWithUnion4() {}
+
+    public StructWithUnion4(Union4<Integer, String, Double, Boolean> union) {
+      this.union = union;
+    }
+  }
+
+  public static class StructWithUnion5 {
+    public Union5<Integer, String, Double, Boolean, Long> union;
+
+    public StructWithUnion5() {}
+
+    public StructWithUnion5(Union5<Integer, String, Double, Boolean, Long> 
union) {
+      this.union = union;
+    }
+  }
+
+  public static class StructWithUnion6 {
+    public Union6<Integer, String, Double, Boolean, Long, Float> union;
+
+    public StructWithUnion6() {}
+
+    public StructWithUnion6(Union6<Integer, String, Double, Boolean, Long, 
Float> union) {
+      this.union = union;
+    }
+  }
+
+  @Test

Review Comment:
   Could we make all those tests as parameterized terts, with `CompatibleMode` 
set `Compatible/SCHEMA_CONSISTENT`.
   
   And we also need to update `ClassDef.FieldType#toTypeToken` to return 
correct union `Type`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to