mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-06 05:31:41 +02:00
Go to notification blacklist, allow an app if blacklisted, than configure it's behavior with the menu icon on the right hand side. Should be pretty much self explanatory. Database Scheme raised to 20
109 lines
5.3 KiB
Java
109 lines
5.3 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.NotificationFilterActivity;
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilter;
|
|
import nodomain.freeyourgadget.gadgetbridge.test.TestBase;
|
|
import org.junit.Test;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
public class NotificationListenerTest extends TestBase {
|
|
|
|
private NotificationListener mNotificationListener;
|
|
private List<String> wordList = Arrays.asList("Hello", "world", "test");
|
|
|
|
@Override
|
|
public void setUp() throws Exception {
|
|
super.setUp();
|
|
mNotificationListener = new NotificationListener();
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestBlacklistFindAnyWord_WordFound_MustReturnFalse() {
|
|
String body = "Hello world this is a test";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_BLACKLIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ANY);
|
|
assertFalse(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestWhitelistFindAnyWord_WordFound_MustReturnTrue() {
|
|
String body = "Hello world this is a test";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_WHITELIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ANY);
|
|
assertTrue(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestBlacklistFindAllWords_WordsFound_MustReturnFalse() {
|
|
String body = "Hello world this is a test";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_BLACKLIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ALL);
|
|
assertFalse(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestWhitelistFindAllWords_WordsFound_MustReturnTrue() {
|
|
String body = "Hello world this is a test";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_WHITELIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ALL);
|
|
assertTrue(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestBlacklistFindAnyWord_WordNotFound_MustReturnTrue() {
|
|
String body = "Hallo Welt das ist ein Versuch";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_BLACKLIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ANY);
|
|
assertTrue(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestWhitelistFindAnyWord_WordNotFound_MustReturnFalse() {
|
|
String body = "Hallo Welt das ist ein Versuch";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_WHITELIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ANY);
|
|
assertFalse(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestBlacklistFindAllWords_WordNotFound_MustReturnTrue() {
|
|
String body = "Hallo Welt das ist ein Versuch";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_BLACKLIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ALL);
|
|
assertTrue(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestWhitelistFindAllWords_WordNotFound_MustReturnFalse() {
|
|
String body = "Hallo Welt das ist ein Versuch";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_WHITELIST);
|
|
filter.setNotificationFilterSubMode(NotificationFilterActivity.NOTIFICATION_FILTER_SUBMODE_ALL);
|
|
assertFalse(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
}
|
|
|
|
@Test
|
|
public void shouldContinueAfterFilter_TestFilterNone_MustReturnTrue() {
|
|
String body = "A text without a meaning";
|
|
NotificationFilter filter = new NotificationFilter();
|
|
filter.setNotificationFilterMode(NotificationFilterActivity.NOTIFICATION_FILTER_MODE_NONE);
|
|
assertTrue(mNotificationListener.shouldContinueAfterFilter(body, wordList, filter));
|
|
}
|
|
} |