summaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-05-14 16:02:43 -0500
committerSonarTech <sonartech@sonarsource.com>2019-05-16 20:21:08 +0200
commit74cbdd7c043e8e9ee51d7c18aeef86db386df136 (patch)
tree480cb1cca1765b6a0d985cb754de31d325604a4e /sonar-duplications
parent9240dd9a15b317d94c1db5c94281398a16b2b36a (diff)
downloadsonarqube-74cbdd7c043e8e9ee51d7c18aeef86db386df136.tar.gz
sonarqube-74cbdd7c043e8e9ee51d7c18aeef86db386df136.zip
SONAR-12108 Support Java 11 RTE
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java58
1 files changed, 51 insertions, 7 deletions
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
index c739fa666ab..92b2085ef3d 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
@@ -19,13 +19,6 @@
*/
package org.sonar.duplications.java;
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.sonar.duplications.DuplicationsTestUtil;
-import org.sonar.duplications.statement.Statement;
-import org.sonar.duplications.statement.StatementChunker;
-import org.sonar.duplications.token.TokenChunker;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -33,6 +26,12 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.List;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.sonar.duplications.DuplicationsTestUtil;
+import org.sonar.duplications.statement.Statement;
+import org.sonar.duplications.statement.StatementChunker;
+import org.sonar.duplications.token.TokenChunker;
import static org.assertj.core.api.Assertions.assertThat;
@@ -318,6 +317,51 @@ public class JavaStatementBuilderTest {
assertThat(statements.get(1).getValue()).isEqualTo("something()");
}
+ /**
+ * Java 8.
+ */
+ @Test
+ public void shouldHandleLambda() {
+ List<Statement> statements;
+ statements = chunk("List<String> result = lines.stream().filter(line -> !\"mkyong\".equals(line)).collect(Collectors.toList());");
+ assertThat(statements.size()).isEqualTo(1);
+ assertThat(statements).extracting(Statement::getValue).containsExactly("List<String>result=lines.stream().filter(line->!$CHARS.equals(line)).collect(Collectors.toList())");
+
+ statements = chunk("items.forEach((k,v)->{System.out.println(\"Item : \" + k + \" Count : \" + v); if(\"E\".equals(k)) { System.out.println(\"Hello E\");}});");
+ assertThat(statements.size()).isEqualTo(5);
+ assertThat(statements).extracting(Statement::getValue)
+ .containsExactly("items.forEach((k,v)->",
+ "System.out.println($CHARS+k+$CHARS+v)",
+ "if($CHARS.equals(k))",
+ "System.out.println($CHARS)",
+ ")");
+ }
+
+ /**
+ * Java 9.
+ */
+ @Test
+ public void shouldHandleModuleInfo() {
+ List<Statement> statements;
+ statements = chunk("module com.application.infra { requires com.application.domain; exports com.application.infra.api; }");
+ assertThat(statements.size()).isEqualTo(3);
+ assertThat(statements).extracting(Statement::getValue)
+ .containsExactly("modulecom.application.infra",
+ "requirescom.application.domain",
+ "exportscom.application.infra.api");
+ }
+
+ /**
+ * Java 11.
+ */
+ @Test
+ public void shouldHandleVar() {
+ List<Statement> statements;
+ statements = chunk("IFunc f = (@NonNull var x, final var y) -> Foo.foo(x, y);");
+ assertThat(statements.size()).isEqualTo(1);
+ assertThat(statements).extracting(Statement::getValue).containsExactly("IFuncf=(@NonNullvarx,finalvary)->Foo.foo(x,y)");
+ }
+
@Test
public void realExamples() {
assertThat(chunk(DuplicationsTestUtil.findFile("/java/MessageResources.java")).size()).isGreaterThan(0);