@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);
@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);
@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);
@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);
@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);
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)))
return timeMachine;
}
-
}
*/
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;
- }
-
- }
}