Skip to content

Commit

Permalink
Satisfied constructor dependency for testsuites in test package
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Aug 5, 2023
1 parent 8c13a21 commit e4989af
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.openobservatory.ooniprobe.ui;

import android.content.Intent;
import android.content.res.Resources;

import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand All @@ -15,6 +16,7 @@
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.openobservatory.ooniprobe.AbstractTest;
import org.openobservatory.ooniprobe.TestApplicationProvider;
import org.openobservatory.ooniprobe.activity.MainActivity;
import org.openobservatory.ooniprobe.activity.RunningActivity;
import org.openobservatory.ooniprobe.common.service.RunTestService;
Expand Down Expand Up @@ -45,6 +47,8 @@ public class RunningActivityTest extends AbstractTest {
public RuleChain chain = RuleChain.outerRule(flakyRule)
.around(serviceRule);

Resources resources = TestApplicationProvider.app().getResources();

@Override
public void before() {
super.before();
Expand Down Expand Up @@ -87,7 +91,7 @@ private void startRunTestService() {
serviceRule.startService(
new Intent(c, RunTestService.class)
.putExtra("testSuites", new ArrayList<AbstractSuite>() {{
add(new InstantMessagingSuite());
add(new InstantMessagingSuite(resources));
}})
);
} catch (TimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.TestApplicationProvider;
import org.openobservatory.ooniprobe.factory.ResultFactory;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.database.Result;
Expand All @@ -22,17 +23,20 @@
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.content.res.Resources;

@RunWith(AndroidJUnit4.class)
public class CircumventionTest extends MeasurementAbstractTest {

@Rule
public FlakyTestRule flakyRule = new FlakyTestRule();
Resources resources = TestApplicationProvider.app().getResources();

@Test
@AllowFlaky(attempts = 3)
public void testHeaderData() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 3, 0);

// Act
launchDetails(testResult.id);
Expand All @@ -44,7 +48,7 @@ public void testHeaderData() {
@Test
public void testSuccessPsiphon() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 3, 0);
Measurement measurement = testResult.getMeasurement("psiphon");
String formattedBootstrap = FormattingUtils.formatBootstrap(measurement.getTestKeys().bootstrap_time);

Expand All @@ -61,7 +65,7 @@ public void testSuccessPsiphon() {
@Test
public void testBlockedPsiphon() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 0, 3);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 0, 3);
Measurement measurement = testResult.getMeasurement("psiphon");

// Act
Expand All @@ -77,7 +81,7 @@ public void testBlockedPsiphon() {
@Test
public void testSuccessTor() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 3, 0);
Measurement measurement = testResult.getMeasurement("tor");

String formattedBridges = FormattingUtils.getFormattedBridges(measurement);
Expand All @@ -97,7 +101,7 @@ public void testSuccessTor() {
@Test
public void testBlockedTor() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 0, 3);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 0, 3);
Measurement measurement = testResult.getMeasurement("tor");

String formattedBridges = FormattingUtils.getFormattedBridges(measurement);
Expand All @@ -117,7 +121,7 @@ public void testBlockedTor() {
@Test
public void testSuccessfulRiseUpVPN() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 3, 0);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 3, 0);
Measurement measurement = testResult.getMeasurement("riseupvpn");

// Act
Expand All @@ -135,7 +139,7 @@ public void testSuccessfulRiseUpVPN() {
@Test
public void testBlockedRiseUpVPN() {
// Arrange
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(), 0, 3);
Result testResult = ResultFactory.createAndSave(new CircumventionSuite(resources), 0, 3);
Measurement measurement = testResult.getMeasurement("riseupvpn");

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.TestApplicationProvider;
import org.openobservatory.ooniprobe.factory.ResultFactory;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.test.suite.InstantMessagingSuite;
Expand All @@ -20,17 +21,20 @@
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.content.res.Resources;

@RunWith(AndroidJUnit4.class)
public class InstantMessagingTest extends MeasurementAbstractTest {

@Rule
public FlakyTestRule flakyRule = new FlakyTestRule();
Resources resources = TestApplicationProvider.app().getResources();

@Test
@AllowFlaky(attempts = 3)
public void testHeaderData() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite());
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources));

// Act
launchDetails(testResult.id);
Expand All @@ -43,7 +47,7 @@ public void testHeaderData() {
@AllowFlaky(attempts = 2)
public void testSuccessWhatsApp() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite());
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources));

// Act
launchDetails(testResult.id);
Expand All @@ -57,7 +61,7 @@ public void testSuccessWhatsApp() {
@Test
public void testBlockedWhatsApp() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4);
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources), 0, 4);

