package ua.anironglass.template;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.manifest.AndroidManifest;
import org.robolectric.res.Fs;

import ua.anironglass.template.utils.DefaultConfig;

import static com.google.common.truth.Truth.assertThat;


@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = DefaultConfig.EMULATE_SDK)
public final class PermissionsTest {

    private static final Object[] EXPECTED_RELEASE_PERMISSIONS = {
            "android.permission.INTERNET",
            "android.permission.ACCESS_NETWORK_STATE",
    };

    private static final Object[] EXPECTED_DEBUG_PERMISSIONS = {
            "android.permission.INTERNET",
            "android.permission.ACCESS_NETWORK_STATE",
            "android.permission.DISABLE_KEYGUARD",
            "android.permission.WAKE_LOCK",
            "android.permission.READ_LOGS",
            "android.permission.READ_EXTERNAL_STORAGE",
            "android.permission.WRITE_EXTERNAL_STORAGE"
    };

    private static final String MERGED_MANIFEST_FILE =
            "build/intermediates/manifests/full/debug/AndroidManifest.xml";

    @Test
    public void shouldMatchPermissions() {
        AndroidManifest manifest = new AndroidManifest(
                Fs.fileFromPath(MERGED_MANIFEST_FILE),
                null,
                null
        );

        Object[] expectedPermissions;
        if (BuildConfig.DEBUG) {
            expectedPermissions = EXPECTED_DEBUG_PERMISSIONS;
        } else {
            expectedPermissions = EXPECTED_RELEASE_PERMISSIONS;
        }

        assertThat(manifest.getUsedPermissions())
                .containsExactly(expectedPermissions);
    }

}
@@ -1134,24 +1134,172 @@
 ring MERGED_
+RELEASE_MANIFEST_FILE =%0A            %22build/intermediates/manifests/full/release/AndroidManifest.xml%22;%0A%0A    private static final String MERGED_DEBUG_
 MANIFEST_FIL
@@ -1375,24 +1375,25 @@
 fest.xml%22;%0A%0A
+%0A
     @Test%0A  
@@ -1417,16 +1417,23 @@
 uldMatch
+Release
 Permissi
@@ -1535,16 +1535,24 @@
 (MERGED_
+RELEASE_
 MANIFEST
@@ -1613,25 +1613,24 @@
      );%0A
-%0A
         
 Object%5B%5D
@@ -1625,23 +1625,33 @@
     
-Object%5B%5D expect
+assertThat(manifest.getUs
 edPe
@@ -1659,17 +1659,19 @@
 missions
-;
+())
 %0A       
@@ -1675,67 +1675,33 @@
     
-if (BuildConfig.DEBUG) %7B%0A            expectedPermissions = 
+        .containsExactly(
 EXPE
@@ -1697,37 +1697,39 @@
 xactly(EXPECTED_
-DEBUG
+RELEASE
 _PERMISSIONS;%0A  
@@ -1728,101 +1728,246 @@
 IONS
+)
 ;%0A    
+%7D%0A%0A
     
-%7D else %7B%0A            expectedPermissions = EXPECTED_RELEASE_PERMISSIONS;%0A        %7D%0A
+@Test%0A    public void shouldMatchDebugPermissions() %7B%0A        AndroidManifest manifest = new AndroidManifest(%0A                Fs.fileFromPath(MERGED_DEBUG_MANIFEST_FILE),%0A                null,%0A                null%0A        );
 %0A   
@@ -2050,27 +2050,34 @@
 tly(
-expectedPermissions
+EXPECTED_DEBUG_PERMISSIONS
 );%0A 

Fix debug and release permissions test