tests added
This commit is contained in:
		
							parent
							
								
									9c105f96a9
								
							
						
					
					
						commit
						d5f3962afe
					
				
					 5 changed files with 90 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								.idea/inspectionProfiles/Project_Default.xml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								.idea/inspectionProfiles/Project_Default.xml
									
										
									
										generated
									
									
									
								
							|  | @ -42,5 +42,6 @@ | ||||||
|       <option name="processLiterals" value="true" /> |       <option name="processLiterals" value="true" /> | ||||||
|       <option name="processComments" value="true" /> |       <option name="processComments" value="true" /> | ||||||
|     </inspection_tool> |     </inspection_tool> | ||||||
|  |     <inspection_tool class="TestFunctionName" enabled="false" level="WEAK WARNING" enabled_by_default="false" /> | ||||||
|   </profile> |   </profile> | ||||||
| </component> | </component> | ||||||
|  | @ -66,6 +66,7 @@ dependencies { | ||||||
|     implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" |     implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" | ||||||
|     implementation 'androidx.compose.material:material:1.2.0' |     implementation 'androidx.compose.material:material:1.2.0' | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" |     debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" | ||||||
| 
 | 
 | ||||||
|     // ViewModel |     // ViewModel | ||||||
|  | @ -97,6 +98,9 @@ dependencies { | ||||||
|     testImplementation 'junit:junit:4.13.2' |     testImplementation 'junit:junit:4.13.2' | ||||||
|     androidTestImplementation 'androidx.test.ext:junit:1.1.5' |     androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||||||
| 
 | 
 | ||||||
|  |     // Coroutine testing | ||||||
|  |     testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4' | ||||||
|  | 
 | ||||||
|     // Mocking |     // Mocking | ||||||
|     testImplementation 'org.mockito.kotlin:mockito-kotlin:3.2.0' |     testImplementation 'org.mockito.kotlin:mockito-kotlin:3.2.0' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -46,7 +46,6 @@ fun SessionScreen( | ||||||
|     val mediaplayer = MediaPlayer.create(context, uri) |     val mediaplayer = MediaPlayer.create(context, uri) | ||||||
|     mediaplayer.isLooping = false |     mediaplayer.isLooping = false | ||||||
| 
 | 
 | ||||||
|     // evt mediaplayer meegeven vanaf hier als reserve oplossing |  | ||||||
|     InvisibleSessionManager.setParameters(viewModel = viewModel, mediaplayer = mediaplayer) |     InvisibleSessionManager.setParameters(viewModel = viewModel, mediaplayer = mediaplayer) | ||||||
| 
 | 
 | ||||||
|     Column( |     Column( | ||||||
|  |  | ||||||
|  | @ -0,0 +1,83 @@ | ||||||
|  | package be.ugent.sel.studeez.timer_functional | ||||||
|  | 
 | ||||||
|  | import android.media.MediaPlayer | ||||||
|  | import be.ugent.sel.studeez.data.SelectedTimerState | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  | import be.ugent.sel.studeez.screens.session.InvisibleSessionManager | ||||||
|  | import be.ugent.sel.studeez.screens.session.SessionViewModel | ||||||
|  | import kotlinx.coroutines.ExperimentalCoroutinesApi | ||||||
|  | import kotlinx.coroutines.launch | ||||||
|  | import kotlinx.coroutines.test.advanceTimeBy | ||||||
|  | import kotlinx.coroutines.test.runTest | ||||||
|  | import org.junit.Assert | ||||||
|  | import org.junit.Test | ||||||
|  | import org.mockito.kotlin.mock | ||||||
|  | 
 | ||||||
|  | @ExperimentalCoroutinesApi | ||||||
|  | class InvisibleSessionManagerTest { | ||||||
|  |     private var timerState: SelectedTimerState = SelectedTimerState() | ||||||
|  |     private lateinit var viewModel: SessionViewModel | ||||||
|  |     private val mediaPlayer = mock<MediaPlayer>() | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     fun InvisibleEndlessTimerTest() = runTest { | ||||||
|  |         timerState.selectedTimer = FunctionalEndlessTimer() | ||||||
|  |         viewModel = SessionViewModel(timerState, mock()) | ||||||
|  |         InvisibleSessionManager.setParameters(viewModel, mediaPlayer) | ||||||
|  | 
 | ||||||
|  |         val test = launch { | ||||||
|  |             InvisibleSessionManager.updateTimer() | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().time.time, 0) | ||||||
|  |         advanceTimeBy(1_000) // Start tikker | ||||||
|  |         advanceTimeBy(10_000_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().time.time, 10000) | ||||||
|  | 
 | ||||||
|  |         test.cancel() | ||||||
|  |         return@runTest | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Test | ||||||
|  |     fun InvisiblePomodoroTimerTest() = runTest { | ||||||
|  |         val studyTime = 10 | ||||||
|  |         val breakTime = 5 | ||||||
|  |         val repeats = 1 | ||||||
|  |         timerState.selectedTimer = FunctionalPomodoroTimer(studyTime, breakTime, repeats) | ||||||
|  |         viewModel = SessionViewModel(timerState, mock()) | ||||||
|  |         InvisibleSessionManager.setParameters(viewModel, mediaPlayer) | ||||||
|  | 
 | ||||||
|  |         val test = launch { | ||||||
|  |             InvisibleSessionManager.updateTimer() | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().time.time, 10) | ||||||
|  |         advanceTimeBy(1_000) // start tikker | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(9_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().view, FunctionalTimer.StudyState.FOCUS) // Tijdens het focussen | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(1_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().time.time, 0) // Focussen gedaan | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(4_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().view, FunctionalTimer.StudyState.BREAK) // Tijdens pauze | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(1_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().time.time, 0) // Pauze gedaan | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(9_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().view, FunctionalTimer.StudyState.FOCUS_REMAINING) // Tijdens 2e focus | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(1_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().time.time, 0) // 2e focus gedaan | ||||||
|  | 
 | ||||||
|  |         advanceTimeBy(4_000) | ||||||
|  |         Assert.assertEquals(viewModel.getTimer().view, FunctionalTimer.StudyState.DONE) // Done | ||||||
|  | 
 | ||||||
|  |         test.cancel() | ||||||
|  |         return@runTest | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -7,6 +7,8 @@ | ||||||
| # Specifies the JVM arguments used for the daemon process. | # Specifies the JVM arguments used for the daemon process. | ||||||
| # The setting is particularly useful for tweaking memory settings. | # The setting is particularly useful for tweaking memory settings. | ||||||
| org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||||||
|  | org.gradle.daemon=true | ||||||
|  | org.gradle.parallel=true | ||||||
| # When configured, Gradle will run in incubating parallel mode. | # When configured, Gradle will run in incubating parallel mode. | ||||||
| # This option should only be used with decoupled projects. More details, visit | # This option should only be used with decoupled projects. More details, visit | ||||||
| # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Rune Dyselinck
						Rune Dyselinck