Skip to content

Implement createUniqueInstance method and improve tests#10

Merged
kapilasrikanth merged 5 commits into
masterfrom
issue-9-getter-setter
Jun 30, 2026
Merged

Implement createUniqueInstance method and improve tests#10
kapilasrikanth merged 5 commits into
masterfrom
issue-9-getter-setter

Conversation

@srikanthkapila

Copy link
Copy Markdown
Collaborator
  1. Creates an instance for clazz and applies increaseValue up to uniquenessIndex times, producing a value that is distinct from instances created with a lower index. Guards against null and ClassCastException returns from changers (stopping the loop early when the changer chain can't produce further distinct values).

  2. GetterTester.java — set a unique value per field before asserting the getter

Replaced the simple forEach with an IntStream.range so each field gets a positional index. Before invoking the getter, FieldUtils.setValue writes a unique value (createUniqueInstance(field.getType(), fieldIndex)) into the field on the shared instance. This ensures:

•  fieldA gets value index=0 (e.g. "www.pojo.pl")
•  fieldB gets value index=1 (e.g. "www.pojo.pl++increased")

A copy-paste getter returning the wrong field will now produce a mismatch → test fails as expected.

  1. GetterAssertionError.java — made public

Was package-private (class), changed to public class so the regression test can reference it.

  1. GetterTesterTest.java — new regression test + CopyPasteGetterBugPojo class

Added Should_Fail_When_Getter_Returns_Wrong_Field_Of_Same_Type, which tests a POJO where getFieldB() erroneously returns fieldA, and asserts that the tester now throws GetterAssertionError.

Added a method to create unique instances of a given class to avoid conflicts in POJO tests.
Add test for incorrect getter returning wrong field type.
Removed unnecessary blank line at the beginning of the file.
@kapilasrikanth kapilasrikanth merged commit 306089e into master Jun 30, 2026
4 checks passed
@kapilasrikanth kapilasrikanth deleted the issue-9-getter-setter branch June 30, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants