Subject.displayedAs(...)
- Dominant language
- Java
- Stars
- 2.8k
- Forks
- 275
- Avg merge
- 7m
- Merged PRs (30d)
- 4
Description
`Subject.named("foo")` prefixes "foo" before the subject, in any place where the subject is supplied for display.
Originally `.named()` was a replacement, not a prefix, and this was changed. However, the need for a replacement option is still legitimate, and has some applications, especially for `check().that(getSubject().someInternalState()).hasSomeProperty()` calls within subject implementors, or other cases where there can be no meaningful `toString()`.
Of note - the method will be named `displayedAs` and support the limited format-string substitutions. e.g.
```
assertThat(someBoolean).displayedAs("Displayable Field %s", fieldName).isTrue();
...
check().that(getSubject().getFoo()).displayedAs("%s's foo", getSubject().getName())
.isNotNull();
```
This will result in `getDisplaySubject()` returning the supplied string in place of the subject's toString();. This is incompatible with named(), and any prior or later named() calls will simply be circumvented.
Todo:
- [ ] Validate whether this should silently override, or blow up if an prior `.named()`
call was made. (This might be impossible, as some subjects which return subjects
pre-call `.named()` and this would break them. But let's see what's possible.
- [x] While here, fix the javadoc for `Subject.named()` which implies that it's non-prefixing
- [x] Audit for the presence of getDisplaySubject overrides, and try to make that API final.
- [ ] Implement the specific feature `displayedAs(String, Object...)`
Contributor guide
Assessment
This issue has not been assessed yet.