package apidez.com.android_mvvm_sample.view.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.test.rule.ActivityTestRule;
import android.test.suitebuilder.annotation.MediumTest;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.concurrent.CountDownLatch;

/**
 * Created by nongdenchet on 10/3/15.
 */
@MediumTest
@RunWith(JUnit4.class)
public class PurchaseActivityInteractTest {

    @Rule
    public ActivityTestRule<PurchaseActivity> activityTestRule =
            new ActivityTestRule<>(PurchaseActivity.class, true, false);

    @Before
    public void setUp() throws Exception {
        activityTestRule.launchActivity(new Intent());
    }

    @Test
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    public void testImpl() throws InterruptedException {
        final CountDownLatch latch = new CountDownLatch(1);
        activityTestRule.getActivity().getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            }

            @Override
            public void onActivityStarted(Activity activity) {
            }

            @Override
            public void onActivityResumed(Activity activity) {
            }

            @Override
            public void onActivityPaused(Activity activity) {
            }

            @Override
            public void onActivityStopped(Activity activity) {
            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                if (activityTestRule.getActivity() == activity) {
                    latch.countDown();
                    activityTestRule.getActivity().getApplication().unregisterActivityLifecycleCallbacks(this);
                }
            }
        });
        latch.await();
    }

}

@@ -1140,16 +1140,33 @@
 cation()
+%0A                
 .registe
@@ -1244,32 +1244,40 @@
 ) %7B%0A            
+        
 @Override%0A      
@@ -1262,32 +1262,40 @@
       @Override%0A
+        
             publ
@@ -1372,35 +1372,47 @@
 ) %7B%0A            
-%7D%0A%0A
+        %7D%0A%0A    
             @Ove
@@ -1399,32 +1399,36 @@
                 
+    
 @Override%0A      
@@ -1413,32 +1413,40 @@
       @Override%0A
+        
             publ
@@ -1496,32 +1496,40 @@
 ) %7B%0A            
+        
 %7D%0A%0A            @
@@ -1519,32 +1519,40 @@
  %7D%0A%0A            
+ 
+       
 @Override%0A      
@@ -1537,32 +1537,40 @@
       @Override%0A
+        
             publ
@@ -1620,35 +1620,51 @@
 ) %7B%0A            
-%7D%0A%0A
+        %7D%0A%0A        
             @Ove
@@ -1673,32 +1673,40 @@
 ide%0A            
+  
+      
 public void onAc
@@ -1743,32 +1743,40 @@
 ) %7B%0A            
+        
 %7D%0A%0A            @
@@ -1766,32 +1766,40 @@
  %7D%0A%0A            
+  
+      
 @Override%0A      
@@ -1784,32 +1784,40 @@
       @Override%0A
+        
             publ
@@ -1867,35 +1867,48 @@
 ) %7B%0A            
+  
-%7D%0A%0A
+      %7D%0A%0A     
             @Ove
@@ -1895,32 +1895,35 @@
                 
+   
 @Override%0A      
@@ -1908,32 +1908,40 @@
       @Override%0A
+        
             publ
@@ -2018,35 +2018,46 @@
 ) %7B%0A            
-%7D%0A%0A
+        %7D%0A%0A   
             @Ove
@@ -2044,32 +2044,37 @@
 %0A               
+     
 @Override%0A      
@@ -2059,32 +2059,40 @@
       @Override%0A
+        
             publ
@@ -2156,16 +2156,24 @@
         
+    
+    
 if (acti
@@ -2230,24 +2230,32 @@
             
+        
 latch.countD
@@ -2273,32 +2273,40 @@
                 
+    
+    
 activityTestRule
@@ -2336,16 +2336,53 @@
 cation()
+%0A                                    
 .unregis
@@ -2430,30 +2430,24 @@
             
-%7D%0A    
         %7D%0A  
@@ -2444,16 +2444,46 @@
       %7D%0A
+                    %7D%0A        
         

refactor test