Skip to content

Commit 9031583

Browse files
committed
refactor: extract 'menu()' from 'TestClass'
general extension method in order to split out `TestClass` to libanki:testutils
1 parent 0d0ed30 commit 9031583

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

AnkiDroid/src/test/java/com/ichi2/anki/DeckPickerTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.ichi2.testutils.BackupManagerTestUtilities
3535
import com.ichi2.testutils.DbUtils
3636
import com.ichi2.testutils.common.Flaky
3737
import com.ichi2.testutils.common.OS
38+
import com.ichi2.testutils.ext.menu
3839
import com.ichi2.testutils.grantWritePermissions
3940
import com.ichi2.testutils.revokeWritePermissions
4041
import com.ichi2.utils.ResourceLoader

AnkiDroid/src/test/java/com/ichi2/testutils/TestClass.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
package com.ichi2.testutils
1818

1919
import android.annotation.SuppressLint
20-
import android.view.Menu
2120
import androidx.appcompat.app.AppCompatDelegate
22-
import androidx.appcompat.widget.Toolbar
2321
import anki.collection.OpChanges
24-
import com.ichi2.anki.AnkiActivity
2522
import com.ichi2.anki.CollectionManager
26-
import com.ichi2.anki.R
2723
import com.ichi2.anki.ioDispatcher
2824
import com.ichi2.anki.isCollectionEmpty
2925
import com.ichi2.anki.libanki.Card
@@ -49,7 +45,6 @@ import net.ankiweb.rsdroid.exceptions.BackendDeckIsFilteredException
4945
import timber.log.Timber
5046
import kotlin.coroutines.CoroutineContext
5147
import kotlin.coroutines.EmptyCoroutineContext
52-
import kotlin.test.assertNotNull
5348
import kotlin.time.Duration.Companion.milliseconds
5449

5550
/**
@@ -336,8 +331,6 @@ interface TestClass {
336331
col.updateNote(this)
337332
}
338333

339-
fun AnkiActivity.menu(): Menu = assertNotNull(findViewById<Toolbar>(R.id.toolbar)?.menu)
340-
341334
/** * A wrapper around the standard [kotlinx.coroutines.test.runTest] that
342335
* takes care of updating the dispatcher used by CollectionManager as well.
343336
* * An argument could be made for using [StandardTestDispatcher] and
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2025 David Allison <davidallisongithub@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.ichi2.testutils.ext
18+
19+
import android.view.Menu
20+
import androidx.appcompat.widget.Toolbar
21+
import com.ichi2.anki.AnkiActivity
22+
import com.ichi2.anki.R
23+
import kotlin.test.assertNotNull
24+
25+
fun AnkiActivity.menu(): Menu = assertNotNull(findViewById<Toolbar>(R.id.toolbar)?.menu)

0 commit comments

Comments
 (0)