From: Simon Brandhof Date: Wed, 23 Apr 2014 13:17:38 +0000 (+0200) Subject: Remove the class MoreConditions from sonar-testing-harness X-Git-Tag: 4.4-RC1~1418 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b131f3d7faae41ae931f522b4ae208c69aab5dee;p=sonarqube.git Remove the class MoreConditions from sonar-testing-harness --- diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterDashboardsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterDashboardsTest.java index 2a38d59274a..33ea65d13ef 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterDashboardsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterDashboardsTest.java @@ -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 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 index 16681d6f88f..00000000000 --- a/sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java +++ /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 equalsIgnoreEOL(String text) { - final String strippedText = EOLS.removeFrom(text); - - return new Condition() { - @Override - public boolean matches(String value) { - return EOLS.removeFrom(value).equals(strippedText); - } - }.as("equal to " + strippedText); - } - - public static Condition> contains(final Object expected) { - return new Condition>() { - @Override - public boolean matches(Collection collection) { - for (Object actual : collection) { - if (EqualsBuilder.reflectionEquals(expected, actual)) { - return true; - } - } - return false; - } - }; - } - - public static Condition reflectionEqualTo(final Object expected) { - return new Condition() { - @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 index d741713daad..00000000000 --- a/sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java +++ /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 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 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; - } - } -}