From 0c1ef3ab4f352445df3c1ebf87fe9eac2f78df41 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 12 Jan 2017 14:59:11 +0300 Subject: tests refactoring --- juick-server/build.gradle | 11 +++++ .../juick/configuration/MockDataConfiguration.java | 51 ++++++++++++++++++++++ .../test/java/com/juick/tests/util/MockUtils.java | 33 ++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java create mode 100644 juick-server/src/test/java/com/juick/tests/util/MockUtils.java (limited to 'juick-server') diff --git a/juick-server/build.gradle b/juick-server/build.gradle index ee77b572..2c140b12 100644 --- a/juick-server/build.gradle +++ b/juick-server/build.gradle @@ -62,3 +62,14 @@ compileJava.options.encoding = 'UTF-8' configurations { all*.exclude module: 'commons-logging' } + +configurations { + testArtifacts.extendsFrom testRuntime +} +task testJar(type: Jar) { + classifier "test" + from sourceSets.test.output +} +artifacts { + testArtifacts testJar +} diff --git a/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java b/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java new file mode 100644 index 00000000..be72f6ca --- /dev/null +++ b/juick-server/src/test/java/com/juick/configuration/MockDataConfiguration.java @@ -0,0 +1,51 @@ +package com.juick.configuration; + +import com.juick.service.*; +import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; + +/** + * Created by vitalyster on 12.01.2017. + */ +public class MockDataConfiguration { + @Bean + MessagesService messagesService() { + return Mockito.mock(MessagesService.class); + } + @Bean + UserService userService() { + return Mockito.mock(UserService.class); + } + @Bean + TagService tagService() { + return Mockito.mock(TagService.class); + } + @Bean + PushQueriesService pushQueriesService() { + return Mockito.mock(PushQueriesService.class); + } + @Bean + SubscriptionService subscriptionService() { + return Mockito.mock(SubscriptionService.class); + } + @Bean + PMQueriesService pmQueriesService() { + return Mockito.mock(PMQueriesService.class); + } + @Bean + TelegramService telegramService() { + return Mockito.mock(TelegramService.class); + } + @Bean + AdsService adsService() { + return Mockito.mock(AdsService.class); + } + @Bean + CrosspostService crosspostService() { + return Mockito.mock(CrosspostService.class); + } + @Bean + EmailService emailService() { + return Mockito.mock(EmailService.class); + } +} diff --git a/juick-server/src/test/java/com/juick/tests/util/MockUtils.java b/juick-server/src/test/java/com/juick/tests/util/MockUtils.java new file mode 100644 index 00000000..c67b26ef --- /dev/null +++ b/juick-server/src/test/java/com/juick/tests/util/MockUtils.java @@ -0,0 +1,33 @@ +package com.juick.tests.util; + +import com.juick.Message; +import com.juick.User; +import org.apache.commons.lang3.RandomStringUtils; + +import java.util.Date; + +/** + * Created by vitalyster on 12.01.2017. + */ +public class MockUtils { + public static Message mockMessage(Integer mid, final User user, final String messageText) { + Message msg = new Message(); + + msg.setMid(mid); + msg.setUser(user); + msg.setText(messageText == null ? RandomStringUtils.randomAlphanumeric(24) : messageText); + msg.setDate(new Date()); + return msg; + } + + public static User mockUser(final int uid, final String name, final String password) { + User user = new User(); + + user.setName(name); + user.setUid(uid); + user.setCredentials(password); + user.setBanned(false); + + return user; + } +} -- cgit v1.2.3