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