Skip to content

Commit

Permalink
refactor(kotlin): migration of the FinderSelector to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
davinkevin committed Dec 30, 2018
1 parent 4d16a4d commit a59dc23
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 203 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Podcast-Server

Back-end : [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2030290b1c2145f6878e9ad7811c542e)](https://www.codacy.com/app/davin-kevin/Podcast-Server?utm_source=github.com&utm_medium=referral&utm_content=davinkevin/Podcast-Server&utm_campaign=Badge_Grade) [![Coverage Status](https://coveralls.io/repos/davinkevin/Podcast-Server/badge.svg?branch=master)](https://coveralls.io/r/davinkevin/Podcast-Server?branch=master)

Migration : ![Java stage](https://badgen.net/badge/Java/66%25/orange) ![Kotlin stage](https://badgen.net/badge/Kotlin/34%25/purple)
Migration : ![Java stage](https://badgen.net/badge/Java/65%25/orange) ![Kotlin stage](https://badgen.net/badge/Kotlin/35%25/purple)

Front-end : [![Code Climate](https://codeclimate.com/github/davinkevin/Podcast-Server/badges/gpa.svg)](https://codeclimate.com/github/davinkevin/Podcast-Server)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.davinkevin.podcastserver.business.find

import lan.dk.podcastserver.entity.Podcast
import lan.dk.podcastserver.manager.selector.FinderSelector
import com.github.davinkevin.podcastserver.manager.selector.FinderSelector
import org.springframework.stereotype.Component

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lan.dk.podcastserver.manager.selector
package com.github.davinkevin.podcastserver.manager.selector

import lan.dk.podcastserver.manager.worker.Finder
import lan.dk.podcastserver.manager.worker.noop.NoOpFinder
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.davinkevin.podcastserver.business.find
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import lan.dk.podcastserver.entity.Podcast
import lan.dk.podcastserver.manager.selector.FinderSelector
import com.github.davinkevin.podcastserver.manager.selector.FinderSelector
import lan.dk.podcastserver.manager.worker.Finder
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.github.davinkevin.podcastserver.manager.selector

import com.github.davinkevin.podcastserver.manager.worker.francetv.FranceTvFinder
import com.github.davinkevin.podcastserver.manager.worker.jeuxvideocom.JeuxVideoComFinder
import com.github.davinkevin.podcastserver.manager.worker.sixplay.SixPlayFinder
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.whenever
import lan.dk.podcastserver.manager.worker.beinsports.BeInSportsFinder
import lan.dk.podcastserver.manager.worker.dailymotion.DailymotionFinder
import lan.dk.podcastserver.manager.worker.gulli.GulliFinder
import lan.dk.podcastserver.manager.worker.itunes.ItunesFinder
import lan.dk.podcastserver.manager.worker.mycanal.MyCanalFinder
import lan.dk.podcastserver.manager.worker.rss.RSSFinder
import lan.dk.podcastserver.manager.worker.tf1replay.TF1ReplayFinder
import lan.dk.podcastserver.manager.worker.youtube.YoutubeFinder
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.stream.Stream
import kotlin.reflect.KClass

/**
* Created by kevin on 08/03/2016 for Podcast Server
*/
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
class FinderSelectorTest {

@Mock lateinit var beInSportsFinder: BeInSportsFinder
@Mock lateinit var dailymotionFinder: DailymotionFinder
@Mock lateinit var franceTvFinder: FranceTvFinder
@Mock lateinit var gulliFinder: GulliFinder
@Mock lateinit var itunesFinder: ItunesFinder
@Mock lateinit var jeuxVideoComFinder: JeuxVideoComFinder
@Mock lateinit var myCanalFinder: MyCanalFinder
@Mock lateinit var rssFinder: RSSFinder
@Mock lateinit var sixPlayFinder: SixPlayFinder
@Mock lateinit var tf1ReplayFinder: TF1ReplayFinder
@Mock lateinit var youtubeFinder: YoutubeFinder

lateinit var finderSelector: FinderSelector

@BeforeEach
fun beforeEach() {
whenever(beInSportsFinder.compatibility(any())).thenCallRealMethod()
whenever(dailymotionFinder.compatibility(any())).thenCallRealMethod()
whenever(franceTvFinder.compatibility(any())).thenCallRealMethod()
whenever(gulliFinder.compatibility(any())).thenCallRealMethod()
whenever(itunesFinder.compatibility(any())).thenCallRealMethod()
whenever(jeuxVideoComFinder.compatibility(any())).thenCallRealMethod()
whenever(myCanalFinder.compatibility(any())).thenCallRealMethod()
whenever(rssFinder.compatibility(any())).thenCallRealMethod()
whenever(sixPlayFinder.compatibility(any())).thenCallRealMethod()
whenever(tf1ReplayFinder.compatibility(any())).thenCallRealMethod()
whenever(youtubeFinder.compatibility(any())).thenCallRealMethod()

finderSelector = FinderSelector(setOf(beInSportsFinder, myCanalFinder, dailymotionFinder, franceTvFinder, gulliFinder, itunesFinder, jeuxVideoComFinder, rssFinder, sixPlayFinder, tf1ReplayFinder, youtubeFinder))
}

@Test
fun `should return noop finder if empty url is send to finder`() {
/* When */
val finder = finderSelector.of("")
/* Then */
assertThat(finder).isEqualTo(FinderSelector.NO_OP_FINDER)
}

@Test
fun `should return noop finder if null url is send to finder`() {
/* When */
val finder = finderSelector.of(null)
/* Then */
assertThat(finder).isEqualTo(FinderSelector.NO_OP_FINDER)
}

@MethodSource("urlToFinderType")
@DisplayName("should return")
@ParameterizedTest(name = "{1} finder for {0}")
fun `should return matching updater`(url: String, type: KClass<*>) {
/* When */
val finderClass = finderSelector.of(url)
/* Then */
assertThat(finderClass).isInstanceOf(type.java)
}

companion object {
@JvmStatic
fun urlToFinderType() =
Stream.of(
Arguments.of("http://www.beinsports.com/france/replay/lexpresso", BeInSportsFinder::class),
Arguments.of("http://www.dailymotion.com/foo/bar", DailymotionFinder::class),
Arguments.of("http://www.france.tv/videos/comment_ca_va_bien.html", FranceTvFinder::class),
Arguments.of("http://replay.gulli.fr/videos/foo/bar", GulliFinder::class),
Arguments.of("https://itunes.apple.com/fr/podcast/cauet-sl%C3%A2che/id1278255446?l=en&mt=2", ItunesFinder::class),
Arguments.of("http://www.jeuxvideo.com/chroniques-video.htm", JeuxVideoComFinder::class),
Arguments.of("http://www.mycanal.fr/c-divertissement/c-le-grand-journal/pid5411-le-grand-journal.html", MyCanalFinder::class),
Arguments.of("http://foo.bar.com/to/rss/file.xml", RSSFinder::class),
Arguments.of("http://www.6play.fr/videos/foo/bar", SixPlayFinder::class),
Arguments.of("http://www.tf1.fr/videos/foo/bar", TF1ReplayFinder::class),
Arguments.of("http://www.youtube.com/channel/UC_ioajefokjFAOI", YoutubeFinder::class)
)
}

}

0 comments on commit a59dc23

Please sign in to comment.