Package it.tidalwave.util.test
Class FileComparisonUtils
java.lang.Object
it.tidalwave.util.test.FileComparisonUtils
A utility class to compare two text files and assert that they have the same contents.
- Author:
- Fabrizio Giudici
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertSameContents(File expectedFile, File actualFile) Asserts that two files have the same contents.static voidassertSameContents(Path expectedPath, Path actualPath) Asserts that two files have the same contents.static voidassertSameContents(List<String> expected, List<String> actual) Asserts that two collections of strings have the same contents.static booleancheckSameContents(Path expectedPath, Path actualPath) Checks whether two files have the same contents.static StringcommonPrefix(String s1, 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.fileToStrings(Path file) Reads a file into a list of strings.Reads an input stream into a list of strings.resourceToStrings(String path) Reads a classpath resource (not a regular file) into a list of strings.stringToStrings(String string) Converts a string which contains newlines into a list of strings.
-
Field Details
-
P_TABULAR_OUTPUT
-
P_TABULAR_LIMIT
-
-
Constructor Details
-
FileComparisonUtils
public FileComparisonUtils()
-
-
Method Details
-
assertSameContents
public static void assertSameContents(@Nonnull File expectedFile, @Nonnull File actualFile) throws IOException Asserts that two files have the same contents.- Parameters:
expectedFile- the file with the expected contentsactualFile- the file with the contents to probe- Throws:
IOException- in case of error
-
assertSameContents
public static void assertSameContents(@Nonnull Path expectedPath, @Nonnull Path actualPath) throws IOException Asserts that two files have the same contents.- Parameters:
expectedPath- the file with the expected contentsactualPath- the file with the contents to probe- Throws:
IOException- in case of error
-
assertSameContents
Asserts that two collections of strings have the same contents.- Parameters:
expected- the expected valuesactual- the actual values
-
checkSameContents
public static boolean checkSameContents(@Nonnull Path expectedPath, @Nonnull Path actualPath) throws IOException Checks whether two files have the same contents.- Parameters:
expectedPath- the file with the expected contentsactualPath- the file with the contents to probe- Returns:
- whether the two files have the same contents
- Throws:
IOException- in case of error- Since:
- 1.2-ALPHA-15
-
stringToStrings
Converts a string which contains newlines into a list of strings.- Parameters:
string- the source- Returns:
- the strings
- Throws:
IOException- in case of error
-
fileToStrings
Reads a file into a list of strings.- Parameters:
file- the file- Returns:
- the strings
- Throws:
IOException- in case of error
-
resourceToStrings
Reads a classpath resource (not a regular file) into a list of strings.- Parameters:
path- the path of the classpath resource- Returns:
- the strings
- Throws:
IOException- in case of error
-
resourceToStrings
Reads an input stream into a list of strings. The stream is closed at the end.- Parameters:
is- the input stream- Returns:
- the strings
- Throws:
IOException- in case of error
-
commonPrefix
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
-