added Scalatest spec. related changes in pom
parent
6a3ae6ac23
commit
322d33358f
|
@ -2,8 +2,8 @@
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||||
|
<classpathentry kind="src" path="src/test/scala"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<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">
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
@ -7,10 +19,14 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" />
|
<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/main/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/scala" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<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" scope="TEST" name="Maven: junit:junit:4.4" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
75
pom.xml
75
pom.xml
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<scala.version>2.7.7</scala.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -25,10 +26,80 @@
|
||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</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>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-report-plugin</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report-only</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</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>
|
<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>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -36,5 +107,5 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class Just<T> extends Maybe<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return value.toString();
|
return "Just(" + value.toString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package net.abhinavsarkar.nulllessj;
|
package net.abhinavsarkar.nulllessj;
|
||||||
|
|
||||||
import static net.abhinavsarkar.nulllessj.Just.just;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import static net.abhinavsarkar.nulllessj.Just.just;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A container class for representing a value which 'maybe' present.
|
* A container class for representing a value which 'maybe' present.
|
||||||
* This is an abstract class with two concrete subclasses: {@link Just}
|
* This is an abstract class with two concrete subclasses: {@link Just}
|
||||||
|
@ -130,7 +130,8 @@ public abstract class Maybe<T> {
|
||||||
*
|
*
|
||||||
* @see Maybe#maybe
|
* @see Maybe#maybe
|
||||||
*/
|
*/
|
||||||
public <V> Maybe<V> callIfSomething(final ContextualCallable<T,V> callable) {
|
public <V> Maybe<V> callIfSomething(
|
||||||
|
final ContextualCallable<? super T,V> callable) {
|
||||||
if (isSomething()) {
|
if (isSomething()) {
|
||||||
callable.setContext(get());
|
callable.setContext(get());
|
||||||
try {
|
try {
|
||||||
|
@ -190,7 +191,8 @@ public abstract class Maybe<T> {
|
||||||
*
|
*
|
||||||
* @throws RuntimeException See the description.
|
* @throws RuntimeException See the description.
|
||||||
*/
|
*/
|
||||||
public void runIfSomething(final ContextualRunnable<T> runnable) {
|
public void runIfSomething(
|
||||||
|
final ContextualRunnable<? super T> runnable) {
|
||||||
if (isSomething()) {
|
if (isSomething()) {
|
||||||
runnable.setContext(get());
|
runnable.setContext(get());
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,126 @@
|
||||||
|
package net.abhinavsarkar.nulllessj
|
||||||
|
|
||||||
|
import org.scalatest.WordSpec
|
||||||
|
import org.scalatest.junit.{ShouldMatchersForJUnit,JUnitRunner}
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import java.util.concurrent.Callable
|
||||||
|
import java.lang.String
|
||||||
|
|
||||||
|
@RunWith(classOf[JUnitRunner])
|
||||||
|
class NulllessjSpec extends WordSpec with ShouldMatchersForJUnit {
|
||||||
|
|
||||||
|
"Nothing" should {
|
||||||
|
"return true for isNothing " in {
|
||||||
|
(new Nothing() isNothing) should be (true)
|
||||||
|
}
|
||||||
|
"return false for isSomething " in {
|
||||||
|
(new Nothing() isSomething) should be (false)
|
||||||
|
}
|
||||||
|
"have same hashcode for all instances " in {
|
||||||
|
(new Nothing() hashCode) should be (new Nothing() hashCode)
|
||||||
|
}
|
||||||
|
"have all instances equal " in {
|
||||||
|
(new Nothing) should be (new Nothing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"Nothing" when {
|
||||||
|
"getting value from it" should {
|
||||||
|
"throw NothingException " in {
|
||||||
|
evaluating { (new Nothing) get } should produce [NothingException]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"getting value from it with default value" should {
|
||||||
|
"return the default value " in {
|
||||||
|
((new Nothing) getOrElse "a") should be ("a")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"Just" should {
|
||||||
|
"return false for isNothing " in {
|
||||||
|
(new Just(new {}) isNothing) should be (false)
|
||||||
|
}
|
||||||
|
"return true for isSomething " in {
|
||||||
|
(new Just(new {}) isSomething) should be (true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"Just" when {
|
||||||
|
"created with a null value" should {
|
||||||
|
"throw NothingException " in {
|
||||||
|
evaluating { new Just(null) } should produce [NothingException]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"getting value from it" should {
|
||||||
|
"return the wrapped value " in {
|
||||||
|
(new Just("a") get) should be ("a")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"getting value from it with default value" should {
|
||||||
|
"return the wrapped value " in {
|
||||||
|
(new Just("a") getOrElse "b") should be ("a")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val callable = new Callable[String] { def call() = "abc" }
|
||||||
|
val runnable = new Runnable { def run { throw new RuntimeException } }
|
||||||
|
val contextualCallable = new ContextualCallable[Object, String] {
|
||||||
|
def call() = "abc"
|
||||||
|
}
|
||||||
|
val contextualRunnable = new ContextualRunnable[Object] {
|
||||||
|
def run { throw new RuntimeException }
|
||||||
|
}
|
||||||
|
|
||||||
|
"Maybe" when {
|
||||||
|
"created with a null value" should {
|
||||||
|
"return a Nothing " in {
|
||||||
|
Maybe.maybe(null).getClass should be (classOf[Nothing[_]])
|
||||||
|
}
|
||||||
|
"have 'NONE' kind " in {
|
||||||
|
Maybe.maybe(null).kind should be (Maybe.MaybeKind.NONE)
|
||||||
|
}
|
||||||
|
"call the callable in 'callIfNothing' method " in {
|
||||||
|
Maybe.maybe(null).callIfNothing(callable).get should be ("abc")
|
||||||
|
}
|
||||||
|
"run the runnable in 'runIfNothing' method " in {
|
||||||
|
evaluating {
|
||||||
|
Maybe.maybe(null).runIfNothing(runnable)} should
|
||||||
|
produce [RuntimeException]
|
||||||
|
}
|
||||||
|
"not call the callable in 'callIfSomething' method " in {
|
||||||
|
evaluating { Maybe.maybe(null)
|
||||||
|
.callIfSomething(contextualCallable).get } should
|
||||||
|
produce [NothingException]
|
||||||
|
}
|
||||||
|
"not run the runnable in 'runIfSomething' method " in {
|
||||||
|
Maybe.maybe(null).runIfSomething(contextualRunnable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"created with a non-null value" should {
|
||||||
|
"return a Just " in {
|
||||||
|
Maybe.maybe(new {}).getClass should be (classOf[Just[_]])
|
||||||
|
}
|
||||||
|
"have 'SOME' kind " in {
|
||||||
|
Maybe.maybe(new {}).kind should be (Maybe.MaybeKind.SOME)
|
||||||
|
}
|
||||||
|
"not call the callable in 'callIfNothing' method " in {
|
||||||
|
evaluating {
|
||||||
|
Maybe.maybe(new {}).callIfNothing(callable).get } should
|
||||||
|
produce [NothingException]
|
||||||
|
}
|
||||||
|
"not run the runnable in 'runIfNothing' method " in {
|
||||||
|
Maybe.maybe(new {}).runIfNothing(runnable)
|
||||||
|
}
|
||||||
|
"call the callable in 'callIfSomething' method " in {
|
||||||
|
Maybe.maybe(new {})
|
||||||
|
.callIfSomething(contextualCallable).get should be ("abc")
|
||||||
|
}
|
||||||
|
"run the runnable in 'runIfSomething' method " in {
|
||||||
|
evaluating { Maybe.maybe(new {})
|
||||||
|
.runIfSomething(contextualRunnable) } should
|
||||||
|
produce [RuntimeException]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue