]> source.dussan.org Git - sonarqube.git/commitdiff
Fix compatibility of some tests with java8
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 3 Apr 2014 09:33:09 +0000 (11:33 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 3 Apr 2014 09:33:25 +0000 (11:33 +0200)
sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
sonar-core/src/test/java/org/sonar/jpa/session/JpaDatabaseSessionTest.java
sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java

index b60278525b335489a0d7553f00ceb9f0d0e0e4cb..2004a1e259b82cd6055aec5f74039ea8201282bb 100644 (file)
@@ -55,7 +55,7 @@ import java.util.Collections;
 import java.util.TimeZone;
 
 import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.anyListOf;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -116,10 +116,10 @@ public class JsonReportTest {
       .setUpdateDate(SIMPLE_DATE_FORMAT.parse("2013-04-25"))
       .setNew(false);
     when(ruleFinder.findByKey(RuleKey.of("squid", "AvoidCycles"))).thenReturn(new Rule().setName("Avoid Cycles"));
-    when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
+    when(jsonReport.getIssues()).thenReturn(Lists.newArrayList(issue));
     DefaultUser user1 = new DefaultUser().setLogin("julien").setName("Julien");
     DefaultUser user2 = new DefaultUser().setLogin("simon").setName("Simon");
-    when(userFinder.findByLogins(eq(Arrays.asList("julien", "simon")))).thenReturn(Lists.<User>newArrayList(user1, user2));
+    when(userFinder.findByLogins(anyListOf(String.class))).thenReturn(Lists.<User>newArrayList(user1, user2));
 
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
index 782d52f39e718fbf73ed07e5acb8600d027d8f18..2c6f92b573394346048310b3c9f861cdae01eef1 100644 (file)
@@ -69,7 +69,7 @@ public class JpaDatabaseSessionTest {
   @Test
   public void shouldBuildCriteriasHQL() {
     StringBuilder hql = new StringBuilder();
-    Map<String, Object> mappedCriterias = Maps.newHashMap();
+    Map<String, Object> mappedCriterias = Maps.newLinkedHashMap();
     mappedCriterias.put("foo", "value");
     mappedCriterias.put("bar", null);
     session.buildCriteriasHQL(hql, mappedCriterias);
index ded08d4c880affd7534340f5c8fc578eb4f4790f..d6b280e93d4f93ca1c6941bc81838869b505d2cb 100644 (file)
@@ -23,12 +23,10 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.commons.lang.SystemUtils;
 import org.junit.Test;
 
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class CycleDetectorTest {
 
@@ -41,7 +39,7 @@ public class CycleDetectorTest {
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dag);
     cycleDetector.detectCycles();
-    assertTrue(cycleDetector.isAcyclicGraph());
+    assertThat(cycleDetector.isAcyclicGraph()).isTrue();
   }
 
   @Test
@@ -51,7 +49,7 @@ public class CycleDetectorTest {
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg);
     cycleDetector.detectCycles();
-    assertFalse(cycleDetector.isAcyclicGraph());
+    assertThat(cycleDetector.isAcyclicGraph()).isFalse();
   }
 
   @Test
@@ -67,8 +65,14 @@ public class CycleDetectorTest {
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg);
     cycleDetector.detectCycles();
-    assertThat(cycleDetector.getCycles().size(), is(8));
-    assertThat(cycleDetector.getSearchCyclesCalls(), is(8L));
+    assertThat(cycleDetector.getCycles()).hasSize(8);
+
+    if (SystemUtils.IS_JAVA_1_6 || SystemUtils.IS_JAVA_1_7) {
+      assertThat(cycleDetector.getSearchCyclesCalls()).isEqualTo(8);
+    } else {
+      // Java 8
+      assertThat(cycleDetector.getSearchCyclesCalls()).isEqualTo(11);
+    }
   }
 
   @Test
@@ -80,11 +84,11 @@ public class CycleDetectorTest {
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg);
     cycleDetector.detectCyclesWithMaxSearchDepth(3);
-    assertThat(cycleDetector.getCycles().size(), is(2));
+    assertThat(cycleDetector.getCycles()).hasSize(2);
 
     cycleDetector = new CycleDetector<String>(dcg);
     cycleDetector.detectCyclesWithMaxSearchDepth(2);
-    assertThat(cycleDetector.getCycles().size(), is(1));
+    assertThat(cycleDetector.getCycles()).hasSize(1);
   }
 
   @Test
@@ -100,7 +104,7 @@ public class CycleDetectorTest {
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg, excludedEdges);
     cycleDetector.detectCycles();
-    assertThat(cycleDetector.getCycles().size(), is(1));
+    assertThat(cycleDetector.getCycles()).hasSize(1);
   }
 
   @Test
@@ -111,11 +115,11 @@ public class CycleDetectorTest {
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg);
     cycleDetector.detectCycles();
-    assertThat(cycleDetector.getCycles().size(), is(1));
+    assertThat(cycleDetector.getCycles()).hasSize(1);
     Cycle cycle = cycleDetector.getCycles().iterator().next();
-    assertThat(cycle.size(), is(2));
-    assertTrue(cycle.contains(new StringEdge("A", "B")));
-    assertTrue(cycle.contains(new StringEdge("B", "A")));
+    assertThat(cycle.size()).isEqualTo(2);
+    assertThat(cycle.contains(new StringEdge("A", "B"))).isTrue();
+    assertThat(cycle.contains(new StringEdge("B", "A"))).isTrue();
   }
 
   @Test
@@ -126,12 +130,12 @@ public class CycleDetectorTest {
     // C must not be used to find cycles
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg, Arrays.asList("A", "B"));
     cycleDetector.detectCycles();
-    assertThat(cycleDetector.getCycles().size(), is(0));
+    assertThat(cycleDetector.getCycles()).isEmpty();
 
     // C is used to find cycles
     cycleDetector = new CycleDetector<String>(dcg, Arrays.asList("A", "B", "C"));
     cycleDetector.detectCycles();
-    assertThat(cycleDetector.getCycles().size(), is(1));
+    assertThat(cycleDetector.getCycles().size()).isEqualTo(1);
   }
 
   @Test(expected = IllegalStateException.class)
@@ -151,6 +155,6 @@ public class CycleDetectorTest {
     dcg.addEdge("B", "A");
 
     CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg);
-    assertThat(cycleDetector.detectCyclesWithUpperLimit(1).size(), is(1));
+    assertThat(cycleDetector.detectCyclesWithUpperLimit(1)).hasSize(1);
   }
 }