package net.grandcentrix.tray.provider;

import org.mockito.Mockito;

import android.content.Context;
import android.net.Uri;
import android.test.AndroidTestCase;

/**
 * Created by pascalwelsch on 4/12/15.
 */
public class TrayContractTest extends AndroidTestCase {

    public void testConstruction() throws Exception {
        new TrayContract();
    }

    public void testGenerateContentUri() throws Exception {
        Uri uri = TrayContract.generateContentUri(getContext());
        assertEquals("content://com.example.preferences/preferences", uri.toString());

        TrayContract.setAuthority("asdf");
        uri = TrayContract.generateContentUri(Mockito.mock(Context.class));
        assertEquals("content://asdf/preferences", uri.toString());
    }

    public void testGenerateInternalContentUri() throws Exception {
        Uri uri = TrayContract.generateInternalContentUri(getContext());
        assertEquals("content://com.example.preferences/internal_preferences", uri.toString());

        TrayContract.setAuthority("blubb");
        uri = TrayContract.generateInternalContentUri(Mockito.mock(Context.class));
        assertEquals("content://blubb/internal_preferences", uri.toString());
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        TrayContract.setAuthority(null);
    }


}
@@ -45,30 +45,72 @@
 ort 
-org.mockito.Mockit
+android.content.Context;%0Aimport android.content.pm.PackageInf
 o;%0A
-%0A
 impo
@@ -120,39 +120,89 @@
 android.content.
-Context
+pm.PackageManager;%0Aimport android.content.pm.ProviderInfo
 ;%0Aimport android
@@ -247,16 +247,182 @@
 estCase;
+%0Aimport android.test.mock.MockContext;%0Aimport android.test.mock.MockPackageManager;%0A%0Aimport org.mockito.Mockito;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -1462,24 +1462,1439 @@
 ());%0A    %7D%0A%0A
+    public void testGenerateContentUri2() throws Exception %7B%0A        MockContext mockContext = new MockContext() %7B%0A            @Override%0A            public Context getApplicationContext() %7B%0A                return this;%0A            %7D%0A%0A            @Override%0A            public String getPackageName() %7B%0A                return getContext().getPackageName();%0A            %7D%0A%0A            @Override%0A            public PackageManager getPackageManager() %7B%0A                return new MockPackageManager() %7B%0A                    @Override%0A                    public List%3CPackageInfo%3E getInstalledPackages(int flags) %7B%0A                        if (flags == PackageManager.GET_PROVIDERS) %7B%0A                            PackageInfo packageInfo = new PackageInfo();%0A                            ProviderInfo providerInfo = new ProviderInfo();%0A                            providerInfo.authority = getContext().getPackageName() + %22.tray%22;%0A                            packageInfo.providers = new ProviderInfo%5B%5D%7BproviderInfo%7D;%0A                            return Collections.singletonList(packageInfo);%0A                        %7D%0A                        return super.getInstalledPackages(flags);%0A                    %7D%0A                %7D;%0A            %7D%0A        %7D;%0A        Uri uri = TrayContract.generateContentUri(mockContext);%0A        assertEquals(%22content://%22 + getContext().getPackageName() + %22.tray/preferences%22, uri.toString());%0A    %7D%0A%0A
     @Overrid

add authority test