示例#1
0
  @Test(expected = SonarException.class)
  public void shouldFailIfIndexingAndLocked() {
    lock.setFailWhenLocked(true);
    lock.lock();

    Directory dir = new Directory("org/foo");
    index.index(dir);
  }
示例#2
0
 @Test
 public void shouldBeExcluded() {
   File file = new File("org/foo/ExcludedBar.java");
   assertThat(index.index(file), is(false));
   assertThat(index.isIndexed(file, true), is(true));
   assertThat(index.isIndexed(file, false), is(false));
   assertThat(index.isExcluded(file), is(true));
 }
示例#3
0
  /** Only a warning is logged when index is locked. */
  @Test
  public void shouldIndexEvenIfLocked() {
    lock.lock();

    Directory dir = new Directory("org/foo");
    assertThat(index.index(dir), is(true));
    assertThat(index.isIndexed(dir, true), is(true));
  }
示例#4
0
  @Test
  public void shouldIndexTreeOfResources() {
    Directory directory = new Directory("org/foo");
    File file = new File("org/foo/Bar.java");
    file.setLanguage(Java.INSTANCE);

    assertThat(index.index(directory), is(true));
    assertThat(index.index(file, directory), is(true));

    File fileRef = new File("org/foo/Bar.java");
    assertThat(index.getResource(fileRef).getKey(), is("org/foo/Bar.java"));
    assertThat(index.getResource(fileRef).getLanguage(), is((Language) Java.INSTANCE));
    assertThat(index.isIndexed(fileRef, true), is(true));
    assertThat(index.isExcluded(fileRef), is(false));
    assertThat(index.getChildren(fileRef).size(), is(0));
    assertThat(index.getParent(fileRef), is(Directory.class));
  }
示例#5
0
  @Test
  public void shouldIndexLibraryOutsideProjectTree() {
    Library lib = new Library("junit", "4.8");
    assertThat(index.index(lib), is(true));

    Library reference = new Library("junit", "4.8");
    assertThat(index.getResource(reference).getQualifier(), is(Qualifiers.LIBRARY));
    assertThat(index.isIndexed(reference, true), is(true));
    assertThat(index.isExcluded(reference), is(false));
  }
示例#6
0
  @Test
  public void shouldIndexParentOfDeprecatedFiles() {
    File file = new File("org/foo/Bar.java");
    assertThat(index.index(file), is(true));

    Directory reference = new Directory("org/foo");
    assertThat(index.getResource(reference).getName(), is("org/foo"));
    assertThat(index.isIndexed(reference, true), is(true));
    assertThat(index.isExcluded(reference), is(false));
    assertThat(index.getChildren(reference).size(), is(1));
    assertThat(index.getParent(reference), is(Project.class));
  }
示例#7
0
  @Test
  public void shouldNotIndexResourceIfParentNotIndexed() {
    Directory directory = new Directory("org/other");
    File file = new File("org/foo/Bar.java");

    assertThat(index.index(file, directory), is(false));

    File fileRef = new File("org/foo/Bar.java");
    assertThat(index.isIndexed(directory, true), is(false));
    assertThat(index.isIndexed(fileRef, true), is(false));
    assertThat(index.isExcluded(fileRef), is(false));
    assertThat(index.getChildren(fileRef).size(), is(0));
    assertThat(index.getParent(fileRef), nullValue());
  }