Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java

Issue 29819555: Fix libadblockplus-android tests
Patch Set: Fixed indentation issues. Created Aug. 27, 2018, 8:03 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
diff --git a/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java b/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
index c5523b02a8dfd46c5321865688f09b1c71fe9a13..c06495c89f009f21f0980bdc995f81ab4a036cbd 100644
--- a/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
+++ b/adblock-android-tests/src/org/adblockplus/libadblockplus/tests/FilterEngineTest.java
@@ -17,6 +17,9 @@
package org.adblockplus.libadblockplus.tests;
+import android.util.Log;
+
+import org.adblockplus.libadblockplus.BaseFilterEngineTest;
import org.adblockplus.libadblockplus.Filter;
import org.adblockplus.libadblockplus.FilterEngine;
import org.adblockplus.libadblockplus.MockFilterChangeCallback;
@@ -28,6 +31,8 @@ import java.util.List;
public class FilterEngineTest extends BaseFilterEngineTest
{
+ private static final String TAG = FilterEngineTest.class.getSimpleName();
+
@Test
public void testFilterCreation()
{
@@ -46,10 +51,7 @@ public class FilterEngineTest extends BaseFilterEngineTest
@Test
public void testAddRemoveFilters()
{
- while (filterEngine.getListedFilters().size() > 0)
- {
- filterEngine.getListedFilters().get(0).removeFromList();
- }
+ this.removeListedSubscriptions();
assertEquals(0, filterEngine.getListedFilters().size());
Filter filter = filterEngine.getFilter("foo");
@@ -76,12 +78,45 @@ public class FilterEngineTest extends BaseFilterEngineTest
}
@Test
+ public void testAddedSubscriptionIsEnabled()
+ {
+ Subscription subscription = filterEngine.getSubscription("foo");
+ assertFalse(subscription.isDisabled());
+ }
+
+ @Test
+ public void testDisablingSubscriptionDisablesItAndFiresEvent()
+ {
+ Subscription subscription = filterEngine.getSubscription("foo");
+ MockFilterChangeCallback callback = new MockFilterChangeCallback("subscription.disabled", "url","foo");
+ filterEngine.setFilterChangeCallback(callback);
+ assertFalse(subscription.isDisabled());
+ subscription.setDisabled(true);
+ assertEquals(1, callback.getTimesCalled());
+ assertTrue(subscription.isDisabled());
+ filterEngine.removeFilterChangeCallback();
+ }
+
+ @Test
+ public void testEnablingSubscriptionEnablesItAndFiresEvent()
+ {
+ Subscription subscription = filterEngine.getSubscription("foo");
+ assertFalse(subscription.isDisabled());
+ subscription.setDisabled(true);
+ assertTrue(subscription.isDisabled());
+
+ MockFilterChangeCallback callback = new MockFilterChangeCallback("subscription.disabled", "url", "foo");
+ filterEngine.setFilterChangeCallback(callback);
+ subscription.setDisabled(false);
+ assertEquals(1, callback.getTimesCalled());
+ assertFalse(subscription.isDisabled());
+ filterEngine.removeFilterChangeCallback();
+ }
+
+ @Test
public void testAddRemoveSubscriptions()
{
- while (filterEngine.getListedSubscriptions().size() > 0)
- {
- filterEngine.getListedSubscriptions().get(0).removeFromList();
- }
+ this.removeListedSubscriptions();
assertEquals(0, filterEngine.getListedSubscriptions().size());
Subscription subscription = filterEngine.getSubscription("foo");
@@ -324,23 +359,21 @@ public class FilterEngineTest extends BaseFilterEngineTest
}
@Test
- public void testFirstRunFlag()
- {
- assertFalse(filterEngine.isFirstRun());
- }
-
- @Test
public void testSetRemoveFilterChangeCallback()
{
- MockFilterChangeCallback mockFilterChangeCallback = new MockFilterChangeCallback(0);
+ MockFilterChangeCallback callback = new MockFilterChangeCallback("subscription.added", "defaults", "blocking");
- filterEngine.setFilterChangeCallback(mockFilterChangeCallback);
- filterEngine.getFilter("foo").addToList();
- assertEquals(1, mockFilterChangeCallback.getTimesCalled());
+ filterEngine.setFilterChangeCallback(callback);
+ Filter filter = filterEngine.getFilter("foo");
+ assertFalse(filter.isListed());
+ filter.addToList();
+ assertEquals(1, callback.getTimesCalled());
filterEngine.removeFilterChangeCallback();
- filterEngine.getFilter("foo").removeFromList();
- assertEquals(1, mockFilterChangeCallback.getTimesCalled());
+ callback.clearCheckValues();
+ filter.removeFromList();
+ assertFalse(filter.isListed());
+ assertEquals(1, callback.getTimesCalled());
}
@Test

Powered by Google App Engine
This is Rietveld