Skip to content
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

Add methods in KiwiReflection to ignore or include specific properties to nullify #522

Closed
sleberknight opened this issue Mar 17, 2021 · 0 comments · Fixed by #523
Closed
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Mar 17, 2021

KiwiReflection has the invokeMutatorMethodsWithNull method which is primarily useful in tests to set all mutable properties to null (e.g. when testing validations). However, sometimes this doesn't work for whatever reason, or you want to nullify only certain properties. This will add three new methods:

  • static void invokeMutatorMethodsWithNullIgnoringProperties(Object target, String... properties)
  • static void invokeMutatorMethodsWithNullIncludingOnlyProperties(Object target, String... properties)
  • static void invokeMutatorMethodsWithNullSatisfying(Object target, Predicate<Method> methodPredicate)

The last method was added b/c it was created to be generic and used by the first two methods, and by itself is also useful, e.g. you could exclude setting properties that are Optional or Iterable to null.

The properties arguments define the name of the logical property, e.g. "firstName" rather than the setter method name. The setter method name will be constructed by prepending "set" and capitalizing the first letter of the property.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Mar 17, 2021
@sleberknight sleberknight added this to the 0.21.0 milestone Mar 17, 2021
@sleberknight sleberknight self-assigned this Mar 17, 2021
sleberknight added a commit that referenced this issue Mar 17, 2021
* invokeMutatorMethodsWithNullIgnoringProperties(target, props...)
* invokeMutatorMethodsWithNullIncludingOnlyProperties(target, props...)
* invokeMutatorMethodsWithNullSatisfying(target, predicate)

Closes #522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant