RecommendationTest.kt 1.99 KB
Newer Older
1 2
package org.craftsrecords.talkadvisor.recommendation

Julien Topçu's avatar
Julien Topçu committed
3
import org.assertj.core.api.Assertions.assertThat
Julien Topçu's avatar
Julien Topçu committed
4
import org.craftsrecords.talkadvisor.recommendation.criteria.createCriteria
Julien Topçu's avatar
Julien Topçu committed
5 6
import org.craftsrecords.talkadvisor.recommendation.talk.createTalk
import org.craftsrecords.talkadvisor.recommendation.talk.createTalks
7
import org.junit.jupiter.api.Test
Julien Topçu's avatar
Julien Topçu committed
8
import java.util.*
9 10 11

internal class RecommendationTest {
    @Test
Julien Topçu's avatar
Julien Topçu committed
12 13
    fun `should create a recommendation`() {
        val talks = createTalks()
14
        val criteria = createCriteria()
Julien Topçu's avatar
Julien Topçu committed
15

16
        val recommendation = Recommendation(criteria = criteria, talks = talks)
Julien Topçu's avatar
Julien Topçu committed
17 18 19

        assertThat(recommendation.id).isNotNull()
        assertThat(recommendation.talks).isEqualTo(talks)
20
        assertThat(recommendation.criteria).isEqualTo(criteria)
Julien Topçu's avatar
Julien Topçu committed
21 22 23 24 25 26
    }

    @Test
    fun `should store a copy of the talks`() {

        val talks = createTalks().toMutableSet()
27
        val recommendation = Recommendation(criteria = createCriteria(), talks = talks)
Julien Topçu's avatar
Julien Topçu committed
28 29 30 31 32 33 34 35 36 37 38
        val newTalk = createTalk()

        talks.add(newTalk)

        assertThat(recommendation.talks).doesNotContain(newTalk)
    }

    @Test
    fun `should satisfy entity equality`() {
        val id = UUID.randomUUID()

39 40
        val recommendation1 = Recommendation(id, criteria = createCriteria(), talks = createTalks())
        val recommendation2 = Recommendation(id, criteria = createCriteria(), talks = createTalks())
Julien Topçu's avatar
Julien Topçu committed
41 42 43 44 45 46 47 48 49

        assertThat(recommendation1).isEqualTo(recommendation2)
        assertThat(recommendation1.hashCode()).isEqualTo(recommendation2.hashCode())
    }

    @Test
    fun `should satisfy entity inequality`() {

        val talks = createTalks()
50
        val criteria = createCriteria()
Julien Topçu's avatar
Julien Topçu committed
51

52 53
        val recommendation1 = Recommendation(criteria = criteria, talks = talks)
        val recommendation2 = Recommendation(criteria = criteria, talks = talks)
Julien Topçu's avatar
Julien Topçu committed
54 55 56

        assertThat(recommendation1).isNotEqualTo(recommendation2)
        assertThat(recommendation1.hashCode()).isNotEqualTo(recommendation2.hashCode())
57
    }
Julien Topçu's avatar
Julien Topçu committed
58

59
}