summaryrefslogtreecommitdiff
path: root/app/src/test
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-01-24 23:23:06 +0100
committercyBerta <cyberta@riseup.net>2024-01-24 23:23:06 +0100
commit190b8d731d646ed18e771ce07b43a6c846526dd5 (patch)
treefb2215a289415dcec19f534cd6331a81132f46d0 /app/src/test
parent827be305805bd98362692f506c46dc7c73c6fc97 (diff)
add TorStatusObservableTest testing propertyChange pattern
Diffstat (limited to 'app/src/test')
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/tor/TorStatusObservableTest.java46
1 files changed, 44 insertions, 2 deletions
diff --git a/app/src/test/java/se/leap/bitmaskclient/tor/TorStatusObservableTest.java b/app/src/test/java/se/leap/bitmaskclient/tor/TorStatusObservableTest.java
index bdf8f6ac..10dbf6cb 100644
--- a/app/src/test/java/se/leap/bitmaskclient/tor/TorStatusObservableTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/tor/TorStatusObservableTest.java
@@ -1,6 +1,48 @@
package se.leap.bitmaskclient.tor;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+@RunWith(MockitoJUnitRunner.class)
public class TorStatusObservableTest {
-
+
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mockContext;
+
+
+
+ @Test
+ public void testPropertyChange() throws PackageManager.NameNotFoundException {
+ TorStatusObservable statusObservable = TorStatusObservable.getInstance();
+ int i = 10;
+ PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ assertEquals(12, TorStatusObservable.getBootstrapProgress());
+ assertEquals("a logkey", TorStatusObservable.getLastLogs().lastElement());
+ assertNull(evt.getOldValue());
+ TorStatusObservable.getInstance().deleteObserver(this);
+ }
+ };
+
+ TorStatusObservable.updateState(mockContext, "STARTING", 10, "a logkey");
+ TorStatusObservable.updateState(mockContext, "STARTING", 11, "a log 2");
+ TorStatusObservable.getInstance().addObserver(propertyChangeListener);
+ TorStatusObservable.updateState(mockContext, "STARTING", 12, "a log 3");
+
+ }
+
} \ No newline at end of file