-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing JT-173 (backport of initial PR made by phax)
- Loading branch information
Laurent SCHOELENS
committed
Aug 7, 2023
1 parent
949454e
commit 42b9fe7
Showing
2 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
maven-plugin/plugin-core/src/test/java/org/jvnet/jaxb/maven/util/IOUtilsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.jvnet.jaxb.maven.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class IOUtilsTests { | ||
|
||
private File directory = new File("/"); | ||
|
||
@Test | ||
public void reorderFilesIncludesNull() { | ||
List<File> files = new ArrayList<>(); | ||
files.add(new File(directory, "a.xsd")); | ||
files.add(new File(directory, "c.xsd")); | ||
files.add(new File(directory, "b.xsd")); | ||
List<File> orderedFiles = IOUtils.reorderFiles(files, directory, null); | ||
|
||
Assert.assertNotNull("Ordered files list should not be null", | ||
orderedFiles); | ||
Assert.assertEquals("Ordered files list should contains all elements of initial list", | ||
files.size(), orderedFiles.size()); | ||
Assert.assertEquals(files.get(0), orderedFiles.get(0)); | ||
Assert.assertEquals(files.get(1), orderedFiles.get(1)); | ||
Assert.assertEquals(files.get(2), orderedFiles.get(2)); | ||
} | ||
|
||
@Test | ||
public void reorderFilesIncludesEmpty() { | ||
List<File> files = new ArrayList<>(); | ||
files.add(new File(directory, "a.xsd")); | ||
files.add(new File(directory, "c.xsd")); | ||
files.add(new File(directory, "b.xsd")); | ||
List<File> orderedFiles = IOUtils.reorderFiles(files, directory, new String[] {}); | ||
|
||
Assert.assertNotNull("Ordered files list should not be null", | ||
orderedFiles); | ||
Assert.assertEquals("Ordered files list should contains all elements of initial list", | ||
files.size(), orderedFiles.size()); | ||
Assert.assertEquals(files.get(0), orderedFiles.get(0)); | ||
Assert.assertEquals(files.get(1), orderedFiles.get(1)); | ||
Assert.assertEquals(files.get(2), orderedFiles.get(2)); | ||
} | ||
|
||
@Test | ||
public void reorderFilesIncludesNoWildcard() { | ||
List<File> files = new ArrayList<>(); | ||
files.add(new File(directory, "a.xsd")); | ||
files.add(new File(directory, "c.xsd")); | ||
files.add(new File(directory, "b.xsd")); | ||
List<File> orderedFiles = IOUtils.reorderFiles(files, directory, new String[] { "b.xsd", "c.xsd", "a.xsd" }); | ||
|
||
Assert.assertNotNull("Ordered files list should not be null", | ||
orderedFiles); | ||
Assert.assertEquals("Ordered files list should contains all elements of initial list", | ||
files.size(), orderedFiles.size()); | ||
Assert.assertEquals(files.get(2), orderedFiles.get(0)); | ||
Assert.assertEquals(files.get(1), orderedFiles.get(1)); | ||
Assert.assertEquals(files.get(0), orderedFiles.get(2)); | ||
} | ||
|
||
@Test | ||
public void reorderFilesIncludesNoWildcardWithCommonSuffix() { | ||
List<File> files = new ArrayList<>(); | ||
files.add(new File(directory, "a.xsd")); | ||
files.add(new File(directory, "b.xsd")); | ||
files.add(new File(directory, "service-ab.xsd")); | ||
List<File> orderedFiles = IOUtils.reorderFiles(files, directory, new String[] { "b.xsd", "a.xsd", "service-ab.xsd" }); | ||
|
||
Assert.assertNotNull("Ordered files list should not be null", | ||
orderedFiles); | ||
Assert.assertEquals("Ordered files list should contains all elements of initial list", | ||
files.size(), orderedFiles.size()); | ||
Assert.assertEquals(files.get(1), orderedFiles.get(0)); | ||
Assert.assertEquals(files.get(0), orderedFiles.get(1)); | ||
Assert.assertEquals(files.get(2), orderedFiles.get(2)); | ||
} | ||
|
||
@Test | ||
public void reorderFilesIncludesWithWildcard() { | ||
List<File> files = new ArrayList<>(); | ||
files.add(new File(directory, "a.xsd")); | ||
files.add(new File(directory, "common/c1.xsd")); | ||
files.add(new File(directory, "b.xsd")); | ||
files.add(new File(directory, "common/c2.xsd")); | ||
files.add(new File(directory, "common/a.xsd")); | ||
files.add(new File(directory, "common/b.xsd")); | ||
List<File> orderedFiles = IOUtils.reorderFiles(files, directory, new String[] { "common/*.xsd", "a.xsd", "b.xsd" }); | ||
|
||
Assert.assertNotNull("Ordered files list should not be null", | ||
orderedFiles); | ||
Assert.assertEquals("Ordered files list should contains all elements of initial list", | ||
files.size(), orderedFiles.size()); | ||
// a.xsd is the first file | ||
Assert.assertEquals(files.get(0), orderedFiles.get(0)); | ||
// b.xsd is the second file | ||
Assert.assertEquals(files.get(2), orderedFiles.get(1)); | ||
// and then we have all common/*.xsd files in same order | ||
Assert.assertEquals(files.get(1), orderedFiles.get(2)); | ||
Assert.assertEquals(files.get(3), orderedFiles.get(3)); | ||
Assert.assertEquals(files.get(4), orderedFiles.get(4)); | ||
Assert.assertEquals(files.get(5), orderedFiles.get(5)); | ||
} | ||
} |