Browse Source

Removed JUnit test. Added Scalatest spec.

Abhinav Sarkar 10 years ago
parent
commit
ce4a80d105

+ 1
- 0
.classpath View File

@@ -2,6 +2,7 @@
2 2
 <classpath>
3 3
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
4 4
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
5
+	<classpathentry kind="src" path="src/test/scala"/>
5 6
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
6 7
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7 8
 	<classpathentry kind="output" path="target/classes"/>

+ 3
- 2
.project View File

@@ -6,17 +6,18 @@
6 6
 	</projects>
7 7
 	<buildSpec>
8 8
 		<buildCommand>
9
-			<name>org.eclipse.jdt.core.javabuilder</name>
9
+			<name>org.maven.ide.eclipse.maven2Builder</name>
10 10
 			<arguments>
11 11
 			</arguments>
12 12
 		</buildCommand>
13 13
 		<buildCommand>
14
-			<name>org.maven.ide.eclipse.maven2Builder</name>
14
+			<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
15 15
 			<arguments>
16 16
 			</arguments>
17 17
 		</buildCommand>
18 18
 	</buildSpec>
19 19
 	<natures>
20
+		<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
20 21
 		<nature>org.eclipse.jdt.core.javanature</nature>
21 22
 		<nature>org.maven.ide.eclipse.maven2Nature</nature>
22 23
 	</natures>

+ 21
- 2
SpelHelper.iml View File

@@ -1,16 +1,35 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" inherit-compiler-output="false">
3
+  <component name="FacetManager">
4
+    <facet type="Scala" name="Scala">
5
+      <configuration>
6
+        <option name="takeFromSettings" value="true" />
7
+        <option name="myScalaSdkJarPaths">
8
+          <array>
9
+            <option value="$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.7/scala-library-2.7.7.jar" />
10
+          </array>
11
+        </option>
12
+      </configuration>
13
+    </facet>
14
+  </component>
15
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
4 16
     <output url="file://$MODULE_DIR$/target/classes" />
5 17
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 18
     <content url="file://$MODULE_DIR$">
19
+      <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
7 20
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8 21
       <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
-      <excludeFolder url="file://$MODULE_DIR$/target" />
22
+      <sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="true" />
23
+      <excludeFolder url="file://$MODULE_DIR$/target/classes" />
24
+      <excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
25
+      <excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
10 26
     </content>
11 27
     <orderEntry type="inheritedJdk" />
12 28
     <orderEntry type="sourceFolder" forTests="false" />
13 29
     <orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
30
+    <orderEntry type="library" exported="" name="Maven: org.scala-lang:scala-library:2.7.7" level="project" />
31
+    <orderEntry type="library" scope="TEST" name="Maven: org.scalatest:scalatest:1.0" level="project" />
32
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.4" level="project" />
14 33
     <orderEntry type="library" exported="" name="Maven: org.springframework:spring-core:3.0.2.RELEASE" level="project" />
15 34
     <orderEntry type="library" exported="" name="Maven: org.springframework:spring-asm:3.0.2.RELEASE" level="project" />
16 35
     <orderEntry type="library" exported="" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />

+ 61
- 1
pom.xml View File

@@ -13,6 +13,7 @@
13 13
 
14 14
  <properties>
15 15
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16
+  <scala.version>2.7.7</scala.version>
16 17
  </properties>
17 18
 
18 19
  <issueManagement>
@@ -41,7 +42,7 @@
41 42
     <executions>
42 43
      <execution>
43 44
       <id>javadoc</id>
44
-      <phase>process-sources</phase>
45
+      <phase>install</phase>
45 46
       <goals>
46 47
        <goal>javadoc</goal>
47 48
       </goals>
@@ -70,7 +71,38 @@
70 71
      <target>1.6</target>
71 72
     </configuration>
72 73
    </plugin>
