| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
package capsule; |
| 10 |
|
| 11 |
import org.junit.Test; |
| 12 |
import static org.junit.Assert.*; |
| 13 |
|
| 14 |
import static capsule.Dependencies.*; |
| 15 |
import java.util.Arrays; |
| 16 |
|
| 17 |
import org.eclipse.aether.artifact.DefaultArtifact; |
| 18 |
import org.eclipse.aether.graph.Dependency; |
| 19 |
import org.eclipse.aether.graph.Exclusion; |
| 20 |
import org.eclipse.aether.repository.RemoteRepository; |
| 21 |
import org.eclipse.aether.util.artifact.JavaScopes; |
| 22 |
|
| 23 |
import java.util.Collections; |
| 24 |
import java.util.HashSet; |
| 25 |
import java.util.Set; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class DependenciesTest { |
| 31 |
@Test |
| 32 |
public void testDeps() { |
| 33 |
assertEquals("com.esotericsoftware.kryo:kryo:LATEST", toCapsuleDependencyString(depWithoutExclusions)); |
| 34 |
assertEquals ( |
| 35 |
"com.esotericsoftware.kryo:kryo:[2.23.0)(org.ow2.asm:1.0.0)", |
| 36 |
toCapsuleDependencyString(depWithExclusion) |
| 37 |
); |
| 38 |
assertEquals ( |
| 39 |
"com.esotericsoftware.kryo:kryo:2.23.0(org.ow2.asm:*)", |
| 40 |
toCapsuleDependencyString(depWithExclusionWildcardExplicit) |
| 41 |
); |
| 42 |
assertEquals ( |
| 43 |
"com.esotericsoftware.kryo:kryo:RELEASE(org.ow2.asm:*)", |
| 44 |
toCapsuleDependencyString(depWithExclusionWildcardImplicit) |
| 45 |
); |
| 46 |
assertTrue( |
| 47 |
"com.esotericsoftware.kryo:kryo:[2.23.0)(capsule:*,org.ow2.asm:1.0.0)".equals( |
| 48 |
toCapsuleDependencyString(depWithExclusions) |
| 49 |
) || |
| 50 |
"com.esotericsoftware.kryo:kryo:[2.23.0)(org.ow2.asm:1.0.0,capsule:*)".equals( |
| 51 |
toCapsuleDependencyString(depWithExclusions) |
| 52 |
) |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
@Test |
| 57 |
public void testRepos() { |
| 58 |
assertEquals("central", toCapsuleRepositoryString(repoDefault)); |
| 59 |
assertEquals("http://clojars.org/repo", toCapsuleRepositoryString(repoUrl)); |
| 60 |
} |
| 61 |
|
| 62 |
private static final Dependency depWithoutExclusions = |
| 63 |
new Dependency ( |
| 64 |
new DefaultArtifact("com.esotericsoftware.kryo", "kryo", null, null, "LATEST"), |
| 65 |
JavaScopes.RUNTIME |
| 66 |
); |
| 67 |
|
| 68 |
private static final Dependency depWithExclusion = |
| 69 |
new Dependency ( |
| 70 |
new DefaultArtifact("com.esotericsoftware.kryo", "kryo", null, null, "[2.23.0)"), |
| 71 |
JavaScopes.RUNTIME, |
| 72 |
false, |
| 73 |
set(new Exclusion("org.ow2.asm", "1.0.0", null, null)) |
| 74 |
); |
| 75 |
|
| 76 |
private static final Dependency depWithExclusions = |
| 77 |
new Dependency ( |
| 78 |
new DefaultArtifact("com.esotericsoftware.kryo", "kryo", null, null, "[2.23.0)"), |
| 79 |
JavaScopes.RUNTIME, |
| 80 |
false, |
| 81 |
set ( |
| 82 |
new Exclusion("org.ow2.asm", "1.0.0", null, null), |
| 83 |
new Exclusion("capsule", null, null, null) |
| 84 |
) |
| 85 |
); |
| 86 |
|
| 87 |
private static final Dependency depWithExclusionWildcardImplicit = |
| 88 |
new Dependency ( |
| 89 |
new DefaultArtifact("com.esotericsoftware.kryo", "kryo", null, null, "RELEASE"), |
| 90 |
JavaScopes.RUNTIME, |
| 91 |
false, |
| 92 |
set(new Exclusion("org.ow2.asm", null, null, null)) |
| 93 |
); |
| 94 |
|
| 95 |
private static final Dependency depWithExclusionWildcardExplicit = |
| 96 |
new Dependency ( |
| 97 |
new DefaultArtifact("com.esotericsoftware.kryo", "kryo", null, null, "2.23.0"), |
| 98 |
JavaScopes.RUNTIME, |
| 99 |
false, |
| 100 |
set(new Exclusion("org.ow2.asm", "*", null, null)) |
| 101 |
); |
| 102 |
|
| 103 |
private static final RemoteRepository repoDefault = |
| 104 |
new RemoteRepository.Builder("central", null, null).build(); |
| 105 |
|
| 106 |
private static final RemoteRepository repoUrl = |
| 107 |
new RemoteRepository.Builder(null, null, "http://clojars.org/repo").build(); |
| 108 |
|
| 109 |
@SafeVarargs |
| 110 |
private static <T> Set<T> set(T... xs) { |
| 111 |
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(xs))); |
| 112 |
} |
| 113 |
} |