// Path: sdk/src/com/sharethis/loopy/sdk/util/AppUtils.java
// public class AppUtils {
// 
//     static final AppUtils instance = new AppUtils();
// 
//     AppUtils() {}
// 
//     public static AppUtils getInstance() {
//         return instance;
//     }
// 
//     /**
//      * Determines inclusive permissions.
//      * @param context The current context.
//      * @param permissions The permissions sought.
//      * @return Returns true iff the app has ALL the given permissions.
//      */
//     public boolean hasAndPermission(Context context, String...permissions) {
//         for (String permission : permissions) {
//             int res = context.checkCallingOrSelfPermission(permission);
//             if(res != PackageManager.PERMISSION_GRANTED) {
//                 return false;
//             }
//         }
//         return true;
//     }
// 
//     /**
//      * Determines exclusive permissions.
//      * @param context The current context.
//      * @param permissions The permissions sought.
//      * @return Returns true iff the app has ANY the given permissions.
//      */
//     public boolean hasOrPermission(Context context, String...permissions) {
//         for (String permission : permissions) {
//             int res = context.checkCallingOrSelfPermission(permission);
//             if(res == PackageManager.PERMISSION_GRANTED) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
//     /**
//      * Returns the app info for the apps which support the ACTION_SEND intent with the given types.
//      * @param context The current context.
//      * @param contentTypes The content types supported.
//      * @return A Collection (set) of ResolveInfo objects corresponding to the apps installed on the device that
//      *          support the content type(s).
//      */
//     public Collection<ResolveInfo> getAppsForContentType(Context context, String...contentTypes) {
//         Set<ResolveInfo> apps = new LinkedHashSet<ResolveInfo>();
//         for (String type : contentTypes) {
//             List<ResolveInfo> appsByType = listAppsForType(context, type);
//             if(appsByType != null && appsByType.size() > 0) {
//                 apps.addAll(appsByType);
//             }
//         }
//         return apps;
//     }
// 
//     List<ResolveInfo> listAppsForType(Context context, String type) {
//         Intent intent = getSendIntent();
//         intent.setType(type);
// 
//         PackageManager p = context.getPackageManager();
// 
//         List<ResolveInfo> appList = p.queryIntentActivities(intent, 0);
// 
//         // Sort alphabetically.
//         Collections.sort(appList, new android.content.pm.ResolveInfo.DisplayNameComparator(p));
// 
//         return appList;
//     }
// 
//     // mockable
//     Intent getSendIntent() {
//         return new Intent(Intent.ACTION_SEND);
//     }
// 
// }
// 
// Path: test/src/com/sharethis/loopy/sdk/util/MockAppDataCache.java
// public class MockAppDataCache extends AppDataCache{
// 
//     public MockAppDataCache() {}
// 
//     @Override
//     public String getKey(ResolveInfo item) {
//         return super.getKey(item);
//     }
// 
//     @Override
//     public AppUtils getAppUtils() {
//         return super.getAppUtils();
//     }
// 
//     public static void setInstance(AppDataCache instance) {
//         AppDataCache.instance = instance;
//     }
// }
// 
// Path: test/src/com/sharethis/loopy/test/util/Holder.java
// public class Holder<T> {
// 
// 	private T object;
// 
//     private List<T> objects = new ArrayList<T>();
// 
// 	public Holder() {}
// 
// 	public Holder(T object) {
// 		super();
// 		this.object = object;
// 	}
// 
// 	public T get() {
// 		return object;
// 	}
// 
// 	public void set(T object) {
// 		this.object = object;
// 	}
// 
//     public void add(T object) {
//         objects.add(object);
//     }
// 
//     public List<T> getObjects() {
//         return objects;
//     }
// }


