Skip to content

Instantly share code, notes, and snippets.

@DomainService
class TalksAdvisor(private val searchTalks: SearchTalks,
private val recommendations: Recommendations,
private val profiles: Profiles) : RecommendTalks {
override fun to(userId: String): Recommendation {
val profile = profiles.fetch(userId) ?: throw ProfileNotFoundException(userId)
return recommendTalksSatisfying(profile.preferences)
}
@Aggregate
class Recommendation(val id: UUID = UUID.randomUUID(), val criteria: Criteria, talks: Set<Talk>) {
val talks: Set<Talk>
init {
checkCriteriaTalkFormatsCorrespondToTheTalksOne(talks)
this.talks = talks.toSet()
}
@beyondxscratch
beyondxscratch / CreateProfile.kt
Last active August 9, 2020 23:00
CreateProfile.kt
package org.craftsrecords.talkadvisor.recommendation.api
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences
import org.craftsrecords.talkadvisor.recommendation.profile.Profile
@FunctionalInterface
interface CreateProfile {
fun forUserWithPreferences(userId: String, preferences: Preferences): Profile
}
@beyondxscratch
beyondxscratch / pom.xml
Last active August 9, 2020 19:47
Maven Enforcer Plugin to seal a domain in Hexagonal Architecture
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
/* Before */
//Check if the talk is related to a topic
if(talk.title.contains("topic")){}
//Check that the recommendation has some talks related to the topic
if((recommendation.talks.map { it.title }.anyMatch{ it.contains("topic") }){}
/*After cleaning the code*/
if(talk.isRelatedTo("topic")){}
if((recommendation.hasTalksRelatedTo("topic")){}
//Talk is related to the topic
assertThat(talk.title).contains("topic")
//All recommended talks are related to the topic
assertThat(recommendation.talks.map { it.title }).allMatch{ it.contains("topic") }
<properties>
<cucumber.version>4.2.3</cucumber.version>
<assertj-core.version>3.11.1</assertj-core.version>
</properties>
...
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
@RunWith(Cucumber::class)
@CucumberOptions(strict = true, plugin = ["pretty", "json:target/cucumber/recommendation.json"], features = ["classpath:features/recommending-talks.feature"])
class RecommendationFunctionalTests
cucumber.api.java.ObjectFactory=org.craftsrecords.talkadvisor.CustomPicoFactory
class CustomPicoFactory : PicoFactory() {
init {
addClass(TestContext::class.java)
addClass(TalksAdvisor::class.java)
addClass(HardCodedTalksSearcher::class.java)
addClass(InMemoryRecommendations::class.java)
addClass(ProfileCreator::class.java)
addClass(InMemoryProfiles::class.java)
}
}