-
Notifications
You must be signed in to change notification settings - Fork 909
Add unit tests for Person bean #13963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
+22
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Two concrete issues:
To meaningfully test equality, assert on the 🐛 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 |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test name
testPersonEqualityis misleading because it only compares email fields rather than testing object equality (using equals() method). Consider renaming totestPersonEmailEqualityortestGetEmailReturnsCorrectValueto accurately reflect what is being tested.