From edb8fc9261d5dcf7f54316f8fe33af5ceaf201ad Mon Sep 17 00:00:00 2001 From: davinkevin Date: Mon, 29 Oct 2018 06:51:42 +0100 Subject: [PATCH] refactor(kotlin): migration of the HibernateSearchIndexation to Kotlin --- .../scheduled/HibernateSearchIndexation.java | 22 --------------- .../scheduled/HibernateSearchIndexation.kt | 16 +++++++++++ .../HibernateSearchIndexationTest.java | 27 ------------------ .../HibernateSearchIndexationTest.kt | 28 +++++++++++++++++++ 4 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 backend/src/main/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexation.java create mode 100644 backend/src/main/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexation.kt delete mode 100644 backend/src/test/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexationTest.java create mode 100644 backend/src/test/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexationTest.kt diff --git a/backend/src/main/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexation.java b/backend/src/main/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexation.java deleted file mode 100644 index 56197a0c9..000000000 --- a/backend/src/main/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexation.java +++ /dev/null @@ -1,22 +0,0 @@ -package lan.dk.podcastserver.scheduled; - -import lan.dk.podcastserver.business.ItemBusiness; -import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -/** - * Created by kevin on 22/08/2014. - */ -@Component -@RequiredArgsConstructor -public class HibernateSearchIndexation { - - private final ItemBusiness itemBusiness; - - @Scheduled(fixedDelay = 86400000) - public void refreshIndex() throws InterruptedException { - itemBusiness.reindex(); - } - -} diff --git a/backend/src/main/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexation.kt b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexation.kt new file mode 100644 index 000000000..e26607a3f --- /dev/null +++ b/backend/src/main/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexation.kt @@ -0,0 +1,16 @@ +package com.github.davinkevin.podcastserver.scheduled + +import lan.dk.podcastserver.business.ItemBusiness +import org.springframework.scheduling.annotation.Scheduled +import org.springframework.stereotype.Component + +/** + * Created by kevin on 22/08/2014. + */ +@Component +class HibernateSearchIndexation(private val itemBusiness: ItemBusiness) { + + @Scheduled(fixedDelay = 86400000) + fun refreshIndex() = itemBusiness.reindex() + +} diff --git a/backend/src/test/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexationTest.java b/backend/src/test/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexationTest.java deleted file mode 100644 index 892629c0b..000000000 --- a/backend/src/test/java/lan/dk/podcastserver/scheduled/HibernateSearchIndexationTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package lan.dk.podcastserver.scheduled; - -import lan.dk.podcastserver.business.ItemBusiness; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * Created by kevin on 17/08/15 for Podcast Server - */ -@RunWith(MockitoJUnitRunner.class) -public class HibernateSearchIndexationTest { - - @Mock ItemBusiness itemBusiness; - @InjectMocks HibernateSearchIndexation hibernateSearchIndexation; - - @Test - public void should_refresh_index() throws InterruptedException { - /* When */ hibernateSearchIndexation.refreshIndex(); - /* Then */ verify(itemBusiness, times(1)).reindex(); - } -} diff --git a/backend/src/test/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexationTest.kt b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexationTest.kt new file mode 100644 index 000000000..6e436261b --- /dev/null +++ b/backend/src/test/kotlin/com/github/davinkevin/podcastserver/scheduled/HibernateSearchIndexationTest.kt @@ -0,0 +1,28 @@ +package com.github.davinkevin.podcastserver.scheduled + +import lan.dk.podcastserver.business.ItemBusiness +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.Mockito.times +import org.mockito.Mockito.verify +import org.mockito.junit.jupiter.MockitoExtension + +/** + * Created by kevin on 17/08/15 for Podcast Server + */ +@ExtendWith(MockitoExtension::class) +class HibernateSearchIndexationTest { + + @Mock lateinit var itemBusiness: ItemBusiness + @InjectMocks lateinit var hibernateSearchIndexation: HibernateSearchIndexation + + @Test + fun should_refresh_index() { + /* When */ + hibernateSearchIndexation.refreshIndex() + /* Then */ + verify(itemBusiness, times(1)).reindex() + } +}