From 68b58c210dde04385a97ad7dc33b29c2b89900f1 Mon Sep 17 00:00:00 2001 From: Chris Tingue Date: Thu, 28 Jul 2016 04:34:45 -0700 Subject: [PATCH] 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 --- .../google/registry/tools/CommandTestCase.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/javatests/google/registry/tools/CommandTestCase.java b/javatests/google/registry/tools/CommandTestCase.java index 6dac241dc..8036682a0 100644 --- a/javatests/google/registry/tools/CommandTestCase.java +++ b/javatests/google/registry/tools/CommandTestCase.java @@ -147,6 +147,15 @@ public abstract class CommandTestCase { 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 { return Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(getStdoutAsString()); } + protected String stripImmutableObjectHashCodes(String string) { + return string.replaceAll("\\(@\\d+\\)", "(@)"); + } + @SuppressWarnings("unchecked") protected C newCommandInstance() { try {