import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import com.sharethis.loopy.sdk.util.AppUtils;
import com.sharethis.loopy.sdk.util.MockAppDataCache;
import com.sharethis.loopy.test.util.Holder;
import org.mockito.Mockito;
import java.util.Arrays;
import java.util.List;
        assertNotNull(appLabel);
        assertEquals("foobar", appLabel);

        appLabel = cache.getAppLabel("foo", "bar");

        assertNotNull(appLabel);
        assertEquals("foobar", appLabel);

        Mockito.verify(activityInfo, Mockito.times(1)).loadLabel((PackageManager) Mockito.any());
    }

    public void testGetAppIcon() {

        // Can't mock the ResolveInfo because activityInfo has members not methods.
        ResolveInfo mockInfo = new ResolveInfo();
        ActivityInfo activityInfo = Mockito.mock(ActivityInfo.class);
        Drawable drawable = Mockito.mock(Drawable.class);

        activityInfo.packageName = "foo";
        activityInfo.name = "bar";

        Mockito.when(activityInfo.loadIcon((PackageManager) Mockito.any())).thenReturn(drawable);

        mockInfo.activityInfo = activityInfo;

        MockAppDataCache cache = new MockAppDataCache() ;

        Drawable cached = cache.getAppIcon(getContext(), mockInfo);

        assertNotNull(cached);
// Path: sdk/src/com/sharethis/loopy/sdk/util/AppUtils.java
// public class AppUtils {
// 
//     static final AppUtils instance = new AppUtils();
// 
//     AppUtils() {}
// 
//     public static AppUtils getInstance() {
//         return instance;
//     }
// 
//     /**
//      * Determines inclusive permissions.
//      * @param context The current context.
//      * @param permissions The permissions sought.
//      * @return Returns true iff the app has ALL the given permissions.
//      */
//     public boolean hasAndPermission(Context context, String...permissions) {
//         for (String permission : permissions) {
//             int res = context.checkCallingOrSelfPermission(permission);
//             if(res != PackageManager.PERMISSION_GRANTED) {
//                 return false;
//             }
//         }
//         return true;
//     }
// 
//     /**
//      * Determines exclusive permissions.
//      * @param context The current context.
//      * @param permissions The permissions sought.
//      * @return Returns true iff the app has ANY the given permissions.
//      */
//     public boolean hasOrPermission(Context context, String...permissions) {
//         for (String permission : permissions) {
//             int res = context.checkCallingOrSelfPermission(permission);
//             if(res == PackageManager.PERMISSION_GRANTED) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
//     /**
//      * Returns the app info for the apps which support the ACTION_SEND intent with the given types.
//      * @param context The current context.
//      * @param contentTypes The content types supported.
//      * @return A Collection (set) of ResolveInfo objects corresponding to the apps installed on the device that
//      *          support the content type(s).
//      */
//     public Collection<ResolveInfo> getAppsForContentType(Context context, String...contentTypes) {
//         Set<ResolveInfo> apps = new LinkedHashSet<ResolveInfo>();
//         for (String type : contentTypes) {
//             List<ResolveInfo> appsByType = listAppsForType(context, type);
//             if(appsByType != null && appsByType.size() > 0) {
//                 apps.addAll(appsByType);
//             }
//         }
//         return apps;
//     }
// 
//     List<ResolveInfo> listAppsForType(Context context, String type) {
//         Intent intent = getSendIntent();
//         intent.setType(type);
// 
//         PackageManager p = context.getPackageManager();
// 
//         List<ResolveInfo> appList = p.queryIntentActivities(intent, 0);
// 
//         // Sort alphabetically.
//         Collections.sort(appList, new android.content.pm.ResolveInfo.DisplayNameComparator(p));
// 
//         return appList;
//     }
// 
//     // mockable
//     Intent getSendIntent() {
//         return new Intent(Intent.ACTION_SEND);
//     }
// 
// }
// 
// Path: test/src/com/sharethis/loopy/sdk/util/MockAppDataCache.java
// public class MockAppDataCache extends AppDataCache{
// 
//     public MockAppDataCache() {}
// 
//     @Override
//     public String getKey(ResolveInfo item) {
//         return super.getKey(item);
//     }
// 
//     @Override
//     public AppUtils getAppUtils() {
//         return super.getAppUtils();
//     }
// 
//     public static void setInstance(AppDataCache instance) {
//         AppDataCache.instance = instance;
//     }
// }
// 
// Path: test/src/com/sharethis/loopy/test/util/Holder.java
// public class Holder<T> {
// 
// 	private T object;
// 
//     private List<T> objects = new ArrayList<T>();
// 
// 	public Holder() {}
// 
// 	public Holder(T object) {
// 		super();
// 		this.object = object;
// 	}
// 
// 	public T get() {
// 		return object;
// 	}
// 
// 	public void set(T object) {
// 		this.object = object;
// 	}
// 
//     public void add(T object) {
//         objects.add(object);
//     }
// 
//     public List<T> getObjects() {
//         return objects;
//     }
// }


// Path: test/src/com/sharethis/loopy/test/AppDataCacheTest.java
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import com.sharethis.loopy.sdk.util.AppUtils;
import com.sharethis.loopy.sdk.util.MockAppDataCache;
import com.sharethis.loopy.test.util.Holder;
import org.mockito.Mockito;
import java.util.Arrays;
import java.util.List;

        assertNotNull(appLabel);
        assertEquals("foobar", appLabel);

        appLabel = cache.getAppLabel("foo", "bar");

        assertNotNull(appLabel);
        assertEquals("foobar", appLabel);

        Mockito.verify(activityInfo, Mockito.times(1)).loadLabel((PackageManager) Mockito.any());
    }

    public void testGetAppIcon() {

        // Can't mock the ResolveInfo because activityInfo has members not methods.
        ResolveInfo mockInfo = new ResolveInfo();
        ActivityInfo activityInfo = Mockito.mock(ActivityInfo.class);
        Drawable drawable = Mockito.mock(Drawable.class);

        activityInfo.packageName = "foo";
        activityInfo.name = "bar";

        Mockito.when(activityInfo.loadIcon((PackageManager) Mockito.any())).thenReturn(drawable);

        mockInfo.activityInfo = activityInfo;

        MockAppDataCache cache = new MockAppDataCache() ;

        Drawable cached = cache.getAppIcon(getContext(), mockInfo);

        assertNotNull(cached);
        assertSame(drawable, cached);