From e0ee3dce40cb01567f2ebfb69dc1a134cd92d142 Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Thu, 17 Dec 2020 09:40:04 +0100 Subject: [PATCH] Use @BeforeClass for ContentSettingsManagerTest.beforeClass --- .../settings/ContentSettingsManagerTest.kt | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt b/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt index 9809fd5fc..5ac132f7f 100644 --- a/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt +++ b/app/src/test/java/org/schabi/newpipe/settings/ContentSettingsManagerTest.kt @@ -4,6 +4,7 @@ import android.content.SharedPreferences import org.junit.Assert import org.junit.Assume import org.junit.Before +import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Suite @@ -22,24 +23,27 @@ class ContentSettingsManagerTest { @RunWith(MockitoJUnitRunner::class) class ExportTest { - private lateinit var preferences: SharedPreferences - private lateinit var newpipeDb: File - private lateinit var newpipeSettings: File + companion object { + private lateinit var newpipeDb: File + private lateinit var newpipeSettings: File - @Before - fun beforeClass() { + @JvmStatic + @BeforeClass + fun setupFiles() { + val dbPath = ExportTest::class.java.classLoader?.getResource("settings/newpipe.db")?.file + val settingsPath = ExportTest::class.java.classLoader?.getResource("settings/newpipe.settings")?.path + Assume.assumeNotNull(dbPath) + Assume.assumeNotNull(settingsPath) - val dbPath = javaClass.classLoader?.getResource("settings/newpipe.db")?.file - val settingsPath = javaClass.classLoader?.getResource("settings/newpipe.settings")?.path - Assume.assumeNotNull(dbPath) - Assume.assumeNotNull(settingsPath) - - newpipeDb = File(dbPath!!) - newpipeSettings = File(settingsPath!!) + newpipeDb = File(dbPath!!) + newpipeSettings = File(settingsPath!!) + } } + private lateinit var preferences: SharedPreferences + @Before - fun before() { + fun setupMocks() { preferences = Mockito.mock(SharedPreferences::class.java, Mockito.withSettings().stubOnly()) }