mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 12:11:59 +00:00
Merge pull request #523 from nextcloud/unit-tests
test: added unit tests for the TextMatchers utility class.
This commit is contained in:
commit
f6c3c51e2c
@ -22,12 +22,13 @@
|
||||
|
||||
package com.nextcloud.talk.utils;
|
||||
|
||||
import android.util.Patterns;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
import com.vanniktech.emoji.EmojiInformation;
|
||||
import com.vanniktech.emoji.EmojiUtils;
|
||||
|
||||
import androidx.core.util.PatternsCompat;
|
||||
import eu.medsea.mimeutil.MimeUtil;
|
||||
import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
|
||||
import eu.medsea.mimeutil.detector.MagicMimeMimeDetector;
|
||||
@ -44,7 +45,7 @@ public final class TextMatchers {
|
||||
|
||||
public static ChatMessage.MessageType getMessageTypeFromString(@NonNull final String text) {
|
||||
List<String> links = new ArrayList<>();
|
||||
Matcher m = Patterns.WEB_URL.matcher(text);
|
||||
Matcher m = PatternsCompat.WEB_URL.matcher(text);
|
||||
while (m.find()) {
|
||||
String url = m.group();
|
||||
links.add(url);
|
||||
|
@ -1,18 +0,0 @@
|
||||
package com.nextcloud.talk;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void additionIsCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
package com.nextcloud.talk.utils;
|
||||
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TextMatchersTest {
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_regularTextGiven_regularTextMessageTypeReturned() {
|
||||
String simpleMessageText = "Hello world! Have a cookie!";
|
||||
String messageContainingLink = "Hello https://nextcloud.com! Have a good day";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(simpleMessageText));
|
||||
assertEquals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(messageContainingLink));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_singleUrlTextGiven_singleLinkMessageTypeReturned() {
|
||||
String simpleUrlText = "https://nextcloud.com/";
|
||||
String complexUrlText = "https://docs.nextcloud.com/server/15/admin_manual/#target-audience";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(simpleUrlText));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(complexUrlText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_imageLinkGiven_singleLinkImageMessageReturned() {
|
||||
String simpleImageText = "https://nextcloud.com/image.jpg";
|
||||
String complexImageUrlText = "https://nextcloud.com/wp-content/themes/next/assets/img/features/mobileDesktop.png?x22777";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(simpleImageText));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(complexImageUrlText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_gifLinkGiven_gifMessageTypeReturned() {
|
||||
String gifImageText = "https://nextcloud.com/funny.gif";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_GIF_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(gifImageText));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_audioLinkGiven_audioMessageTypeReturned() {
|
||||
String wavLink = "https://nextcloud.com/message.wav";
|
||||
String mp3Link = "https://nextcloud.com/message.mp3";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(wavLink));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(mp3Link));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_videoLinkGiven_videoMessageTypeReturned() {
|
||||
String mp4Link = "https://nextcloud.com/message.mp4";
|
||||
String flvLink = "https://nextcloud.com/message.flv";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(mp4Link));
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(flvLink));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_giphyLinkGiven_giphyMessageTypeReturned() {
|
||||
String giphyLink = "https://media.giphy.com/media/11fucLQCTOdvBS/giphy.gif";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_GIPHY_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(giphyLink));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageTypeFromString_tenorLinkGiven_tenorMessageTypeReturned() {
|
||||
String tenorLink = "https://media.tenor.com/images/d98e76e3930cf171cc39e301c9e974af/tenor.gif";
|
||||
|
||||
assertEquals(ChatMessage.MessageType.SINGLE_LINK_TENOR_MESSAGE,
|
||||
TextMatchers.getMessageTypeFromString(tenorLink));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user