1
0
mirror of https://github.com/google/nomulus synced 2026-01-08 23:23:32 +00:00

Move Imm.Obj. hash code stripping into utility fx

Spotted this functionality in one of mcilwain's test classes that could
be useful to other CommandTestCases when comparing ImmutableObject
output.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128686426
This commit is contained in:
Chris Tingue
2016-07-28 04:34:45 -07:00
committed by Justine Tunney
parent 5332ac4e4a
commit 68b58c210d

View File

@@ -147,6 +147,15 @@ public abstract class CommandTestCase<C extends Command> {
return ofy().load().type(PollMessage.class).count();
}
/**
* Asserts whether standard out matches an expected string, allowing for differences in
* ImmutableObject hash codes (i.e. "(@1234567)").
*/
protected void assertStdoutForImmutableObjectIs(String expected) throws Exception {
assertThat(stripImmutableObjectHashCodes(getStdoutAsString()).trim())
.isEqualTo(stripImmutableObjectHashCodes(expected).trim());
}
protected void assertStdoutIs(String expected) throws Exception {
assertThat(getStdoutAsString()).isEqualTo(expected);
}
@@ -177,6 +186,10 @@ public abstract class CommandTestCase<C extends Command> {
return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(getStdoutAsString());
}
protected String stripImmutableObjectHashCodes(String string) {
return string.replaceAll("\\(@\\d+\\)", "(@)");
}
@SuppressWarnings("unchecked")
protected C newCommandInstance() {
try {