// Act
launchDetails(testResult.id);
Expand All @@ -72,7 +76,7 @@ public void testBlockedWhatsApp() {
@Test
public void testSuccessTelegram() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite());
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources));

// Act
launchDetails(testResult.id);
Expand All @@ -87,7 +91,7 @@ public void testSuccessTelegram() {
@Test
public void testBlockedTelegram() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4);
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources), 0, 4);

// Act
launchDetails(testResult.id);
Expand All @@ -102,7 +106,7 @@ public void testBlockedTelegram() {
@Test
public void testSuccessFacebookMessenger() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite());
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources));

// Act
launchDetails(testResult.id);
Expand All @@ -117,7 +121,7 @@ public void testSuccessFacebookMessenger() {
@Test
public void testBlockedFacebookMessenger() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4);
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources), 0, 4);

// Act
launchDetails(testResult.id);
Expand All @@ -132,7 +136,7 @@ public void testBlockedFacebookMessenger() {
@Test
public void testSuccessSignal() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite());
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources));

// Act
launchDetails(testResult.id);
Expand All @@ -146,7 +150,7 @@ public void testSuccessSignal() {
@Test
public void testBlockedSignal() {
// Arrange
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(), 0, 4);
Result testResult = ResultFactory.createAndSave(new InstantMessagingSuite(resources), 0, 4);

// Act
launchDetails(testResult.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.TestApplicationProvider;
import org.openobservatory.ooniprobe.factory.ResultFactory;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.database.Result;
Expand All @@ -33,17 +34,20 @@
import static org.hamcrest.Matchers.containsString;
import static org.openobservatory.ooniprobe.ui.utils.RecyclerViewMatcher.withRecyclerView;

import android.content.res.Resources;

@RunWith(AndroidJUnit4.class)
public class PerformanceTest extends MeasurementAbstractTest {

@Rule
public FlakyTestRule flakyRule = new FlakyTestRule();
Resources resources = TestApplicationProvider.app().getResources();

@Test
@AllowFlaky(attempts = 3)
public void testHeaderData() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite());
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources));
Measurement dashMeasurement = testResult.getMeasurement(Dash.NAME);
String videoQuality = getResourceString(dashMeasurement.getTestKeys().getVideoQuality(false));

Expand Down Expand Up @@ -90,7 +94,7 @@ public void testHeaderData() {
@Test
public void testListOfMeasurements() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite());
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources));
Measurement dashMeasurement = testResult.getMeasurement(Dash.NAME);
String videoQuality = getResourceString(dashMeasurement.getTestKeys().getVideoQuality(true));
String notDetected = getResourceString(R.string.TestResults_Overview_MiddleBoxes_NotFound);
Expand Down Expand Up @@ -147,7 +151,7 @@ public void testListOfMeasurements() {
@Test
public void testNDT() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite());
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources));
Measurement ndtMeasurement = testResult.getMeasurement(Ndt.NAME);
Integer ndtProtocol = ndtMeasurement.getTestKeys().protocol;
TestKeys.Summary ndtSummary = ndtMeasurement.getTestKeys().summary;
Expand Down Expand Up @@ -193,7 +197,7 @@ public void testNDT() {
@Test
public void testStreaming() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite());
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources));
Measurement dashMeasurement = testResult.getMeasurement(Dash.NAME);
String videoQuality = getResourceString(dashMeasurement.getTestKeys().getVideoQuality(true));
String bitrateUnit = getResourceString(dashMeasurement.getTestKeys().getMedianBitrateUnit());
Expand All @@ -214,7 +218,7 @@ public void testStreaming() {
@Test
public void testRequestLine() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite());
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources));
Measurement invalidRequest = testResult.getMeasurement(HttpInvalidRequestLine.NAME);

// Act
Expand All @@ -229,7 +233,7 @@ public void testRequestLine() {
@Test
public void testRequestLineDetection() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(), 2, 2);
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources), 2, 2);
Measurement invalidRequest = testResult.getMeasurement(HttpInvalidRequestLine.NAME);

// Act
Expand All @@ -244,7 +248,7 @@ public void testRequestLineDetection() {
@Test
public void testFieldManipulation() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite());
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources));
Measurement fieldManipulation = testResult.getMeasurement(HttpHeaderFieldManipulation.NAME);

// Act
Expand All @@ -259,7 +263,7 @@ public void testFieldManipulation() {
@Test
public void testFieldManipulationDetection() {
// Arrange
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(), 2, 2);
Result testResult = ResultFactory.createAndSave(new PerformanceSuite(resources), 2, 2);
Measurement fieldManipulation = testResult.getMeasurement(HttpHeaderFieldManipulation.NAME);

// Act
Expand Down
Loading

0 comments on commit e4989af

Please sign in to comment.