1 package com.atlassian.plugin.loaders.classloading;
2
3 import org.hamcrest.Description;
4 import org.hamcrest.Matcher;
5 import org.hamcrest.TypeSafeMatcher;
6 import org.junit.Test;
7
8 import java.io.File;
9 import java.io.IOException;
10
11 import static org.junit.Assert.assertEquals;
12
13 public class TestDeploymentUnit {
14
15 @Test
16 public void testCompareTo() throws IOException {
17 File tmp = File.createTempFile("testDeploymentUnit", ".txt");
18 DeploymentUnit unit1 = new DeploymentUnit(tmp);
19 DeploymentUnit unit2 = new DeploymentUnit(tmp);
20 assertEquals(0, unit1.compareTo(unit2));
21
22
23 tmp.setLastModified(System.currentTimeMillis() + 1000);
24 unit2 = new DeploymentUnit(tmp);
25 assertEquals(-1, unit1.compareTo(unit2));
26 }
27
28 public static Matcher<DeploymentUnit> deploymentUnitWithPath(final Matcher<File> pathMatcher) {
29 return new TypeSafeMatcher<DeploymentUnit>() {
30 @Override
31 protected boolean matchesSafely(final DeploymentUnit deploymentUnit) {
32 return pathMatcher.matches(deploymentUnit.getPath());
33 }
34
35 @Override
36 public void describeTo(final Description description) {
37 description.appendText("Deployment unit with path ");
38 pathMatcher.describeTo(description);
39 }
40 };
41 }
42 }