forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract automatic answer Handler
Removes mTimeoutHandler from AbstractFlashcardViewer This is an incremental (bad) refactoring Now we've removed the handler, we can move most of the internal logic into the AutomaticAnswerSettings class This will let us make more methods private
- Loading branch information
1 parent
8e86539
commit 0ffc8d7
Showing
3 changed files
with
129 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
AnkiDroid/src/test/java/com/ichi2/anki/reviewer/AutomaticAnswerSettingsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2021 David Allison <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation; either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ichi2.anki.reviewer | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.ichi2.testutils.EmptyApplication | ||
import org.hamcrest.CoreMatchers.equalTo | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.kotlin.mock | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Config(application = EmptyApplication::class) | ||
class AutomaticAnswerSettingsTest { | ||
|
||
@Test | ||
fun stopAllWorks() { | ||
val target: AutomaticAnswerSettings.AutomaticallyAnswered = mock() | ||
val answer = AutomaticAnswerSettings( | ||
useTimer = true, | ||
questionDelaySeconds = 10, | ||
answerDelaySeconds = 10, | ||
target = target | ||
) | ||
|
||
answer.delayedShowQuestion(0) | ||
answer.delayedShowAnswer(0) | ||
|
||
assertThat(answer.timeoutHandler.hasMessages(0), equalTo(true)) | ||
|
||
answer.stopAll() | ||
|
||
assertThat(answer.timeoutHandler.hasMessages(0), equalTo(false)) | ||
} | ||
} |