aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-testing-harness
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-05-22 11:56:58 +0200
committerDavid Gageot <david@gageot.net>2012-05-22 11:56:58 +0200
commitfd7f6a27f9bfc895298a57be47fe7511d9d004b4 (patch)
tree038e8769718bb18dbb2091604aa6a3f384f72315 /sonar-testing-harness
parent70a99389ba85ae3e7d20c8f56acb571d2ee915a7 (diff)
downloadsonarqube-fd7f6a27f9bfc895298a57be47fe7511d9d004b4.tar.gz
sonarqube-fd7f6a27f9bfc895298a57be47fe7511d9d004b4.zip
SONAR-3016 More work on extension point for filter template
Recognize more filter criterias
Diffstat (limited to 'sonar-testing-harness')
-rw-r--r--sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java17
-rw-r--r--sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java37
2 files changed, 54 insertions, 0 deletions
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
index c83e5ff9ec1..c06b78a65e6 100644
--- a/sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java
+++ b/sonar-testing-harness/src/main/java/org/sonar/test/MoreConditions.java
@@ -20,8 +20,11 @@
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.
*/
@@ -42,4 +45,18 @@ public final class MoreConditions {
}
}.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;
+ }
+ };
+ }
}
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
index 86ba9114c6e..ad83811e999 100644
--- a/sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java
+++ b/sonar-testing-harness/src/test/java/org/sonar/test/MoreConditionsTest.java
@@ -21,7 +21,11 @@ package org.sonar.test;
import org.junit.Test;
+import java.util.Arrays;
+import java.util.Collection;
+
import static org.fest.assertions.Assertions.assertThat;
+import static org.sonar.test.MoreConditions.contains;
import static org.sonar.test.MoreConditions.equalsIgnoreEOL;
public class MoreConditionsTest {
@@ -49,4 +53,37 @@ public class MoreConditionsTest {
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("", "")));
+ }
+
+ static final class Bean {
+ final String key;
+ final String value;
+
+ Bean(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+ }
}