View Javadoc

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