]> source.dussan.org Git - sonarqube.git/commitdiff
Remove warnings
authorDavid Gageot <david@gageot.net>
Mon, 18 Jun 2012 10:51:59 +0000 (12:51 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 18 Jun 2012 10:53:35 +0000 (12:53 +0200)
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/LanguagesTest.java

index f2b885fb65d516c420757bdb9f13431e0e63a283..8ce2c25ebf89395167d16bd7e6afefc035376a21 100644 (file)
@@ -79,7 +79,7 @@ public class ProfileEventsSensorTest {
   @Test
   public void shouldDoNothingIfNoProfileChange() {
     RulesProfile profile = mockProfileWithVersion(1);
-    TimeMachine timeMachine = mockTM(project, 22.0, "Foo", 1.0); // Same profile, same version
+    TimeMachine timeMachine = mockTM(22.0, "Foo", 1.0); // Same profile, same version
     ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
 
     sensor.analyse(project, context);
@@ -90,7 +90,7 @@ public class ProfileEventsSensorTest {
   @Test
   public void shouldCreateEventIfProfileChange() {
     RulesProfile profile = mockProfileWithVersion(1);
-    TimeMachine timeMachine = mockTM(project, 21.0, "Bar", 1.0); // Different profile
+    TimeMachine timeMachine = mockTM(21.0, "Bar", 1.0); // Different profile
     ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
 
     sensor.analyse(project, context);
@@ -104,7 +104,7 @@ public class ProfileEventsSensorTest {
   @Test
   public void shouldCreateEventIfProfileVersionChange() {
     RulesProfile profile = mockProfileWithVersion(2);
-    TimeMachine timeMachine = mockTM(project, 22.0, "Foo", 1.0); // Same profile, different version
+    TimeMachine timeMachine = mockTM(22.0, "Foo", 1.0); // Same profile, different version
     ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
 
     sensor.analyse(project, context);
@@ -118,7 +118,7 @@ public class ProfileEventsSensorTest {
   @Test
   public void shouldNotCreateEventIfFirstAnalysis() {
     RulesProfile profile = mockProfileWithVersion(2);
-    TimeMachine timeMachine = mockTM(project, null, null);
+    TimeMachine timeMachine = mockTM(null, null);
     ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
 
     sensor.analyse(project, context);
@@ -129,7 +129,7 @@ public class ProfileEventsSensorTest {
   @Test
   public void shouldCreateEventIfFirstAnalysisWithVersionsAndVersionMoreThan1() {
     RulesProfile profile = mockProfileWithVersion(2);
-    TimeMachine timeMachine = mockTM(project, 22.0, "Foo", null);
+    TimeMachine timeMachine = mockTM(22.0, "Foo", null);
     ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
 
     sensor.analyse(project, context);
@@ -148,11 +148,11 @@ public class ProfileEventsSensorTest {
     return profile;
   }
 
-  private TimeMachine mockTM(Project project, double profileId, String profileName, Double versionValue) {
-    return mockTM(project, new Measure(CoreMetrics.PROFILE, profileId, profileName), versionValue == null ? null : new Measure(CoreMetrics.PROFILE_VERSION, versionValue));
+  private TimeMachine mockTM(double profileId, String profileName, Double versionValue) {
+    return mockTM(new Measure(CoreMetrics.PROFILE, profileId, profileName), versionValue == null ? null : new Measure(CoreMetrics.PROFILE_VERSION, versionValue));
   }
 
-  private TimeMachine mockTM(Project project, Measure result1, Measure result2) {
+  private TimeMachine mockTM(Measure result1, Measure result2) {
     TimeMachine timeMachine = mock(TimeMachine.class);
 
     when(timeMachine.getMeasures(any(TimeMachineQuery.class)))
@@ -161,5 +161,4 @@ public class ProfileEventsSensorTest {
 
     return timeMachine;
   }
-
 }
index 7034c569f68afe7419be4f17640bcd45766841ac..b22f603fa91d3b53e68519649b25e56ce9ab2b17 100644 (file)
  */
 package org.sonar.api.resources;
 
-import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
-import static org.junit.Assert.*;
 import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import org.sonar.api.database.model.ResourceModel;
-
-import java.io.File;
-import java.util.List;
 
 public class LanguagesTest {
-
   @Test
-  public void shouldAddSeveralTimesTheSameLanguage() {
-    FakeLanguage fake = new FakeLanguage();
-    Languages languages = new Languages(fake, fake);
-    assertEquals("fake", languages.get("fake").getKey());
-  }
+  public void should_add_several_times_the_same_language() {
+    Languages languages = new Languages(
+        language("fake"),
+        language("fake"));
 
+    assertThat(languages.get("fake").getKey()).isEqualTo("fake");
+  }
 
   @Test
-  public void getSuffixes() {
+  public void should_get_suffixes() {
     Languages languages = new Languages(
-        newLang("java", new String[]{"java"}),
-        newLang("php", new String[]{"php4", "php5"}));
+        language("java", "java"),
+        language("php", "php4", "php5"));
 
-    assertThat(languages.getSuffixes(), hasItemInArray("java"));
-    assertThat(languages.getSuffixes(), hasItemInArray("php4"));
-    assertThat(languages.getSuffixes(), hasItemInArray("php5"));
-
-    assertArrayEquals(languages.getSuffixes("java"), new String[]{"java"});
-    assertArrayEquals(languages.getSuffixes("php"), new String[]{"php4", "php5"});
-    assertArrayEquals(languages.getSuffixes("xxx"), new String[0]);
+    assertThat(languages.getSuffixes()).containsOnly("java", "php4", "php5");
+    assertThat(languages.getSuffixes("java")).containsOnly("java");
+    assertThat(languages.getSuffixes("php")).containsOnly("php4", "php5");
+    assertThat(languages.getSuffixes("xxx")).isEmpty();
   }
 
-  private Language newLang(String key, String[] suffixes) {
+  static Language language(String key, String... suffixes) {
     Language lang = mock(Language.class);
     when(lang.getKey()).thenReturn(key);
     when(lang.getFileSuffixes()).thenReturn(suffixes);
     return lang;
   }
-
-  static class FakeLanguage implements Language {
-
-    public String getKey() {
-      return "fake";
-    }
-
-    public String getName() {
-      return "Fake";
-    }
-
-    public String[] getFileSuffixes() {
-      return new String[]{"fak"};
-    }
-
-    public ResourceModel getParent(ResourceModel resource) {
-      return null;
-    }
-
-    public boolean matchExclusionPattern(ResourceModel resource, String wildcardPattern) {
-      return false;
-    }
-
-    public boolean matchExclusionPattern(File source, List<File> sourceDirs, String wildcardPattern) {
-      return false;
-    }
-
-  }
 }