Package it.tidalwave.util.test
Class FileComparisonUtils
- java.lang.Object
-
- it.tidalwave.util.test.FileComparisonUtils
-
public class FileComparisonUtils extends java.lang.ObjectA utility class to compare two text files and assert that they have the same contents.- Author:
- Fabrizio Giudici
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringP_TABULAR_LIMITstatic java.lang.StringP_TABULAR_OUTPUT
-
Constructor Summary
Constructors Constructor Description FileComparisonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertSameContents(java.io.File expectedFile, java.io.File actualFile)Asserts that two files have the same contents.static voidassertSameContents(java.nio.file.Path expectedFile, java.nio.file.Path actualFile)Asserts that two files have the same contents.static voidassertSameContents(java.util.List<java.lang.String> expected, java.util.List<java.lang.String> actual)Asserts that two collections of strings have the same contents.static java.lang.StringcommonPrefix(java.lang.String s1, java.lang.String s2)Given a string that represents a path whose segments are separated by the standard separator of the platform, returns the common prefix - which means the common directory parents.static java.util.List<java.lang.String>fileToStrings(java.io.File file)Reads a file into a list of strings.static java.util.List<java.lang.String>fileToStrings(java.io.InputStream is)Reads an input stream into a list of strings.static java.util.List<java.lang.String>fileToStrings(java.lang.String path)Reads a classpath resource into a list of strings.static java.util.List<java.lang.String>stringToStrings(java.lang.String string)Converts a string which contains newlines into a list of strings.
-
-
-
Method Detail
-
assertSameContents
public static void assertSameContents(@Nonnull java.nio.file.Path expectedFile, @Nonnull java.nio.file.Path actualFile) throws java.io.IOExceptionAsserts that two files have the same contents.- Parameters:
expectedFile- the file with the expected contentsactualFile- the file with the contents to probe- Throws:
java.io.IOException- in case of error
-
assertSameContents
public static void assertSameContents(@Nonnull java.io.File expectedFile, @Nonnull java.io.File actualFile) throws java.io.IOExceptionAsserts that two files have the same contents.- Parameters:
expectedFile- the file with the expected contentsactualFile- the file with the contents to probe- Throws:
java.io.IOException- in case of error
-
assertSameContents
public static void assertSameContents(@Nonnull java.util.List<java.lang.String> expected, @Nonnull java.util.List<java.lang.String> actual)Asserts that two collections of strings have the same contents.- Parameters:
expected- the expected valuesactual- the actual values
-
stringToStrings
@Nonnull public static java.util.List<java.lang.String> stringToStrings(@Nonnull java.lang.String string) throws java.io.IOExceptionConverts a string which contains newlines into a list of strings.- Parameters:
string- the source- Returns:
- the strings
- Throws:
java.io.IOException- in case of error
-
fileToStrings
@Nonnull public static java.util.List<java.lang.String> fileToStrings(@Nonnull java.io.File file) throws java.io.IOExceptionReads a file into a list of strings.- Parameters:
file- the file- Returns:
- the strings
- Throws:
java.io.IOException- in case of error
-
fileToStrings
@Nonnull public static java.util.List<java.lang.String> fileToStrings(@Nonnull java.lang.String path) throws java.io.IOExceptionReads a classpath resource into a list of strings.- Parameters:
path- the path of the classpath resource- Returns:
- the strings
- Throws:
java.io.IOException- in case of error
-
fileToStrings
@Nonnull public static java.util.List<java.lang.String> fileToStrings(@Nonnull java.io.InputStream is) throws java.io.IOExceptionReads an input stream into a list of strings.- Parameters:
is- the input stream- Returns:
- the strings
- Throws:
java.io.IOException- in case of error
-
commonPrefix
@Nonnull public static java.lang.String commonPrefix(@Nonnull java.lang.String s1, @Nonnull java.lang.String s2)Given a string that represents a path whose segments are separated by the standard separator of the platform, returns the common prefix - which means the common directory parents.- Parameters:
s1- the former strings2- the latter string- Returns:
- the common prefix
-
-