From 4f3bd9953c90abd77c49b5cc339601dcd85f9a20 Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Tue, 8 Nov 2016 17:48:55 -0500 Subject: [PATCH] Tests polishing --- .../ide/vscode/commons/jandex/Wrappers.java | 21 ++++++++++++++- .../vscode/commons/maven/JavaIndexTest.java | 26 +++++++++++++++++++ .../yaml/ApplicationYamlEditorTest.java | 10 +++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/vscode-extensions/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/Wrappers.java b/vscode-extensions/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/Wrappers.java index 0e88fd9dc..8ec628f0c 100644 --- a/vscode-extensions/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/Wrappers.java +++ b/vscode-extensions/commons/commons-java/src/main/java/org/springframework/ide/vscode/commons/jandex/Wrappers.java @@ -15,6 +15,7 @@ import org.jboss.jandex.IndexView; import org.jboss.jandex.MethodInfo; import org.jboss.jandex.PrimitiveType; import org.jboss.jandex.Type; +import org.jboss.jandex.Type.Kind; import org.springframework.ide.vscode.commons.java.IAnnotation; import org.springframework.ide.vscode.commons.java.IField; import org.springframework.ide.vscode.commons.java.IJavaType; @@ -319,7 +320,25 @@ public class Wrappers { @SuppressWarnings("unchecked") private static Type from(IJavaType type) { - if (type instanceof TypeWrapper) { + if (type == IPrimitiveType.BOOLEAN) { + return PrimitiveType.BOOLEAN; + } else if (type == IPrimitiveType.BYTE) { + return PrimitiveType.BYTE; + } else if (type == IPrimitiveType.CHAR) { + return PrimitiveType.CHAR; + } else if (type == IPrimitiveType.DOUBLE) { + return PrimitiveType.DOUBLE; + } else if (type == IPrimitiveType.FLOAT) { + return PrimitiveType.FLOAT; + } else if (type == IPrimitiveType.INT) { + return PrimitiveType.INT; + } else if (type == IPrimitiveType.LONG) { + return PrimitiveType.LONG; + } else if (type == IPrimitiveType.SHORT) { + return PrimitiveType.SHORT; + } else if (type == IVoidType.DEFAULT) { + return Type.create(null, Kind.VOID); + } else if (type instanceof TypeWrapper) { return ((TypeWrapper)type).getType(); } throw new IllegalArgumentException("Not a Jandex wrapped typed!"); diff --git a/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/JavaIndexTest.java b/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/JavaIndexTest.java index d49b0594f..48383a330 100644 --- a/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/JavaIndexTest.java +++ b/vscode-extensions/commons/commons-maven/src/test/java/org/springframework/ide/vscode/commons/maven/JavaIndexTest.java @@ -6,10 +6,13 @@ import static org.junit.Assert.assertNull; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collections; +import java.util.stream.Collectors; import java.util.stream.Stream; import org.junit.Test; import org.springframework.ide.vscode.commons.java.IMethod; +import org.springframework.ide.vscode.commons.java.IPrimitiveType; import org.springframework.ide.vscode.commons.java.IType; import org.springframework.ide.vscode.commons.java.IVoidType; import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject; @@ -62,4 +65,27 @@ public class JavaIndexTest { assertEquals(IVoidType.DEFAULT, m.getReturnType()); assertEquals(0, m.parameters().count()); } + + @Test + public void voidConstructor() throws Exception { + MavenJavaProject project = projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"); + IType type = project.findType("java.util.ArrayList"); + assertNotNull(type); + IMethod m = type.getMethod("", Stream.empty()); + assertEquals("", m.getElementName()); + assertEquals(IVoidType.DEFAULT, m.getReturnType()); + assertEquals(0, m.parameters().count()); + } + + @Test + public void constructorMethodWithParams() throws Exception { + MavenJavaProject project = projectsCache.get("gs-rest-service-cors-boot-1.4.1-with-classpath-file"); + IType type = project.findType("java.util.ArrayList"); + assertNotNull(type); + IMethod m = type.getMethod("", Stream.of(IPrimitiveType.INT)); + assertEquals("", m.getElementName()); + assertEquals(IVoidType.DEFAULT, m.getReturnType()); + assertEquals(Collections.singletonList(IPrimitiveType.INT), m.parameters().collect(Collectors.toList())); + } + } diff --git a/vscode-extensions/vscode-application-yaml/src/test/java/org/springframework/ide/vscode/application/yaml/ApplicationYamlEditorTest.java b/vscode-extensions/vscode-application-yaml/src/test/java/org/springframework/ide/vscode/application/yaml/ApplicationYamlEditorTest.java index 12b51a54c..6d88cf677 100644 --- a/vscode-extensions/vscode-application-yaml/src/test/java/org/springframework/ide/vscode/application/yaml/ApplicationYamlEditorTest.java +++ b/vscode-extensions/vscode-application-yaml/src/test/java/org/springframework/ide/vscode/application/yaml/ApplicationYamlEditorTest.java @@ -682,6 +682,16 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest { "bad: BLUE|Expecting a 'demo.Color", "Bogus|Expecting a 'demo.Color" ); + + /* + * TODO: if enums are not sorted by the 3rd party java indexing lib then + * perform the commented out test rather than the above + */ + // editor.assertProblems( +// "bad: BLUE|Expecting a 'demo.Color[RED, GREEN, BLUE]' but got a 'Mapping' node", +// "Bogus|Expecting a 'demo.Color[RED, GREEN, BLUE]' but got 'Bogus'" +// ); + } @Test public void testReconcileSkipIfNoMetadata() throws Exception {