From fdc78953abaf7cf8025f7fd48ca033094de66d84 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Wed, 17 Jul 2024 11:07:45 +0100 Subject: [PATCH] chore(tests): fix broken `AbstractSuiteTest` --- .../openobservatory/ooniprobe/common/OONIDescriptor.kt | 8 ++++---- .../ooniprobe/test/suite/AbstractSuiteTest.java | 10 ++++++++++ .../ooniprobe/test/suite/ExperimentalSuiteTest.java | 5 +++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt index 9905e9ad0..fc75c70cc 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/OONIDescriptor.kt @@ -314,15 +314,15 @@ enum class OONITests( this.run { return OONIDescriptor( name = label, - title = context.getString(title), - shortDescription = context.getString(shortDescription), + title = r.getString(title), + shortDescription = r.getString(shortDescription), description = when (label) { - EXPERIMENTAL.label -> context.getString( + EXPERIMENTAL.label -> r.getString( description, experimentalLinks(r) ) - else -> context.getString(description) + else -> r.getString(description) }, icon = icon, color = ContextCompat.getColor(context, color), diff --git a/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java b/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java index 3f4b97db4..dacb2fa01 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/test/suite/AbstractSuiteTest.java @@ -16,12 +16,18 @@ import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.openobservatory.ooniprobe.test.suite.AbstractSuiteExtensionsKt.getSuite; +import android.content.res.Resources; + public class AbstractSuiteTest { private final Application app = mock(Application.class); + + private final Resources mockContextResources = mock(Resources.class); + private AbstractSuite suite = new AbstractSuite( "test", "", @@ -42,6 +48,10 @@ public class AbstractSuiteTest { @Before public void setUp() { when(app.getPreferenceManager()).thenReturn(pm); + when(app.getResources()).thenReturn(mockContextResources); + when(mockContextResources.getString(anyInt())).thenReturn("mocked string"); + when(mockContextResources.getString(anyInt(),any())).thenReturn("mocked string"); + } @Test diff --git a/app/src/test/java/org/openobservatory/ooniprobe/test/suite/ExperimentalSuiteTest.java b/app/src/test/java/org/openobservatory/ooniprobe/test/suite/ExperimentalSuiteTest.java index 26de1bdd9..3d295ed5d 100644 --- a/app/src/test/java/org/openobservatory/ooniprobe/test/suite/ExperimentalSuiteTest.java +++ b/app/src/test/java/org/openobservatory/ooniprobe/test/suite/ExperimentalSuiteTest.java @@ -1,5 +1,6 @@ package org.openobservatory.ooniprobe.test.suite; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.openobservatory.ooniprobe.common.Application; @@ -22,8 +23,8 @@ public class ExperimentalSuiteTest { private final AbstractSuite autoRunSuite = OONITests.EXPERIMENTAL.toOONIDescriptor(app).getTest(app); private final PreferenceManager pm = mock(PreferenceManager.class); - @BeforeClass - public void setUp() { + @Before + public void setUp() { autoRunSuite.setAutoRun(true); } @Test