maccamlc commented on a change in pull request #885:
URL: https://github.com/apache/avro/pull/885#discussion_r711493615



##########
File path: lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java
##########
@@ -226,6 +228,73 @@ public void testLogicalTypeInSchemaEquals() {
     assertEqualsFalse("Different logical type", schema1, schema3);
   }
 
+  @Test
+  public void testRegisterLogicalTypeThrowsIfTypeNameInconsistent() {
+    assertThrows("Should error if type name is inconsistent", 
IllegalArgumentException.class,
+        "Provided logicalTypeName 'name' does not match factory typeName 
'different'", () -> {
+          LogicalTypes.register("name", new LogicalTypes.LogicalTypeFactory() {
+            @Override
+            public LogicalType fromSchema(Schema schema) {
+              return LogicalTypes.date();
+            }
+
+            @Override
+            public String getTypeName() {
+              return "different";
+            }
+          });
+          return null;
+        });
+  }
+
+  @Test
+  public void testRegisterLogicalTypeWithName() {
+    final LogicalTypes.LogicalTypeFactory factory = new 
LogicalTypes.LogicalTypeFactory() {
+      @Override
+      public LogicalType fromSchema(Schema schema) {
+        return LogicalTypes.date();
+      }
+
+      @Override
+      public String getTypeName() {
+        return "same";
+      }
+    };
+
+    LogicalTypes.register("same", factory);
+
+    MatcherAssert.assertThat(LogicalTypes.getCustomRegisteredTypes(), 
IsMapContaining.hasEntry("same", factory));
+  }
+
+  @Test
+  public void testRegisterLogicalTypeWithFactoryName() {
+    final LogicalTypes.LogicalTypeFactory factory = new 
LogicalTypes.LogicalTypeFactory() {
+      @Override
+      public LogicalType fromSchema(Schema schema) {
+        return LogicalTypes.date();
+      }
+
+      @Override
+      public String getTypeName() {
+        return "factory";
+      }
+    };
+
+    LogicalTypes.register(factory);
+
+    MatcherAssert.assertThat(LogicalTypes.getCustomRegisteredTypes(), 
IsMapContaining.hasEntry("factory", factory));
+  }
+
+  @Test
+  public void testRegisterLogicalTypeWithFactoryNameNotProvidedWithoutError() {
+    final LogicalTypes.LogicalTypeFactory factory = schema -> 
LogicalTypes.date();
+
+    LogicalTypes.register("logicalTypeName", factory);
+
+    MatcherAssert.assertThat(LogicalTypes.getCustomRegisteredTypes(),
+        IsMapContaining.hasEntry("logicalTypeName", factory));
+  }
+

Review comment:
       Reworked




-- 
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]


Reply via email to