Copilot commented on code in PR #13442: URL: https://github.com/apache/gravitino/pull/13442#discussion_r4073226467
########## core/src/test/java/org/apache/gravitino/storage/relational/po/TestExtendedGroupPO.java: ########## @@ -0,0 +1,51 @@ +/* + * 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.gravitino.storage.relational.po; + +import org.apache.commons.lang3.reflect.FieldUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Tests for {@link ExtendedGroupPO} equality. */ +public class TestExtendedGroupPO { + + private static ExtendedGroupPO po(String groupName, String roleNames, String roleIds) + throws IllegalAccessException { + ExtendedGroupPO po = new ExtendedGroupPO(); + FieldUtils.writeField(po, "groupName", groupName, true); + FieldUtils.writeField(po, "roleNames", roleNames, true); + FieldUtils.writeField(po, "roleIds", roleIds, true); + return po; + } + + @Test + void testEqualsIncludesGroupFields() throws IllegalAccessException { + // Two different groups with identical role strings must not be equal; the + // parent GroupPO fields (groupId/groupName/metalakeId/...) are part of identity. + Assertions.assertNotEquals(po("group-a", "r1,r2", "1,2"), po("group-b", "r1,r2", "1,2")); + } + + @Test + void testEqualsAndHashCodeConsistent() throws IllegalAccessException { Review Comment: These tests depend on reflective writes with string field names, which is brittle (field renames/encapsulation changes can silently break tests). Prefer constructing `ExtendedGroupPO` via a package-private constructor/factory, test-only builder, or setters designed for tests so refactors are caught at compile time. ########## core/src/test/java/org/apache/gravitino/storage/relational/po/TestExtendedGroupPO.java: ########## @@ -0,0 +1,51 @@ +/* + * 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.gravitino.storage.relational.po; + +import org.apache.commons.lang3.reflect.FieldUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Tests for {@link ExtendedGroupPO} equality. */ +public class TestExtendedGroupPO { + + private static ExtendedGroupPO po(String groupName, String roleNames, String roleIds) + throws IllegalAccessException { + ExtendedGroupPO po = new ExtendedGroupPO(); + FieldUtils.writeField(po, "groupName", groupName, true); + FieldUtils.writeField(po, "roleNames", roleNames, true); + FieldUtils.writeField(po, "roleIds", roleIds, true); + return po; + } + + @Test + void testEqualsIncludesGroupFields() throws IllegalAccessException { + // Two different groups with identical role strings must not be equal; the + // parent GroupPO fields (groupId/groupName/metalakeId/...) are part of identity. Review Comment: The test comment claims multiple `GroupPO` identity fields are part of identity (e.g., `groupId`, `metalakeId`, ...), but the test only varies `groupName`. Either (a) set additional `GroupPO` identity fields in `po(...)` and assert inequality when those differ, or (b) narrow the comment/method intent to explicitly state it’s validating `groupName` participation in equality. -- 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]
