]> source.dussan.org Git - sonarqube.git/commitdiff
Remove the class MoreConditions from sonar-testing-harness
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Apr 2014 13:17:38 +0000 (15:17 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Apr 2014 13:17:48 +0000 (15:17 +0200)
sonar-server/src/test/java/org/sonar/server/startup/RegisterDashboardsTest.java
sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java [deleted file]
sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java [deleted file]

index 2a38d59274a01ced98242f066f80b5c119f2f334..33ea65d13efb61e1866c59a62cab8457220b0d6f 100644 (file)
@@ -37,6 +37,7 @@ import org.sonar.core.template.LoadedTemplateDao;
 import org.sonar.core.template.LoadedTemplateDto;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -47,7 +48,6 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.sonar.test.MoreConditions.contains;
 
 public class RegisterDashboardsTest {
   private RegisterDashboards task;
@@ -63,8 +63,8 @@ public class RegisterDashboardsTest {
     loadedTemplateDao = mock(LoadedTemplateDao.class);
     fakeDashboardTemplate = mock(DashboardTemplate.class);
 
-    task = new RegisterDashboards(new DashboardTemplate[] {fakeDashboardTemplate}, dashboardDao,
-        activeDashboardDao, loadedTemplateDao);
+    task = new RegisterDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao,
+      activeDashboardDao, loadedTemplateDao);
   }
 
   @Test
@@ -128,8 +128,8 @@ public class RegisterDashboardsTest {
   @Test
   public void shouldCreateDtoFromExtension() {
     Dashboard dashboard = Dashboard.create()
-        .setGlobal(true)
-        .setLayout(DashboardLayout.TWO_COLUMNS_30_70);
+      .setGlobal(true)
+      .setLayout(DashboardLayout.TWO_COLUMNS_30_70);
     Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
     widget.setProperty("fake-property", "fake_metric");
     when(fakeDashboardTemplate.createDashboard()).thenReturn(dashboard);
@@ -153,7 +153,11 @@ public class RegisterDashboardsTest {
     assertThat(widgetDto.getCreatedAt()).isNotNull();
     assertThat(widgetDto.getUpdatedAt()).isNotNull();
 
-    assertThat(widgetDto.getWidgetProperties()).satisfies(contains(new WidgetPropertyDto().setKey("fake-property").setValue("fake_metric")));
+    Collection<WidgetPropertyDto> props = widgetDto.getWidgetProperties();
+    assertThat(props).hasSize(1);
+    WidgetPropertyDto prop = Iterables.getFirst(props, null);
+    assertThat(prop.getKey()).isEqualTo("fake-property");
+    assertThat(prop.getValue()).isEqualTo("fake_metric");
   }
 
   @Test
diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java b/sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java
deleted file mode 100644 (file)
index 16681d6..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.test;
-
-import com.google.common.base.CharMatcher;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.fest.assertions.Condition;
-
-import java.util.Collection;
-
-/**
- * Conditions for use with FestAssert.
- */
-public final class MoreConditions {
-  private static final CharMatcher EOLS = CharMatcher.anyOf("\n\r");
-
-  private MoreConditions() {
-    // static utility class
-  }
-
-  public static Condition<String> equalsIgnoreEOL(String text) {
-    final String strippedText = EOLS.removeFrom(text);
-
-    return new Condition<String>() {
-      @Override
-      public boolean matches(String value) {
-        return EOLS.removeFrom(value).equals(strippedText);
-      }
-    }.as("equal to " + strippedText);
-  }
-
-  public static Condition<Collection<?>> contains(final Object expected) {
-    return new Condition<Collection<?>>() {
-      @Override
-      public boolean matches(Collection<?> collection) {
-        for (Object actual : collection) {
-          if (EqualsBuilder.reflectionEquals(expected, actual)) {
-            return true;
-          }
-        }
-        return false;
-      }
-    };
-  }
-
-  public static Condition<Object> reflectionEqualTo(final Object expected) {
-    return new Condition<Object>() {
-      @Override
-      public boolean matches(Object actual) {
-        return EqualsBuilder.reflectionEquals(expected, actual);
-      }
-    };
-  }
-}
diff --git a/sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java b/sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java
deleted file mode 100644 (file)
index d741713..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.test;
-
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.sonar.test.MoreConditions.reflectionEqualTo;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.sonar.test.MoreConditions.contains;
-import static org.sonar.test.MoreConditions.equalsIgnoreEOL;
-
-public class MoreConditionsTest {
-  @Test
-  public void should_compare_equals_texts() {
-    assertThat("TEXT").satisfies(equalsIgnoreEOL("TEXT"));
-  }
-
-  @Test
-  public void should_ignore_line_feeds_and_carriage_returns() {
-    assertThat("BEFORE\nAFTER").satisfies(equalsIgnoreEOL("BEFOREAFTER"));
-    assertThat("BEFORE\rAFTER").satisfies(equalsIgnoreEOL("BEFOREAFTER"));
-    assertThat("BEFORE\n\rAFTER").satisfies(equalsIgnoreEOL("BEFOREAFTER"));
-    assertThat("BEFOREAFTER").satisfies(equalsIgnoreEOL("BEFORE\n\rAFTER"));
-  }
-
-  @Test
-  public void should_refuse_different_values() {
-    assertThat("TEXT").doesNotSatisfy(equalsIgnoreEOL("DIFFERENT"));
-  }
-
-  @Test
-  public void should_accept_empty_values() {
-    assertThat("").satisfies(equalsIgnoreEOL(""));
-    assertThat("").satisfies(equalsIgnoreEOL("\n\r"));
-    assertThat("\n\r").satisfies(equalsIgnoreEOL(""));
-  }
-
-  @Test
-  public void should_find_value_in_collection() {
-    Collection<String> collection = Arrays.asList("ONE", "TWO");
-
-    assertThat(collection).satisfies(contains("ONE"));
-    assertThat(collection).satisfies(contains("TWO"));
-    assertThat(collection).doesNotSatisfy(contains("THREE"));
-  }
-
-  @Test
-  public void should_find_value_in_collection_using_reflection() {
-    Collection<Bean> collection = Arrays.asList(
-        new Bean("key1", "value1"),
-        null,
-        new Bean("key2", "value2"));
-
-    assertThat(collection).satisfies(contains(new Bean("key1", "value1")));
-    assertThat(collection).satisfies(contains(new Bean("key2", "value2")));
-    assertThat(collection).doesNotSatisfy(contains(new Bean("key1", "value2")));
-    assertThat(collection).doesNotSatisfy(contains(new Bean("key2", "value1")));
-    assertThat(collection).doesNotSatisfy(contains(new Bean("", "")));
-  }
-
-  @Test
-  public void should_compare_using_reflection() {
-    Bean bean1 = new Bean("key1", "value1");
-    Bean bean2 = new Bean("key2", "value2");
-
-    assertThat(bean1).is(reflectionEqualTo(bean1));
-    assertThat(bean2).is(reflectionEqualTo(bean2));
-    assertThat(bean1).isNot(reflectionEqualTo(bean2));
-    assertThat(bean2).isNot(reflectionEqualTo(bean1));
-    assertThat(bean1).isNot(reflectionEqualTo(null));
-    assertThat(bean2).isNot(reflectionEqualTo(null));
-    assertThat(bean1).isNot(reflectionEqualTo(new Object()));
-    assertThat(bean2).isNot(reflectionEqualTo(new Object()));
-    assertThat(bean1).isNot(reflectionEqualTo(new Bean("key1", "value2")));
-    assertThat(bean1).isNot(reflectionEqualTo(new Bean("key2", "value1")));
-    assertThat(bean1).isNot(reflectionEqualTo(new Bean("", "")));
-  }
-
-  static final class Bean {
-    final String key;
-    final String value;
-
-    Bean(String key, String value) {
-      this.key = key;
-      this.value = value;
-    }
-  }
-}