package org.ligi.snackengage;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import org.junit.Before;
import org.ligi.snackengage.snacks.Snack;
import org.ligi.snackengage.stats.SnackStats;
import org.ligi.snackengage.util.OpportunityUsingSnack;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public abstract class BaseTest {

    @Mock
    SnackContext mockSnackContext;

    @Mock
    Context mockAndroidContext;

    @Mock
    ConnectivityManager mockConnectivityManager;

    @Mock
    NetworkInfo mockNetwork;

    protected Snack someSnack = new OpportunityUsingSnack();

    @Before
    public void before() {
        MockitoAnnotations.initMocks(this);

        when(mockAndroidContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mockConnectivityManager);
        when(mockSnackContext.getAndroidContext()).thenReturn(mockAndroidContext);
        when(mockConnectivityManager.getActiveNetworkInfo()).thenReturn(mockNetwork);

        when(mockSnackContext.getStats()).thenReturn(mock(SnackStats.class));
    }

    protected List<Snack> asSnackList(Snack... inTs) {
        final List<Snack> outTs = new ArrayList<>();
        Collections.addAll(outTs, inTs);
        return outTs;
    }

}
@@ -129,16 +129,40 @@
 kInfo;%0A%0A
+import org.junit.After;%0A
 import o
@@ -178,16 +178,16 @@
 Before;%0A
-
 import o
@@ -833,16 +833,49 @@
 Snack();
+%0A    private AutoCloseable mocks;
 %0A%0A    @B
@@ -914,16 +914,24 @@
 %0A       
+ mocks =
  Mockito
@@ -946,12 +946,12 @@
 ons.
-init
+open
 Mock
@@ -1243,24 +1243,24 @@
 kNetwork);%0A%0A
-
         when
@@ -1332,16 +1332,191 @@
 %0A    %7D%0A%0A
+    @After%0A    public void after() %7B%0A        try %7B%0A            mocks.close();%0A        %7D catch (Exception ignore) %7B%0A            // Nothing we can do about it.%0A        %7D%0A    %7D%0A%0A
     prot

Update deprecated mocks' lifecycle.