Custom Truth subjects: Align name passed to Subject#check with reality

In order to print a nice failure message which matches the reality of
the asserted objects, use the real name of the called method or property
if it makes sense. When the assertion is on a derivative of a method or
property or when the real name isn't helpful for a failure message
(e.g. "ab" naming of common lines for diffs), keep using more
descriptive pseudo-method names.

Change-Id: I53fae276c57fe09fb43a58e77efd681b34b60eb7
This commit is contained in:
Alice Kober-Sotzek
2019-03-25 17:38:40 +01:00
parent 4fdaf8060d
commit 398681f154
16 changed files with 50 additions and 53 deletions

View File

@@ -45,16 +45,16 @@ public class ChangeFileContentModificationSubject
public StringSubject filePath() {
isNotNull();
return check("filePath()").that(actual().getFilePath());
return check("getFilePath()").that(actual().getFilePath());
}
public StringSubject newContent() throws IOException {
isNotNull();
RawInput newContent = actual().getNewContent();
check("newContent()").that(newContent).isNotNull();
check("getNewContent()").that(newContent).isNotNull();
String contentString =
CharStreams.toString(
new InputStreamReader(newContent.getInputStream(), StandardCharsets.UTF_8));
return check("newContent()").that(contentString);
return check("getNewContent()").that(contentString);
}
}