package Ġcom . soft na uts . vision aut s . view model Ċ Ċ import Ġcom . soft na uts . vision aut s . rule . Tr amp oline Scheduler Rule Ċ import Ġcom . soft na uts . vision aut s . data . datasource . Settings DataSource Ċ import Ġcom . soft na uts . vision aut s . ui . settings . Settings ViewModel Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . Single Ċ import Ġjunit . framework . TestCase . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġorg . ro bo lectric . Ro bo lectric TestRunner Ċ import Ġorg . ro bo lectric . annotation . Config Ċ import Ġjava . lang . Exception Ċ Ċ @ RunWith ( Ro bo lectric TestRunner :: class ) Ċ @ Config ( manifest Ġ= ĠConfig . NONE ) Ċ class ĠSettings ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġtr amp oline Scheduler Rule Ġ= ĠTr amp oline Scheduler Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġsettings DataSource : ĠSettings DataSource ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠSettings ViewModel ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Range Positive Test (){ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( settings DataSource . get Range ()). thenReturn ( Observable . just ( 1 . 0 f )) ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠSettings ViewModel ( settings DataSource ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . range LiveData . value , Ġ 1 . 0 f ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . range Single Event . value ?. peek Content (), Ġ 1 . 0 f ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Range Negative Test (){ ĊĠĠĠĠĠĠĠ ĠMockito .` when `( settings DataSource . get Range ()). thenReturn ( Observable . error ( Exception (" exception "))) ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠSettings ViewModel ( settings DataSource ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . range LiveData . value , Ġnull ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . range Single Event . value ?. peek Content (), Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsave Range Positive Test (){ ĊĠĠĠĠĠĠĠ Ġval Ġnew Range Ġ= Ġ 1 . 0 f ĊĠĠĠĠĠĠĠ Ġval Ġold Range Ġ= Ġ 0 . 5 f ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( settings DataSource . get Range ()). thenReturn ( Observable . just ( old Range )) ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠSettings ViewModel ( settings DataSource ) ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( settings DataSource . save Range ( Mockito . any Float ())). thenReturn ( Single . just ( new Range )) ĊĊĠĠĠĠĠĠĠ ĠviewModel . save Range ( new Range ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . range LiveData . value , Ġnew Range ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsave Range Negative Test (){ ĊĠĠĠĠĠĠĠ Ġval Ġnew Range Ġ= Ġ 1 . 0 f ĊĠĠĠĠĠĠĠ Ġval Ġold Range Ġ= Ġ 0 . 5 f ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( settings DataSource . get Range ()). thenReturn ( Observable . just ( old Range )) ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠSettings ViewModel ( settings DataSource ) ĊĊĠĠĠĠĠĠĠ ĠMockito .` when `( settings DataSource . save Range ( Mockito . any Float ())). thenReturn ( Single . error ( Exception (" exception "))) ĊĊĠĠĠĠĠĠĠ ĠviewModel . save Range ( new Range ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( viewModel . range LiveData . value , Ġold Range ) ĊĠĠĠ Ġ} Ċ }