package com.orhanobut.hawk;

import android.content.Context;
import android.test.InstrumentationTestCase;
import android.util.Log;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * @author Orhan Obut
 */
public class HawkRxTest extends InstrumentationTestCase {

  Context context;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    System.setProperty(
        "dexmaker.dexcache",
        getInstrumentation().getTargetContext().getCacheDir().getPath());
    context = getInstrumentation().getContext();
    Hawk.init(context).build();
  }

  @Override
  protected void tearDown() throws Exception {
    super.tearDown();
    context = null;
    Hawk.clear();
    Hawk.resetCrypto();
  }

  private static final String KEY = "TAG";

  public void testString() throws Exception {
    Hawk.put(KEY, "hawk");

    Hawk.<String>getObservable(KEY)
        .observeOn(Schedulers.io())
        .subscribeOn(AndroidSchedulers.mainThread())
        .subscribe(new Subscriber<String>() {
          @Override
          public void onCompleted() {
            Log.d("rxtest", "completed");
            assertTrue(true);
          }

          @Override
          public void onError(Throwable e) {
            Log.d("rxtest", "error");
            assertTrue(false);
          }

          @Override
          public void onNext(String s) {
            Log.d("rxtest", s);
            assertTrue(true);
          }
        });
  }

}

@@ -125,16 +125,58 @@
 l.Log;%0A%0A
+import rx.Observable;%0Aimport rx.Observer;%0A
 import r
@@ -237,16 +237,43 @@
 dulers;%0A
+import rx.functions.Func1;%0A
 import r
@@ -1574,10 +1574,920 @@
 );%0A  %7D%0A%0A
+  public void testBuildRx() %7B%0A    Hawk.init(context)%0A        .buildRx()%0A        .concatMap(new Func1%3CBoolean, Observable%3CBoolean%3E%3E() %7B%0A          @Override%0A          public Observable%3CBoolean%3E call(Boolean aBoolean) %7B%0A            return Hawk.putObservable(KEY, %22hawk%22);%0A          %7D%0A        %7D)%0A        .concatMap(new Func1%3CBoolean, Observable%3CString%3E%3E() %7B%0A          @Override%0A          public Observable%3CString%3E call(Boolean aBoolean) %7B%0A            return Hawk.getObservable(KEY);%0A          %7D%0A        %7D)%0A        .subscribe(new Observer%3CString%3E() %7B%0A          @Override%0A          public void onCompleted() %7B%0A            assertTrue(true);%0A          %7D%0A%0A          @Override%0A          public void onError(Throwable throwable) %7B%0A            assertTrue(false);%0A          %7D%0A%0A          @Override%0A          public void onNext(String storedValue) %7B%0A            assertEquals(storedValue, %22hawk%22);%0A          %7D%0A        %7D);%0A  %7D%0A
 %7D%0A

Add test for buildRx()