Browse Source

Removed JUnit test. Added Scalatest spec.

master
Abhinav Sarkar 13 years ago
parent
commit
ce4a80d105
  1. 1
      .classpath
  2. 5
      .project
  3. 23
      SpelHelper.iml
  4. 62
      pom.xml
  5. 4
      src/main/java/net/abhinavsarkar/spelhelper/ImplicitMethodResolver.java
  6. 13
      src/test/java/net/abhinavsarkar/spelhelper/Functions.java
  7. 43
      src/test/java/net/abhinavsarkar/spelhelper/SpelHelperTest.java
  8. 54
      src/test/scala/net/abhinavsarkar/spelhelper/SpelHelperSpec.scala

1
.classpath

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

5
.project

@ -6,17 +6,18 @@
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>

23
SpelHelper.iml

@ -1,16 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<component name="FacetManager">
<facet type="Scala" name="Scala">
<configuration>
<option name="takeFromSettings" value="true" />
<option name="myScalaSdkJarPaths">
<array>
<option value="$MAVEN_REPOSITORY$/org/scala-lang/scala-library/2.7.7/scala-library-2.7.7.jar" />
</array>
</option>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
<sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" exported="" name="Maven: org.scala-lang:scala-library:2.7.7" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.scalatest:scalatest:1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.4" level="project" />
<orderEntry type="library" exported="" name="Maven: org.springframework:spring-core:3.0.2.RELEASE" level="project" />
<orderEntry type="library" exported="" name="Maven: org.springframework:spring-asm:3.0.2.RELEASE" level="project" />
<orderEntry type="library" exported="" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />

62
pom.xml

@ -13,6 +13,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.7.7</scala.version>
</properties>
<issueManagement>
@ -41,7 +42,7 @@
<executions>
<execution>
<id>javadoc</id>
<phase>process-sources</phase>
<phase>install</phase>
<goals>
<goal>javadoc</goal>
</goals>
@ -70,7 +71,38 @@
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<includes>
<include>**/*.scala</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<reportFormat>plain</reportFormat>
<includes>
<include>**/*Spec.class</include>
</includes>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
@ -82,7 +114,34 @@
</resources>
</build>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -100,4 +159,5 @@
<version>3.0.2.RELEASE</version>
</dependency>
</dependencies>
</project>

4
src/main/java/net/abhinavsarkar/spelhelper/ImplicitMethodResolver.java

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

13
src/test/java/net/abhinavsarkar/spelhelper/Functions.java

@ -0,0 +1,13 @@
package net.abhinavsarkar.spelhelper;
public final class Functions {
public static String test(String str) {
return str;
}
@Override
public boolean equals(Object o) {
return o instanceof Functions;
}
}

43
src/test/java/net/abhinavsarkar/spelhelper/SpelHelperTest.java

@ -1,43 +0,0 @@
package net.abhinavsarkar.spelhelper;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
public class SpelHelperTest {
@Test
public void testRegisteredFunction() {
Assert.assertEquals(
Arrays.asList("abhinav", "mini", "dan"),
new SpelHelper().evalExpression(
"#list('abhinav','mini','dan')", new Object(), List.class));
}
@Test
public void testImplicitMethod() {
Assert.assertEquals(
Arrays.asList("abhinav", "dan", "mini"),
new SpelHelper().evalExpression(
"#list('abhinav','mini','dan').sorted", new Object(), List.class));
}
public static final class ConstructorTest {
@Override
public boolean equals(final Object o) {
return o instanceof ConstructorTest;
}
}
@Test
public void testImplicitConstructor() {
Assert.assertEquals(
new ConstructorTest(),
new SpelHelper()
.registerConstructorsFromClass(ConstructorTest.class)
.evalExpression("new ConstructorTest()", new Object(), ConstructorTest.class));
}
}

54
src/test/scala/net/abhinavsarkar/spelhelper/SpelHelperSpec.scala

@ -0,0 +1,54 @@
package net.abhinavsarkar.spelhelper
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.Spec
import org.scalatest.junit.ShouldMatchersForJUnit
@RunWith(classOf[JUnitRunner])
class SpelHelperSpec extends Spec with ShouldMatchersForJUnit {
describe("SpelHelper") {
it ("should register and evaluate functions ") {
new SpelHelper()
.registerFunctionsFromClass(classOf[Functions])
.evalExpression(
"#test('check')", new {}, classOf[String]) should equal("check")
}
it ("should register implicit methods ") {
new SpelHelper()
.registerImplicitMethodsFromClass(classOf[Functions])
.lookupImplicitMethod("java.lang.String.test") should equal(
classOf[Functions].getMethod("test", classOf[String]))
}
it ("should register implicit constructors ") {
new SpelHelper()
.registerConstructorsFromClass(classOf[Functions])
.lookupImplicitConstructor("Functions[]") should equal(
classOf[Functions].getConstructor())
}
it ("should evaluate implicit methods ") {
new SpelHelper()
.registerImplicitMethodsFromClass(classOf[Functions])
.evalExpression(
"'check'.test()", new {}, classOf[String]) should equal("check")
}
it ("should evaluate implicit constructors ") {
new SpelHelper()
.registerConstructorsFromClass(classOf[Functions])
.evalExpression(
"new Functions()", new {}, classOf[Functions]) should equal(new Functions)
}
it ("should evaluate implicit properties ") {
new SpelHelper().evalExpression(
"'abc'.hashCode", new {}, classOf[int]) should equal("abc".hashCode)
}
}
}
Loading…
Cancel
Save