74
+   <plugin>
75
+    <groupId>org.scala-tools</groupId>
76
+    <artifactId>maven-scala-plugin</artifactId>
77
+    <version>2.12</version>
78
+    <executions>
79
+     <execution>
80
+      <goals>
81
+       <goal>compile</goal>
82
+       <goal>testCompile</goal>
83
+      </goals>
84
+     </execution>
85
+    </executions>
86
+    <configuration>
87
+     <scalaVersion>${scala.version}</scalaVersion>
88
+     <includes>
89
+      <include>**/*.scala</include>
90
+     </includes>
91
+    </configuration>
92
+   </plugin>
93
+   <plugin>
94
+    <groupId>org.apache.maven.plugins</groupId>
95
+    <artifactId>maven-surefire-plugin</artifactId>
96
+    <version>2.5</version>
97
+    <configuration>
98
+     <reportFormat>plain</reportFormat>
99
+     <includes>
100
+      <include>**/*Spec.class</include>
101
+     </includes>
102
+    </configuration>
103
+   </plugin>
73 104
   </plugins>
105
+
74 106
   <resources>
75 107
    <resource>
76 108
     <filtering>true</filtering>
@@ -82,7 +114,34 @@
82 114
   </resources>
83 115
  </build>
84 116
 
117
+ <pluginRepositories>
118
+  <pluginRepository>
119
+   <id>scala-tools.org</id>
120
+   <name>Scala-tools Maven2 Repository</name>
121
+   <url>http://scala-tools.org/repo-releases</url>
122
+  </pluginRepository>
123
+ </pluginRepositories>
124
+
125
+ <repositories>
126
+  <repository>
127
+   <id>scala-tools.org</id>
128
+   <name>Scala-Tools Maven2 Repository</name>
129
+   <url>http://scala-tools.org/repo-releases</url>
130
+  </repository>
131
+ </repositories>
132
+
85 133
  <dependencies>
134
+  <dependency>
135
+   <groupId>org.scala-lang</groupId>
136
+   <artifactId>scala-library</artifactId>
137
+   <version>${scala.version}</version>
138
+  </dependency>
139
+  <dependency>
140
+   <groupId>org.scalatest</groupId>
141
+   <artifactId>scalatest</artifactId>
142
+   <version>1.0</version>
143
+   <scope>test</scope>
144
+  </dependency>
86 145
   <dependency>
87 146
    <groupId>junit</groupId>
88 147
    <artifactId>junit</artifactId>
@@ -100,4 +159,5 @@
100 159
    <version>3.0.2.RELEASE</version>
101 160
   </dependency>
102 161
  </dependencies>
162
+
103 163
 </project>

+ 3
- 1
src/main/java/net/abhinavsarkar/spelhelper/ImplicitMethodResolver.java View File

@@ -87,7 +87,9 @@ final class ImplicitMethodResolver implements MethodResolver {
87 87
                                     newArgumentTypes);
88 88
                     MethodExecutor wrappedExecutor = executor == null ? null
89 89
                             : new ImplicitMethodExecutor(executor);
90
-                    CACHE.putIfAbsent(cacheKey, wrappedExecutor);
90
+                    if(wrappedExecutor == null) {
91
+                        CACHE.putIfAbsent(cacheKey, NULL_ME);
92
+                    }
91 93
                     return wrappedExecutor;
92 94
                 }
93 95
             }

+ 13
- 0
src/test/java/net/abhinavsarkar/spelhelper/Functions.java View File

@@ -0,0 +1,13 @@
1
+package net.abhinavsarkar.spelhelper;
2
+
3
+public final class Functions {
4
+
5
+    public static String test(String str) {
6
+        return str;
7
+    }
8
+
9
+    @Override
10
+    public boolean equals(Object o) {
11
+        return o instanceof Functions;
12
+    }
13
+}

+ 0
- 43
src/test/java/net/abhinavsarkar/spelhelper/SpelHelperTest.java View File

