View Javadoc
1   package com.atlassian.plugin.loaders;
2   
3   import com.atlassian.plugin.loaders.classloading.DeploymentUnit;
4   import org.hamcrest.Matcher;
5   import org.junit.Test;
6   
7   import java.io.File;
8   import java.util.Arrays;
9   import java.util.Collection;
10  
11  import static com.atlassian.plugin.loaders.classloading.TestDeploymentUnit.deploymentUnitWithPath;
12  import static com.atlassian.plugin.test.Matchers.fileNamed;
13  import static org.hamcrest.MatcherAssert.assertThat;
14  import static org.hamcrest.Matchers.contains;
15  import static org.hamcrest.Matchers.empty;
16  
17  public class TestFileListScanner {
18      @Test
19      public void testNormalOperation() throws Exception {
20          final FileListScanner scanner = new FileListScanner(Arrays.asList(new File("foo.txt"), new File("bar.txt")));
21          assertContainsFooAndBar(scanner);
22  
23          // Second scan should have no new units.
24          assertThat(scanner.scan(), empty());
25  
26          scanner.reset();
27  
28          assertContainsFooAndBar(scanner);
29      }
30  
31      private void assertContainsFooAndBar(final FileListScanner scanner) {
32          final Collection<DeploymentUnit> scan = scanner.scan();
33          final Matcher[] expected = {deploymentUnitWithPath(fileNamed("foo.txt")), deploymentUnitWithPath(fileNamed("bar.txt"))};
34          assertThat(scan, contains(expected));
35      }
36  }