|
| 1 | +package fi.helsinki.cs.tmc.langs.io.zip; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.nio.file.Path; |
| 8 | +import java.nio.file.Paths; |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +public class UnzipResultTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void unzipResultToStringContainsExpectedPaths() { |
| 16 | + final List<Path> expected = new ArrayList<>(); |
| 17 | + |
| 18 | + Path projectPath = Paths.get("./test/"); |
| 19 | + UnzipResult result = new UnzipResult(projectPath); |
| 20 | + expected.add(projectPath); |
| 21 | + addItemToBoth(Paths.get("test/Toaster.java"), expected, result.newFiles); |
| 22 | + addItemToBoth(Paths.get("test/Overwritten.java"), expected, result.overwrittenFiles); |
| 23 | + addItemToBoth(Paths.get("test/Test.iml"), expected, result.skippedFiles); |
| 24 | + addItemToBoth(Paths.get("test/bar/Foo.java"), expected, result.unchangedFiles); |
| 25 | + addItemToBoth(Paths.get("test/target/Thing.jar"), expected, result.deletedFiles); |
| 26 | + addItemToBoth(Paths.get("test/target/Report.xml"), expected, result.skippedDeletingFiles); |
| 27 | + |
| 28 | + String resultString = result.toString(); |
| 29 | + |
| 30 | + for (Path path : expected) { |
| 31 | + String pathString = path.toString(); |
| 32 | + assertTrue( |
| 33 | + "Expected UnzipResult to contain path \"" + pathString + "\"", |
| 34 | + resultString.contains(pathString)); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + private static <T> void addItemToBoth(T item, List<T> first, List<T> second) { |
| 39 | + first.add(item); |
| 40 | + second.add(item); |
| 41 | + } |
| 42 | +} |
0 commit comments