@@ -1,43 +0,0 @@
1
-package net.abhinavsarkar.spelhelper;
2
-
3
-import java.util.Arrays;
4
-import java.util.List;
5
-
6
-import org.junit.Assert;
7
-import org.junit.Test;
8
-
9
-public class SpelHelperTest {
10
-
11
-    @Test
12
-    public void testRegisteredFunction() {
13
-        Assert.assertEquals(
14
-                Arrays.asList("abhinav", "mini", "dan"),
15
-                new SpelHelper().evalExpression(
16
-                        "#list('abhinav','mini','dan')", new Object(), List.class));
17
-    }
18
-
19
-    @Test
20
-    public void testImplicitMethod() {
21
-        Assert.assertEquals(
22
-                Arrays.asList("abhinav", "dan", "mini"),
23
-                new SpelHelper().evalExpression(
24
-                        "#list('abhinav','mini','dan').sorted", new Object(), List.class));
25
-    }
26
-
27
-    public static final class ConstructorTest {
28
-        @Override
29
-        public boolean equals(final Object o) {
30
-            return o instanceof ConstructorTest;
31
-        }
32
-    }
33
-
34
-    @Test
35
-    public void testImplicitConstructor() {
36
-        Assert.assertEquals(
37
-            new ConstructorTest(),
38
-            new SpelHelper()
39
-                .registerConstructorsFromClass(ConstructorTest.class)
40
-                .evalExpression("new ConstructorTest()", new Object(), ConstructorTest.class));
41
-    }
42
-
43
-}

+ 54
- 0
src/test/scala/net/abhinavsarkar/spelhelper/SpelHelperSpec.scala View File

@@ -0,0 +1,54 @@
1
+package net.abhinavsarkar.spelhelper
2
+
3
+import org.scalatest.junit.JUnitRunner
4
+import org.junit.runner.RunWith
5
+import org.scalatest.Spec
6
+import org.scalatest.junit.ShouldMatchersForJUnit
7
+
8
+@RunWith(classOf[JUnitRunner])
9
+class SpelHelperSpec extends Spec with ShouldMatchersForJUnit {
10
+  describe("SpelHelper") {
11
+
12
+    it ("should register and evaluate functions ") {
13
+      new SpelHelper()
14
+        .registerFunctionsFromClass(classOf[Functions])
15
+        .evalExpression(
16
+          "#test('check')", new {}, classOf[String]) should equal("check")
17
+    }
18
+
19
+    it ("should register implicit methods ") {
20
+      new SpelHelper()
21
+        .registerImplicitMethodsFromClass(classOf[Functions])
22
+        .lookupImplicitMethod("java.lang.String.test") should equal(
23
+          classOf[Functions].getMethod("test", classOf[String]))
24
+    }
25
+
26
+    it ("should register implicit constructors ") {
27
+      new SpelHelper()
28
+        .registerConstructorsFromClass(classOf[Functions])
29
+        .lookupImplicitConstructor("Functions[]") should equal(
30
+          classOf[Functions].getConstructor())
31
+    }
32
+
33
+    it ("should evaluate implicit methods ") {
34
+      new SpelHelper()
35
+        .registerImplicitMethodsFromClass(classOf[Functions])
36
+        .evalExpression(
37
+          "'check'.test()", new {}, classOf[String]) should equal("check")
38
+    }
39
+
40
+    it ("should evaluate implicit constructors ") {
41
+      new SpelHelper()
42
+        .registerConstructorsFromClass(classOf[Functions])
43
+        .evalExpression(
44
+          "new Functions()", new {}, classOf[Functions]) should equal(new Functions)
45
+    }
46
+
47
+    it ("should evaluate implicit properties ") {
48
+      new SpelHelper().evalExpression(
49
+        "'abc'.hashCode", new {}, classOf[int]) should equal("abc".hashCode) 
50
+    }
51
+
52
+  }
53
+}
54
+

Loading…
Cancel
Save