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

Renaming Criteria to Preferences

parent 9bc229b0
package org.craftsrecords.talkadvisor.recommendation.api;
import org.craftsrecords.talkadvisor.recommendation.Recommendation;
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria;
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences;
import javax.annotation.Nonnull;
@FunctionalInterface
public interface RecommendTalksForTopic {
@Nonnull
Recommendation getRecommendation(@Nonnull Criteria criteria);
Recommendation getRecommendation(@Nonnull Preferences preferences);
}
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.spi;
import org.craftsrecords.talkadvisor.recommendation.criteria.Topic;
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic;
import org.craftsrecords.talkadvisor.recommendation.talk.Talk;
import javax.annotation.Nonnull;
......
package org.craftsrecords.talkadvisor.recommendation
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalksForTopic
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences
import org.craftsrecords.talkadvisor.recommendation.spi.Recommendations
import org.craftsrecords.talkadvisor.recommendation.spi.SearchTalks
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
class TalksAdvisor(private val searchTalks: SearchTalks, private val recommendations: Recommendations) : RecommendTalksForTopic {
override fun getRecommendation(criteria: Criteria): Recommendation {
val talks = getTalksSatisfying(criteria)
override fun getRecommendation(preferences: Preferences): Recommendation {
val talks = getTalksSatisfying(preferences)
val recommendation = Recommendation(talks = talks)
recommendations.save(recommendation)
return recommendation
}
private fun getTalksSatisfying(criteria: Criteria): Set<Talk> {
return searchTalks.forTopic(criteria.topic)
.filter { criteria.talksFormats.contains(it.format) }
private fun getTalksSatisfying(preferences: Preferences): Set<Talk> {
return searchTalks.forTopic(preferences.topic)
.filter { preferences.talksFormats.contains(it.format) }
.toSet()
}
}
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.criteria
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.talkadvisor.recommendation.criteria
package org.craftsrecords.talkadvisor.recommendation.preferences
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
class Criteria(val topic: Topic, talksFormats: Set<TalkFormat>) {
class Preferences(val topic: Topic, talksFormats: Set<TalkFormat>) {
val talksFormats: Set<TalkFormat> = talksFormats.toSet()
}
\ No newline at end of file
package org.craftsrecords.talkadvisor.recommendation.preferences
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.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.talkadvisor.recommendation.criteria.Topic
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic
import org.craftsrecords.talkadvisor.recommendation.spi.SearchTalks
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
import java.time.Duration
......
package org.craftsrecords.talkadvisor.recommendation.stepdefs;
import cucumber.api.java8.En;
import org.craftsrecords.talkadvisor.recommendation.criteria.Topic;
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic;
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat;
import java.util.Set;
import static java.util.Collections.singleton;
public class CriteriaStepdefs implements En {
public CriteriaStepdefs(TestContext testContext) {
public class PreferencesStepdefs implements En {
public PreferencesStepdefs(TestContext testContext) {
Given("^a guest user who wants to learn (.+)",
(String topicName) -> testContext.setRequestedTopic(new Topic(topicName)));
Given("^he has only time to watch (.+) talks$",
......
......@@ -4,7 +4,7 @@ import cucumber.api.java8.En;
import kotlin.ranges.ClosedRange;
import org.craftsrecords.talkadvisor.recommendation.Recommendation;
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalksForTopic;
import org.craftsrecords.talkadvisor.recommendation.criteria.Criteria;
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences;
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat;
import java.time.Duration;
......@@ -18,8 +18,8 @@ public class RecommendationStepdefs implements En {
RecommendTalksForTopic recommendTalksForTopic) {
When("^he asks for the related talks$",
() -> {
Criteria criteria = createCriteriaFrom(testContext);
Recommendation recommendation = recommendTalksForTopic.getRecommendation(criteria);
Preferences preferences = createCriteriaFrom(testContext);
Recommendation recommendation = recommendTalksForTopic.getRecommendation(preferences);
testContext.setRecommendationResult(recommendation);
});
Then("^talkadvisor recommends some talks$", () -> {
......@@ -41,7 +41,7 @@ public class RecommendationStepdefs implements En {
});
}
private Criteria createCriteriaFrom(TestContext testContext) {
return new Criteria(testContext.getRequestedTopic(), testContext.getRequestedTalksFormats());
private Preferences createCriteriaFrom(TestContext testContext) {
return new Preferences(testContext.getRequestedTopic(), testContext.getRequestedTalksFormats());
}
}
package org.craftsrecords.talkadvisor.recommendation.criteria
package org.craftsrecords.talkadvisor.recommendation.preferences
import org.assertj.core.api.Assertions.assertThat
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat.CONFERENCE
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat.QUICKIE
import org.junit.jupiter.api.Test
internal class CriteriaTest {
internal class PreferencesTest {
@Test
fun `should store a copy of the talks formats`() {
val talksFormats = mutableSetOf(CONFERENCE)
val criteria = Criteria(Topic("ddd"), talksFormats)
val criteria = Preferences(Topic("ddd"), talksFormats)
talksFormats.add(QUICKIE)
......
package org.craftsrecords.talkadvisor.recommendation.criteria
package org.craftsrecords.talkadvisor.recommendation.preferences
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.Test
......
package org.craftsrecords.talkadvisor.recommendation.stepdefs
import org.craftsrecords.talkadvisor.recommendation.Recommendation
import org.craftsrecords.talkadvisor.recommendation.criteria.Topic
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
class TestContext {
......
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