From 59d3b909e881548e373541882e9290a3a8c8d257 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Mon, 23 Jan 2017 09:04:52 +0100 Subject: [PATCH] Unit test example --- SpringJava/Gradle/build.gradle | 2 +- .../impl/AdDescriptionRevisionServiceShould.java | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 SpringJava/Gradle/spring-jpa-services/src/test/java/de/spring/example/services/impl/AdDescriptionRevisionServiceShould.java diff --git a/SpringJava/Gradle/build.gradle b/SpringJava/Gradle/build.gradle index f318647..523055d 100644 --- a/SpringJava/Gradle/build.gradle +++ b/SpringJava/Gradle/build.gradle @@ -5,7 +5,7 @@ allprojects { // You could use your gradle 'BOM' file in this way: - // apply from: 'http://artifactory:8888/artifactory/libs-snapshot-local/build-BOM-1.0-SNAPSHOT.gradle + // apply from: 'http://artifactory/artifactory/libs-snapshot-local/build-BOM-1.0-SNAPSHOT.gradle apply from: "$rootProject.projectDir/build-BOM-1.0-SNAPSHOT.gradle" } diff --git a/SpringJava/Gradle/spring-jpa-services/src/test/java/de/spring/example/services/impl/AdDescriptionRevisionServiceShould.java b/SpringJava/Gradle/spring-jpa-services/src/test/java/de/spring/example/services/impl/AdDescriptionRevisionServiceShould.java new file mode 100644 index 0000000..ce46ada --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-services/src/test/java/de/spring/example/services/impl/AdDescriptionRevisionServiceShould.java @@ -0,0 +1,37 @@ +package de.spring.example.services.impl; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.history.Revision; + +import de.spring.example.persistence.domain.AdDescription; +import de.spring.example.persistence.repository.AdDescriptionRepository; + +public class AdDescriptionRevisionServiceShould { + + @Test + public void test() { + AdDescriptionRepository adDescriptionRepository = mock(AdDescriptionRepository.class); + AdDescriptionRevisionServiceImpl adDescriptionRevisionService = new AdDescriptionRevisionServiceImpl(); + adDescriptionRevisionService.setRepository(adDescriptionRepository); + List> adRevisions = new ArrayList<>(); + Pageable pageRequest = new PageRequest(0, 1); + Page> page = new PageImpl<>(adRevisions); + + given(adDescriptionRepository.findRevisions(1L, pageRequest)).willReturn(page); + + assertThat(adDescriptionRevisionService.findRevisions(1L, pageRequest), is(page)); + } + +} -- 2.1.4