diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-model/src/test/java/helpers/CompareConfigTestHelper.java |
Publish
Diffstat (limited to 'config-model/src/test/java/helpers/CompareConfigTestHelper.java')
-rw-r--r-- | config-model/src/test/java/helpers/CompareConfigTestHelper.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/config-model/src/test/java/helpers/CompareConfigTestHelper.java b/config-model/src/test/java/helpers/CompareConfigTestHelper.java new file mode 100644 index 00000000000..f7709b4aebf --- /dev/null +++ b/config-model/src/test/java/helpers/CompareConfigTestHelper.java @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package helpers; + +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.collect.Lists; +import com.yahoo.io.IOUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author Vegard Sjonfjell + */ +public class CompareConfigTestHelper { + + public static void assertSerializedConfigFileEquals(String filename, String actual) throws IOException { + assertSerializedConfigEquals(IOUtils.readFile(new File(filename)), actual); + } + + // Written this way to compare order independently but output error with order preserved + // Note that this means that if a test fails you'll also see spurious differences in the comparison + // from lines which are present in both but at different locations. + public static void assertSerializedConfigEquals(String expected, String actual) { + if ( ! sortLines(expected.trim()).equals(sortLines(actual.trim()))) + assertEquals(expected, actual); + } + + private static String sortLines(String fileData) { + final List<String> lines = Lists.newArrayList(Splitter.on('\n').split(fileData)); + Collections.sort(lines); + return Joiner.on('\n').join(lines); + } + +} |