summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-20 09:44:04 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-06-20 09:44:12 +0200
commit3e2c93fa36af82323fb0f46904c2d4e8ca3a248d (patch)
tree8940473ed08eaac8aca0b57bb58c94b051df0e25 /sonar-plugin-api
parentd0569c1ebf7aa7b2aa4a42cef4f0664a2a4bb534 (diff)
downloadsonarqube-3e2c93fa36af82323fb0f46904c2d4e8ca3a248d.tar.gz
sonarqube-3e2c93fa36af82323fb0f46904c2d4e8ca3a248d.zip
Fix Hamcrest tests by replacing it with Fest
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java88
1 files changed, 41 insertions, 47 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java
index c41f6856076..1746a6d982c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/FieldUtils2Test.java
@@ -19,65 +19,76 @@
*/
package org.sonar.api.utils;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
import org.junit.Test;
+import javax.annotation.Nullable;
+
import java.lang.reflect.Field;
import java.util.List;
-import static org.hamcrest.Matchers.hasItem;
-import static org.junit.Assert.assertThat;
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
public class FieldUtils2Test {
@Test
public void shouldGetFieldsOfSingleClass() {
- List<Field> fields = FieldUtils2.getFields(FieldsWithDifferentModifiers.class, true);
- assertThat(fields, hasItem(new FieldMatcher("publicField")));
- assertThat(fields, hasItem(new FieldMatcher("protectedField")));
- assertThat(fields, hasItem(new FieldMatcher("packageField")));
- assertThat(fields, hasItem(new FieldMatcher("privateField")));
- assertThat(fields, hasItem(new FieldMatcher("publicStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("protectedStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("packageStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("privateStaticField")));
+ List<String> fields = fieldsName(FieldUtils2.getFields(FieldsWithDifferentModifiers.class, true));
+ assertThat(fields).contains("publicField");
+ assertThat(fields).contains("protectedField");
+ assertThat(fields).contains("packageField");
+ assertThat(fields).contains("privateField");
+ assertThat(fields).contains("publicStaticField");
+ assertThat(fields).contains("protectedStaticField");
+ assertThat(fields).contains("packageStaticField");
+ assertThat(fields).contains("privateStaticField");
}
@Test
public void shouldGetFieldsOfClassHierarchy() {
- List<Field> fields = FieldUtils2.getFields(Child.class, true);
- assertThat(fields, hasItem(new FieldMatcher("publicField")));
- assertThat(fields, hasItem(new FieldMatcher("protectedField")));
- assertThat(fields, hasItem(new FieldMatcher("packageField")));
- assertThat(fields, hasItem(new FieldMatcher("privateField")));
- assertThat(fields, hasItem(new FieldMatcher("publicStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("protectedStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("packageStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("privateStaticField")));
- assertThat(fields, hasItem(new FieldMatcher("childPrivateField")));
+ List<String> fields = fieldsName(FieldUtils2.getFields(Child.class, true));
+ assertThat(fields).contains("publicField");
+ assertThat(fields).contains("protectedField");
+ assertThat(fields).contains("packageField");
+ assertThat(fields).contains("privateField");
+ assertThat(fields).contains("publicStaticField");
+ assertThat(fields).contains("protectedStaticField");
+ assertThat(fields).contains("packageStaticField");
+ assertThat(fields).contains("privateStaticField");
+ assertThat(fields).contains("childPrivateField");
}
@Test
public void shouldGetOnlyAccessibleFields() {
- List<Field> fields = FieldUtils2.getFields(Child.class, false);
+ List<String> fields = fieldsName(FieldUtils2.getFields(Child.class, false));
- assertThat(fields, hasItem(new FieldMatcher("publicField")));
- assertThat(fields, hasItem(new FieldMatcher("publicStaticField")));
+ assertThat(fields).contains("publicField");
+ assertThat(fields).contains("publicStaticField");
}
@Test
public void shouldGetFieldsOfInterface() {
- List<Field> fields = FieldUtils2.getFields(InterfaceWithFields.class, true);
+ List<String> fields = fieldsName(FieldUtils2.getFields(InterfaceWithFields.class, true));
- assertThat(fields, hasItem(new FieldMatcher("INTERFACE_FIELD")));
+ assertThat(fields).contains("INTERFACE_FIELD");
}
@Test
public void shouldGetFieldsOfInterfaceImplementation() {
- List<Field> fields = FieldUtils2.getFields(InterfaceImplementation.class, true);
+ List<String> fields = fieldsName(FieldUtils2.getFields(InterfaceImplementation.class, true));
+
+ assertThat(fields).contains("INTERFACE_FIELD");
+ }
- assertThat(fields, hasItem(new FieldMatcher("INTERFACE_FIELD")));
+ private static List<String> fieldsName(List<Field> fields){
+ return newArrayList(Iterables.transform(fields, new Function<Field, String>() {
+ @Override
+ public String apply(@Nullable Field input) {
+ return input != null ? input.getName() : null;
+ }
+ }));
}
static interface InterfaceWithFields {
@@ -103,21 +114,4 @@ public class FieldUtils2Test {
private String childPrivateField;
}
-
- static class FieldMatcher extends BaseMatcher<Field> {
- private String name;
-
- FieldMatcher(String name) {
- this.name = name;
- }
-
- public boolean matches(Object o) {
- Field field = (Field) o;
- return name.equals(field.getName());
- }
-
- public void describeTo(Description description) {
- description.appendText("Field with name: ").appendValue(name);
- }
- }
}