/*
 *
 * =======================================================================
 *
 * Copyright (c) 2014-2015 Domlex Limited. All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Domlex Limited.
 * You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with
 * Domlex Limited.
 *
 * =======================================================================
 *
 */

package com.triangleleft.flashcards.service.settings.rest;

import com.triangleleft.flashcards.service.RestService;
import com.triangleleft.flashcards.service.account.AccountModule;

import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@RunWith(JUnit4.class)
public class RestSettingsModuleTest {

    private RestSettingsModule module;

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Mock
    RestService service;
    @Mock
    AccountModule accountModule;

    @Before
    public void before() {
        MockitoAnnotations.initMocks(this);
        module = new RestSettingsModule(service, accountModule);
    }
//
//    @Test
//    public void loadUserData() {
//        when(accountModule.getUserId()).thenReturn(Optional.of("id"));
//        UserDataModel model = mock(UserDataModel.class);
//        UserData userData = UserData.create(Collections.emptyList(), "", "", "", "");
//        when(model.toUserData()).thenReturn(userData);
//        when(service.getUserData("id")).thenReturn(Observable.just(model));
//
//        TestSubscriber<UserData> subscriber = TestSubscriber.create();
//        module.loadUserData().subscribe(subscriber);
//        subscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
//
//        subscriber.assertValue(userData);
//        verify(accountModule).setUserData(userData);
//    }
//
//    @Test
//    public void switchLanguage() {
//        Language language = Language.create("id", "lang", 0, true, true);
//        when(service.switchLanguage(any(SwitchLanguageController.class)))
//                .thenReturn(Observable.just(null));
//
//        TestSubscriber<Void> subscriber = TestSubscriber.create();
//        module.switchLanguage(language).subscribe(subscriber);
//        subscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);
//
//        subscriber.assertNoErrors();
//        subscriber.assertValue(null);
//    }
}
@@ -553,16 +553,52 @@
 .rest;%0A%0A
+import com.annimon.stream.Optional;%0A
 import c
@@ -710,16 +710,412 @@
 tModule;
+%0Aimport com.triangleleft.flashcards.service.settings.Language;%0Aimport com.triangleleft.flashcards.service.settings.UserData;%0Aimport com.triangleleft.flashcards.service.settings.rest.model.SwitchLanguageController;%0Aimport com.triangleleft.flashcards.service.settings.rest.model.UserDataModel;%0Aimport com.triangleleft.flashcards.util.CallUtils;%0Aimport com.triangleleft.flashcards.util.TestObserver;
 %0A%0Aimport
@@ -1152,24 +1152,47 @@
 junit.Rule;%0A
+import org.junit.Test;%0A
 import org.j
@@ -1352,16 +1352,85 @@
 tions;%0A%0A
+import java.util.Collections;%0A%0Aimport static org.mockito.Mockito.*;%0A%0A
 @RunWith
@@ -1838,29 +1838,25 @@
 ule);%0A    %7D%0A
-//%0A//
+%0A
     @Test%0A//
@@ -1845,34 +1845,32 @@
    %7D%0A%0A    @Test%0A
-//
     public void 
@@ -1882,26 +1882,24 @@
 serData() %7B%0A
-//
         when
@@ -1957,18 +1957,16 @@
 %22id%22));%0A
-//
         
@@ -2014,18 +2014,16 @@
 class);%0A
-//
         
@@ -2100,18 +2100,16 @@
 %22, %22%22);%0A
-//
         
@@ -2147,34 +2147,32 @@
 turn(userData);%0A
-//
         when(ser
@@ -2202,34 +2202,33 @@
 .thenReturn(
-Observable
+CallUtils
 .just(model)
@@ -2226,29 +2226,25 @@
 st(model));%0A
-//%0A//
+%0A
         Test
@@ -2243,24 +2243,22 @@
     Test
-Subscrib
+Observ
 er%3CUserD
@@ -2266,48 +2266,41 @@
 ta%3E 
-subscriber = TestSubscriber.create
+observer = new TestObserver%3C%3E
 ();%0A
-//
     
@@ -2327,43 +2327,28 @@
 ata(
-).subscribe(subscrib
+observ
 er);%0A
-//
+%0A
         
 subs
@@ -2347,175 +2347,47 @@
     
-subscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);%0A//%0A//        subscriber.assertValue(userData);%0A//        verify(accountModule).setUserData(userData);%0A//
+observer.assertValue(userData);%0A
     %7D%0A
-//%0A//
+%0A
     
@@ -2392,18 +2392,16 @@
   @Test%0A
-//
     publ
@@ -2427,18 +2427,16 @@
 age() %7B%0A
-//
         
@@ -2501,18 +2501,16 @@
  true);%0A
-//
         
@@ -2578,27 +2578,8 @@
 s)))
-%0A//                
 .the
@@ -2590,18 +2590,17 @@
 urn(
-Observable
+CallUtils
 .jus
@@ -2609,21 +2609,17 @@
 null));%0A
-//%0A//
+%0A
         
@@ -2622,24 +2622,22 @@
     Test
-Subscrib
+Observ
 er%3CVoid%3E
@@ -2641,48 +2641,41 @@
 id%3E 
-subscriber = TestSubscriber.create
+observer = new TestObserver%3C%3E
 ();%0A
-//
     
@@ -2712,43 +2712,30 @@
 uage
-).subscribe(subscrib
+, observ
 er);%0A
-//
+%0A
         
 subs
@@ -2734,144 +2734,39 @@
     
-subscriber.awaitTerminalEvent(5, TimeUnit.SECONDS);%0A//%0A//        subscriber.assertNoErrors();%0A//        subscriber.assertValue(null
+observer.assertOnNextCalled(
 );%0A
-//
     

Update RestSettingsModule tests