Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.wso2.am.integration.services.jaxrs.peoplesample.bean;

import org.junit.Assert;
import org.junit.Test;

public class PersonTest {

@Test
public void testPersonConstructorAndGetters() {

Person person = new Person();

person.setEmail("john@example.com");
person.setFirstName("John");
person.setLastName("Doe");

Assert.assertEquals("john@example.com", person.getEmail());
Assert.assertEquals("John", person.getFirstName());
Assert.assertEquals("Doe", person.getLastName());
}

@Test
public void testPersonEquality() {

Person p1 = new Person();
p1.setEmail("test@example.com");

Person p2 = new Person();
p2.setEmail("test@example.com");

Assert.assertEquals(p1.getEmail(), p2.getEmail());
Comment on lines +23 to +31
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name testPersonEquality is misleading because it only compares email fields rather than testing object equality (using equals() method). Consider renaming to testPersonEmailEquality or testGetEmailReturnsCorrectValue to accurately reflect what is being tested.

Copilot uses AI. Check for mistakes.
}
Comment on lines +22 to +32
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

testPersonEquality does not test object equality and can never fail.

Two concrete issues:

  1. Trivially-true assertion: Assert.assertEquals(p1.getEmail(), p2.getEmail()) only compares two identical String literals — it will always pass regardless of whether Person implements equals()/hashCode() correctly. This gives false confidence.

  2. Wrong assertEquals argument order: JUnit convention is (expected, actual). Both arguments here are computed values, so a failure message would be unhelpful.

To meaningfully test equality, assert on the Person objects directly (if equals() is implemented) or at minimum fix the argument order and rename the method to reflect what is actually being tested:

🐛 Proposed fix
-    `@Test`
-    public void testPersonEquality() {
-
-        Person p1 = new Person();
-        p1.setEmail("test@example.com");
-
-        Person p2 = new Person();
-        p2.setEmail("test@example.com");
-
-        Assert.assertEquals(p1.getEmail(), p2.getEmail());
-    }
+    `@Test`
+    public void testPersonEqualityBySameEmail() {
+        Person p1 = new Person();
+        p1.setEmail("test@example.com");
+
+        Person p2 = new Person();
+        p2.setEmail("test@example.com");
+
+        // Comparing email field values (expected, actual)
+        Assert.assertEquals("test@example.com", p1.getEmail());
+        Assert.assertEquals("test@example.com", p2.getEmail());
+    }
+
+    `@Test`
+    public void testPersonEqualityByObject() {
+        // Uncomment if Person overrides equals()/hashCode()
+        // Person p1 = new Person();
+        // p1.setEmail("test@example.com");
+        // Person p2 = new Person();
+        // p2.setEmail("test@example.com");
+        // Assert.assertEquals(p1, p2);
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@all-in-one-apim/modules/integration/tests-common/backend-service/jaxrs-app/src/test/java/org/wso2/am/integration/services/jaxrs/peoplesample/bean/PersonTest.java`
around lines 22 - 32, The test testPersonEquality currently compares only the
email strings and uses two computed values in the wrong argument order, so
update it to assert object equality: create two Person instances with identical
fields and use Assert.assertEquals(expectedPerson, actualPerson) (or
Assert.assertTrue(p1.equals(p2))) to verify Person.equals()/hashCode() behavior,
or if you only intend to test the email accessor keep the method name and use
Assert.assertEquals("test@example.com", p1.getEmail()) with the expected-first
argument order; reference Person, testPersonEquality, equals(), and
Assert.assertEquals when making the change.

}
Loading