]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 fix ResourceUtils#isPackage() and isClass()
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 14 Feb 2014 11:13:25 +0000 (12:13 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 14 Feb 2014 11:13:35 +0000 (12:13 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceUtilsTest.java

index 1745f57641cf07b6ce1265f506477dbf0f595fdb..4e3ae3772e409e30486e2b7a4e1b9651c2d2daef 100644 (file)
@@ -62,7 +62,7 @@ public final class ResourceUtils {
    */
   @Deprecated
   public static boolean isPackage(Resource resource) {
-    return resource != null && Qualifiers.PACKAGE.equals(resource.getQualifier()) || isDirectory(resource);
+    return resource != null && Qualifiers.PACKAGE.equals(resource.getQualifier());
   }
 
   /**
@@ -115,7 +115,7 @@ public final class ResourceUtils {
    */
   @Deprecated
   public static boolean isClass(Resource resource) {
-    return Qualifiers.CLASS.equals(resource.getQualifier()) || Qualifiers.FILE.equals(resource.getQualifier());
+    return Qualifiers.CLASS.equals(resource.getQualifier());
   }
 
   /**
index 1619b93880f23b5c2bd725e1f7642c80a2e3f5e9..35b9f7a1cc6d07581902edbfdd7d1e216152e99f 100644 (file)
@@ -21,8 +21,7 @@ package org.sonar.api.resources;
 
 import org.junit.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -31,49 +30,49 @@ public class ResourceUtilsTest {
   @Test
   public void checkFile() {
     File file = new File("hello.Foo");
-    assertThat(ResourceUtils.isClass(file), is(true));
-    assertThat(ResourceUtils.isPackage(file), is(false));
-    assertThat(ResourceUtils.isModuleProject(file), is(false));
-    assertThat(ResourceUtils.isSpace(file), is(false));
-    assertThat(ResourceUtils.isEntity(file), is(true));
-    assertThat(ResourceUtils.isSet(file), is(false));
-    assertThat(ResourceUtils.isRootProject(file), is(false));
-    assertThat(ResourceUtils.isUnitTestClass(file), is(false));
+    assertThat(ResourceUtils.isClass(file)).isFalse();
+    assertThat(ResourceUtils.isPackage(file)).isFalse();
+    assertThat(ResourceUtils.isModuleProject(file)).isFalse();
+    assertThat(ResourceUtils.isSpace(file)).isFalse();
+    assertThat(ResourceUtils.isEntity(file)).isTrue();
+    assertThat(ResourceUtils.isSet(file)).isFalse();
+    assertThat(ResourceUtils.isRootProject(file)).isFalse();
+    assertThat(ResourceUtils.isUnitTestClass(file)).isFalse();
   }
 
   @Test
   public void checkUnitTest() {
     File utFile = new File("hello.Foo");
     utFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
-    assertThat(ResourceUtils.isClass(utFile), is(false));
-    assertThat(ResourceUtils.isPackage(utFile), is(false));
-    assertThat(ResourceUtils.isModuleProject(utFile), is(false));
-    assertThat(ResourceUtils.isSpace(utFile), is(false));
-    assertThat(ResourceUtils.isEntity(utFile), is(true));
-    assertThat(ResourceUtils.isSet(utFile), is(false));
-    assertThat(ResourceUtils.isRootProject(utFile), is(false));
-    assertThat(ResourceUtils.isUnitTestClass(utFile), is(true));
+    assertThat(ResourceUtils.isClass(utFile)).isFalse();
+    assertThat(ResourceUtils.isPackage(utFile)).isFalse();
+    assertThat(ResourceUtils.isModuleProject(utFile)).isFalse();
+    assertThat(ResourceUtils.isSpace(utFile)).isFalse();
+    assertThat(ResourceUtils.isEntity(utFile)).isTrue();
+    assertThat(ResourceUtils.isSet(utFile)).isFalse();
+    assertThat(ResourceUtils.isRootProject(utFile)).isFalse();
+    assertThat(ResourceUtils.isUnitTestClass(utFile)).isTrue();
   }
 
   @Test
   public void checkDirectory() {
     Directory dir = new Directory("hello");
-    assertThat(ResourceUtils.isClass(dir), is(false));
-    assertThat(ResourceUtils.isPackage(dir), is(true));
-    assertThat(ResourceUtils.isModuleProject(dir), is(false));
-    assertThat(ResourceUtils.isSpace(dir), is(true));
-    assertThat(ResourceUtils.isEntity(dir), is(false));
-    assertThat(ResourceUtils.isSet(dir), is(false));
-    assertThat(ResourceUtils.isRootProject(dir), is(false));
-    assertThat(ResourceUtils.isUnitTestClass(dir), is(false));
+    assertThat(ResourceUtils.isClass(dir)).isFalse();
+    assertThat(ResourceUtils.isPackage(dir)).isFalse();
+    assertThat(ResourceUtils.isModuleProject(dir)).isFalse();
+    assertThat(ResourceUtils.isSpace(dir)).isTrue();
+    assertThat(ResourceUtils.isEntity(dir)).isFalse();
+    assertThat(ResourceUtils.isSet(dir)).isFalse();
+    assertThat(ResourceUtils.isRootProject(dir)).isFalse();
+    assertThat(ResourceUtils.isUnitTestClass(dir)).isFalse();
   }
 
   @Test
   public void shouldBePersistable() {
-    assertThat(ResourceUtils.isPersistable(new File("Foo.java")), is(true));
-    assertThat(ResourceUtils.isPersistable(new Directory("bar/Foo.java")), is(true));
-    assertThat(ResourceUtils.isPersistable(new Project("foo")), is(true));
-    assertThat(ResourceUtils.isPersistable(new Library("foo", "1.2")), is(true));
+    assertThat(ResourceUtils.isPersistable(new File("Foo.java"))).isTrue();
+    assertThat(ResourceUtils.isPersistable(new Directory("bar/Foo.java"))).isTrue();
+    assertThat(ResourceUtils.isPersistable(new Project("foo"))).isTrue();
+    assertThat(ResourceUtils.isPersistable(new Library("foo", "1.2"))).isTrue();
   }
 
   @Test
@@ -83,7 +82,7 @@ public class ResourceUtilsTest {
     Resource javaMethod = mock(Resource.class);
     when(javaMethod.getScope()).thenReturn(Scopes.BLOCK_UNIT);
 
-    assertThat(ResourceUtils.isPersistable(javaClass), is(false));
-    assertThat(ResourceUtils.isPersistable(javaMethod), is(false));
+    assertThat(ResourceUtils.isPersistable(javaClass)).isFalse();
+    assertThat(ResourceUtils.isPersistable(javaMethod)).isFalse();
   }
 }