diff --git a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/PathBasedMetadataObject.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/PathBasedMetadataObject.java index 9720b813fa5..a1963f64539 100644 --- a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/PathBasedMetadataObject.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/PathBasedMetadataObject.java @@ -122,8 +122,13 @@ public int hashCode() { @Override public String toString() { - return "MetadataObject: [fullName=" + fullName() + "], [path=" + path == null - ? "null" - : path + "], [type=" + type + "]"; + String strPath = path == null ? "null" : path; + return "MetadataObject: [fullName=" + + fullName() + + "], [path=" + + strPath + + "], [type=" + + type + + "]"; } } diff --git a/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/common/TestPathBasedMetadataObject.java b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/common/TestPathBasedMetadataObject.java index 3f604b5f389..d2a2291a356 100644 --- a/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/common/TestPathBasedMetadataObject.java +++ b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/common/TestPathBasedMetadataObject.java @@ -47,4 +47,31 @@ public void PathBasedMetadataObjectNotEquals() { Assertions.assertNotEquals(pathBasedMetadataObject1, pathBasedMetadataObject2); } + + @Test + void testToString() { + PathBasedMetadataObject pathBasedMetadataObject1 = + new PathBasedMetadataObject("parent", "name", "path", PathBasedMetadataObject.Type.PATH); + Assertions.assertEquals( + "MetadataObject: [fullName=parent.name], [path=path], [type=PATH]", + pathBasedMetadataObject1.toString()); + + PathBasedMetadataObject pathBasedMetadataObject2 = + new PathBasedMetadataObject("parent", "name", null, PathBasedMetadataObject.Type.PATH); + Assertions.assertEquals( + "MetadataObject: [fullName=parent.name], [path=null], [type=PATH]", + pathBasedMetadataObject2.toString()); + + PathBasedMetadataObject pathBasedMetadataObject3 = + new PathBasedMetadataObject(null, "name", null, PathBasedMetadataObject.Type.PATH); + Assertions.assertEquals( + "MetadataObject: [fullName=name], [path=null], [type=PATH]", + pathBasedMetadataObject3.toString()); + + PathBasedMetadataObject pathBasedMetadataObject4 = + new PathBasedMetadataObject(null, "name", "path", PathBasedMetadataObject.Type.PATH); + Assertions.assertEquals( + "MetadataObject: [fullName=name], [path=path], [type=PATH]", + pathBasedMetadataObject4.toString()); + } }