From 95820442b90fc0642453e51c9233bae36a3b28db Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 3 Apr 2014 11:33:09 +0200 Subject: [PATCH] Fix compatibility of some tests with java8 --- .../batch/scan/report/JsonReportTest.java | 6 +-- .../jpa/session/JpaDatabaseSessionTest.java | 2 +- .../org/sonar/graph/CycleDetectorTest.java | 40 ++++++++++--------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java index b60278525b3..2004a1e259b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java @@ -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.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.newArrayList(user1, user2)); + when(userFinder.findByLogins(anyListOf(String.class))).thenReturn(Lists.newArrayList(user1, user2)); StringWriter writer = new StringWriter(); jsonReport.writeJson(writer); diff --git a/sonar-core/src/test/java/org/sonar/jpa/session/JpaDatabaseSessionTest.java b/sonar-core/src/test/java/org/sonar/jpa/session/JpaDatabaseSessionTest.java index 782d52f39e7..2c6f92b5733 100644 --- a/sonar-core/src/test/java/org/sonar/jpa/session/JpaDatabaseSessionTest.java +++ b/sonar-core/src/test/java/org/sonar/jpa/session/JpaDatabaseSessionTest.java @@ -69,7 +69,7 @@ public class JpaDatabaseSessionTest { @Test public void shouldBuildCriteriasHQL() { StringBuilder hql = new StringBuilder(); - Map mappedCriterias = Maps.newHashMap(); + Map mappedCriterias = Maps.newLinkedHashMap(); mappedCriterias.put("foo", "value"); mappedCriterias.put("bar", null); session.buildCriteriasHQL(hql, mappedCriterias); diff --git a/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java b/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java index ded08d4c880..d6b280e93d4 100644 --- a/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java +++ b/sonar-graph/src/test/java/org/sonar/graph/CycleDetectorTest.java @@ -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 cycleDetector = new CycleDetector(dag); cycleDetector.detectCycles(); - assertTrue(cycleDetector.isAcyclicGraph()); + assertThat(cycleDetector.isAcyclicGraph()).isTrue(); } @Test @@ -51,7 +49,7 @@ public class CycleDetectorTest { CycleDetector cycleDetector = new CycleDetector(dcg); cycleDetector.detectCycles(); - assertFalse(cycleDetector.isAcyclicGraph()); + assertThat(cycleDetector.isAcyclicGraph()).isFalse(); } @Test @@ -67,8 +65,14 @@ public class CycleDetectorTest { CycleDetector cycleDetector = new CycleDetector(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 cycleDetector = new CycleDetector(dcg); cycleDetector.detectCyclesWithMaxSearchDepth(3); - assertThat(cycleDetector.getCycles().size(), is(2)); + assertThat(cycleDetector.getCycles()).hasSize(2); cycleDetector = new CycleDetector(dcg); cycleDetector.detectCyclesWithMaxSearchDepth(2); - assertThat(cycleDetector.getCycles().size(), is(1)); + assertThat(cycleDetector.getCycles()).hasSize(1); } @Test @@ -100,7 +104,7 @@ public class CycleDetectorTest { CycleDetector cycleDetector = new CycleDetector(dcg, excludedEdges); cycleDetector.detectCycles(); - assertThat(cycleDetector.getCycles().size(), is(1)); + assertThat(cycleDetector.getCycles()).hasSize(1); } @Test @@ -111,11 +115,11 @@ public class CycleDetectorTest { CycleDetector cycleDetector = new CycleDetector(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 cycleDetector = new CycleDetector(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(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 cycleDetector = new CycleDetector(dcg); - assertThat(cycleDetector.detectCyclesWithUpperLimit(1).size(), is(1)); + assertThat(cycleDetector.detectCyclesWithUpperLimit(1)).hasSize(1); } } -- 2.39.5