From 7aaa3f9a29c280f01c677c918932620be45cdbd7 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Thu, 8 Nov 2018 21:38:27 +0300
Subject: Merge everything into single Spring Boot application
---
.../src/test/java/com/juick/FormatterTest.java | 64 -------
.../src/test/java/com/juick/MessageTest.java | 183 ---------------------
juick-common/src/test/java/com/juick/UserTest.java | 36 ----
.../test/java/com/juick/test/util/MockUtils.java | 59 -------
4 files changed, 342 deletions(-)
delete mode 100644 juick-common/src/test/java/com/juick/FormatterTest.java
delete mode 100644 juick-common/src/test/java/com/juick/MessageTest.java
delete mode 100644 juick-common/src/test/java/com/juick/UserTest.java
delete mode 100644 juick-common/src/test/java/com/juick/test/util/MockUtils.java
(limited to 'juick-common/src/test/java/com/juick')
diff --git a/juick-common/src/test/java/com/juick/FormatterTest.java b/juick-common/src/test/java/com/juick/FormatterTest.java
deleted file mode 100644
index da9f5d26..00000000
--- a/juick-common/src/test/java/com/juick/FormatterTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick;
-
-import com.juick.util.DateFormattersHolder;
-import org.apache.commons.lang3.RandomUtils;
-import org.junit.Test;
-
-import java.time.Instant;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-
-/**
- * Created by aalexeev on 12/7/16.
- */
-public class FormatterTest {
-
- @Test
- public void forAnyDateFormatterShouldReturnNotEmptyString() throws Exception {
- Instant ts = Instant.now();
-
- assertThat(DateFormattersHolder.getMessageFormatterInstance().format(ts), not(isEmptyOrNullString()));
- assertThat(DateFormattersHolder.getRssFormatterInstance().format(ts), not(isEmptyOrNullString()));
-
- ts = Instant.ofEpochMilli(RandomUtils.nextLong(1, Long.MAX_VALUE / 10000));
-
- assertThat(DateFormattersHolder.getMessageFormatterInstance().format(ts), not(isEmptyOrNullString()));
- assertThat(DateFormattersHolder.getRssFormatterInstance().format(ts), not(isEmptyOrNullString()));
- }
-
- @Test
- public void forConcreteDateShouldReturnCorrectString() throws Exception {
- Calendar calendar = GregorianCalendar.getInstance();
-
- calendar.set(2012, 0, 1, 0, 0, 0);
- calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- Date date = calendar.getTime();
-
- assertThat(DateFormattersHolder.getMessageFormatterInstance().format(date.toInstant()), equalTo("2012-01-01 00:00:00"));
- assertThat(DateFormattersHolder.getRssFormatterInstance().format(date.toInstant()), equalTo("Sun, 1 Jan 2012 00:00:00"));
- assertThat(DateFormattersHolder.getHttpDateFormatter().format(date.toInstant()), equalTo("Sun, 01 Jan 2012 00:00:00 GMT"));
- }
-}
diff --git a/juick-common/src/test/java/com/juick/MessageTest.java b/juick-common/src/test/java/com/juick/MessageTest.java
deleted file mode 100644
index 6197f861..00000000
--- a/juick-common/src/test/java/com/juick/MessageTest.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick;
-
-import com.juick.util.MessageUtils;
-import org.apache.commons.lang3.RandomUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
-
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-
-/**
- * Created by aalexeev on 12/7/16.
- */
-public class MessageTest {
-
- @Test
- public void equalsShouldBeReturnCorrectResult() {
- Message message1 = new Message();
-
- Message message2 = new Message();
- message2.setMid(RandomUtils.nextInt());
-
- Message message3 = message1;
-
- assertThat(message1, equalTo(message3));
- assertThat(message3, equalTo(message1));
-
- assertThat(message1, not(equalTo(message2)));
- assertThat(message2, not(equalTo(message1)));
-
- int id = RandomUtils.nextInt();
- message1.setMid(id);
- message2.setMid(id);
-
- id = RandomUtils.nextInt();
- message1.setRid(id);
- message2.setRid(id);
-
- assertThat(message1, equalTo(message2));
- assertThat(message2, equalTo(message1));
-
- message1.setMid(RandomUtils.nextInt());
- message1.setRid(RandomUtils.nextInt());
-
- message2.setMid(RandomUtils.nextInt());
- message2.setRid(RandomUtils.nextInt());
-
- assertThat(message1, not(equalTo(message2)));
- assertThat(message2, not(equalTo(message1)));
- }
-
- @Test
- public void compareShouldBeReturnCorrectResult() {
- Message message1 = new Message();
-
- message1.setMid(RandomUtils.nextInt());
- message1.setRid(RandomUtils.nextInt());
-
- Message message2 = message1;
-
- assertThat(message1.compareTo(message2), equalTo(0));
- assertThat(message2.compareTo(message1), equalTo(0));
-
- Message message3 = new Message();
-
- message3.setMid(message1.getMid());
- message3.setRid(message1.getRid());
-
- assertThat(message1.compareTo(message3), equalTo(0));
- assertThat(message3.compareTo(message1), equalTo(0));
- }
-
- @Test
- public void messageWithGreaterMidShouldBeLessThenMesageWithLessMid() {
- Message message1 = new Message();
-
- message1.setMid(RandomUtils.nextInt());
- message1.setRid(RandomUtils.nextInt());
-
- Message message2 = new Message();
-
- message2.setMid(message1.getMid() + RandomUtils.nextInt(1, 10000));
- message2.setRid(RandomUtils.nextInt());
-
- assertThat(message1.compareTo(message2), equalTo(1));
- assertThat(message2.compareTo(message1), equalTo(-1));
- }
-
- @Test
- public void messageWithGreaterRidAndEqualsMidShouldBeGreaterThenMessageWithLessRid() {
- Message message1 = new Message();
-
- message1.setMid(RandomUtils.nextInt());
- message1.setRid(RandomUtils.nextInt());
-
- Message message2 = new Message();
-
- message2.setMid(message1.getMid());
- message2.setRid(message1.getRid() + + RandomUtils.nextInt(1, 10000));
-
- assertThat(message1.compareTo(message2), equalTo(-1));
- assertThat(message2.compareTo(message1), equalTo(1));
- }
-
- @Test
- public void tagsStringShouldBeEmptyIfNoTags() {
- Message message = new Message();
-
- assertThat(MessageUtils.getTagsString(message), isEmptyString());
-
- message.FriendsOnly = true;
-
- assertThat(MessageUtils.getTagsString(message), isEmptyString());
-
- message.Hidden = true;
- message.ReadOnly = true;
-
- assertThat(MessageUtils.getTagsString(message), isEmptyString());
-
- message.setTags(MessageUtils.parseTags(" "));
-
- assertThat(MessageUtils.getTagsString(message), isEmptyString());
- }
-
- @Test
- public void tagsStringShouldHasNoTagDuplicates() {
- Message message = new Message();
-
- message.setTags(MessageUtils.parseTags("test"));
-
- assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1));
-
- message.setTags(MessageUtils.parseTags("test test"));
-
- assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1));
-
- message.setTags(MessageUtils.parseTags("test test ab test"));
-
- assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1));
- assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*ab"), equalTo(1));
- }
- @Test
- public void markdownContentShouldNotHaveUnescapedReplyNumbersBecauseOfTelegram() {
- Message msg = new Message();
- msg.setMid(1);
- msg.setText("See /303 again");
- assertThat(MessageUtils.formatMarkdownText(msg), is("See [/303](https://juick.com/m/1#303) again"));
- }
- @Test
- public void shouldNotThrowIfUrlContainsIllegalCharacters() {
- String msg = "[te](http://juick.com/)[st](http://juick.com/)";
- assertThat(MessageUtils.stripNonSafeUrls(msg), is(msg));
- }
- @Test
- public void mentionsCount() {
- Message msg = new Message();
- msg.setText("@ugnich go home");
- List mentions = MessageUtils.getMentions(msg);
- assertThat(mentions.size(), is(1));
- assertThat(mentions.get(0), is("@ugnich"));
- msg.setText("And dick is @ugnich@jabber.zp.ua");
- assertThat(MessageUtils.getGlobalMentions(msg).size(), is(1));
- }
-}
diff --git a/juick-common/src/test/java/com/juick/UserTest.java b/juick-common/src/test/java/com/juick/UserTest.java
deleted file mode 100644
index 13331426..00000000
--- a/juick-common/src/test/java/com/juick/UserTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.juick.test.util.MockUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class UserTest {
- @Test
- public void userEqualityTest() throws IOException {
- User ugnich = MockUtils.mockUser(1, "ugnich", "secret");
- String jsonUser = "{\"uid\" : 1, \"uname\": \"ugnich\"}";
- ObjectMapper jsonMapper = new ObjectMapper();
- User jsonUgnich = jsonMapper.readValue(jsonUser, User.class);
- Assert.assertEquals(ugnich, jsonUgnich);
- }
-}
diff --git a/juick-common/src/test/java/com/juick/test/util/MockUtils.java b/juick-common/src/test/java/com/juick/test/util/MockUtils.java
deleted file mode 100644
index 017af4d1..00000000
--- a/juick-common/src/test/java/com/juick/test/util/MockUtils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2008-2017, Juick
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-package com.juick.test.util;
-
-import com.juick.Message;
-import com.juick.User;
-import org.apache.commons.text.RandomStringGenerator;
-
-import java.time.Instant;
-
-/**
- * Created by vitalyster on 12.01.2017.
- */
-public class MockUtils {
- final static RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('a', 'z').build();
- 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 ? generator.generate(24) : messageText);
- msg.setTimestamp(Instant.now());
- return msg;
- }
-
- public static Message mockReply(Integer mid, Integer rid, final User user, Integer replyTo, final String messageText) {
- Message msg = mockMessage(mid, user, messageText);
-
- msg.setRid(rid);
- msg.setReplyto(replyTo);
- 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