Commit c9637e01 authored by Julien Topçu's avatar Julien Topçu
Browse files

Java interoperability & Initiating domain objects

parent fb0efc20
# TalkAdvisor
Note: Using Java interoperability for cucumber step defs and functional interfaces.
The current cucumber for kotlin for IntelliJ is not really stable and prevent the creation of step defs from the feature file.
Using Java functional interface instead of kotlin ones in order to not get anonymous class expression instead of lambda.
......@@ -69,10 +69,6 @@
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
......@@ -106,25 +102,25 @@
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
......@@ -137,6 +133,38 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
......@@ -179,6 +207,14 @@
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
......@@ -261,6 +297,17 @@
<artifactId>kotlin-stdlib-jdk7</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
......@@ -28,6 +28,7 @@
<!-- but allow kotlin dependencies-->
<include>org.jetbrains.kotlin:*</include>
<include>org.jetbrains:annotations</include>
<include>org.apache.commons:commons-lang3</include>
<!-- and test dependencies-->
<include>*:*:*:*:test</include>
</includes>
......
package org.craftsrecords.talkadvisor.recommendation.api;
import org.craftsrecords.talkadvisor.recommendation.Recommendation;
import org.craftsrecords.talkadvisor.recommendation.Topic;
@FunctionalInterface
public interface RecommendTalksForTopic{
Recommendation getRecommendation(Topic topic);
}
package org.craftsrecords.talkadvisor.recommendation
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalksForTopic
class Recommendation() {
}
package org.craftsrecords.talkadvisor.recommendation
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalksForTopic
class Talk {
}
package org.craftsrecords.talkadvisor.recommendation
import org.apache.commons.lang3.Validate.notBlank
class Topic(name:String){
val name:String = notBlank(name, "Cannot create a topic with a blank name")
}
package org.craftsrecords.steps;
import cucumber.api.java8.En;
import org.craftsrecords.steps.context.TopicToLearn;
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalksForTopic;
public class TalkStepdefs implements En {
public TalkStepdefs(TopicToLearn topicToLearn, RecommendTalksForTopic recommendTalksForTopic) {
When("^he asks for the related talks$",
() -> recommendTalksForTopic.getRecommendation(topicToLearn.getTopic()));
}
}
package org.craftsrecords.steps;
import cucumber.api.java8.En;
import org.craftsrecords.steps.context.TopicToLearn;
public class UserStepdefs implements En {
public UserStepdefs(TopicToLearn topicToLearn) {
Given("^a guest user who wants to learn (.*)", topicToLearn::setTopic);
}
}
package org.craftsrecords.steps.context
import org.craftsrecords.talkadvisor.recommendation.Topic
class TopicToLearn(topic: String){
var topic = Topic(topic)
}
package org.craftsrecords.talkadvisor.recommendation
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Test
internal class TopicTest{
@Test
fun `should not create a test with a blank name`(){
assertThatThrownBy { Topic(" ") }
.isInstanceOf(IllegalArgumentException::class.java)
.hasMessage("Cannot create a topic with a blank name")
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment