-
Notifications
You must be signed in to change notification settings - Fork 44
Backports from 3de4c3b26c1 - Fixes #105 #106
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -12,9 +12,12 @@ | |
| */ | ||
| package org.assertj.assertions.generator.description; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
| import static org.assertj.assertions.generator.util.ClassUtil.propertyNameOf; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.assertj.assertions.generator.util.ClassUtil; | ||
|
|
||
| /** | ||
| * | ||
|
|
@@ -129,4 +132,39 @@ public Class<?> getSuperType() { | |
| public void setSuperType(Class<?> superType) { | ||
| this.superType = superType; | ||
| } | ||
|
|
||
| public GetterDescription findGetterDescriptionForField(FieldDescription base) { | ||
|
Member
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. can you add unit tests for this in
Contributor
Author
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. Wouldn't it make more sense in Edit: It would, but that class doesn't exist... 😅 |
||
| // Build a map for better look-up | ||
| Map<String, GetterDescription> fieldMap = new HashMap<>(); | ||
| for (GetterDescription getter: this.gettersDescriptions) { | ||
| fieldMap.put(getter.getOriginalMember(), getter); | ||
| } | ||
| for (GetterDescription getter: this.declaredGettersDescriptions) { | ||
| fieldMap.put(getter.getOriginalMember(), getter); | ||
| } | ||
|
|
||
| final String capName = StringUtils.capitalize(propertyNameOf(base.getName())); | ||
| if (base.getTypeDescription().isBoolean()) { | ||
| // deal with predicates | ||
| for (String prefix: ClassUtil.PREDICATE_PREFIXES.keySet()) { | ||
| String propName = prefix + capName; | ||
|
|
||
| GetterDescription getterDesc = fieldMap.get(propName); | ||
| if (getterDesc != null) { | ||
| return getterDesc; | ||
| } | ||
| } | ||
| } else { | ||
|
Member
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. I think the |
||
|
|
||
| String propName = "get" + capName; | ||
|
|
||
| GetterDescription getterDesc = fieldMap.get(propName); | ||
| if (getterDesc != null) { | ||
| return getterDesc; | ||
| } | ||
| } | ||
|
|
||
| // wasn't found | ||
| return null; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
rename
findGetterDescriptionForFieldtohasGetterForFieldand simply return a booleanThere 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.
I agree with the name. For return type, I think it could be useful later to have it returning the value. If we were on Java 8 I'd rather return an
Optional<>, though. Thought?sThere 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.
Additionally, I've realized that there is a very real possibility of multiple. So either:
Set<>ofGettersI'm okay with either.