/*
 * Copyright (c) 2018 Midhun Harikumar
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.ae.apps.lib.permissions;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

public class RuntimePermissionsCheckerTest {

    @Mock
    private PermissionsAwareComponent component;

    private String[] singlePermission = {"PERMISSION ONE"};
    private String[] multiplePermissions = {"PERMISSION ONE", "PERMISSION TWO", "PERMISSION THREE"};

    @Before
    public void setup() {
        component = Mockito.mock(MockPermissionsAwareActivity.class);
    }

    @Test
    public void shouldCreateObject_withSinglePermission(){
        Mockito.when(component.requiredPermissions()).thenReturn(singlePermission);
        RuntimePermissionChecker permissionChecker = new RuntimePermissionChecker(component);
        Assert.assertNotNull(permissionChecker);
    }

    @Test
    public void shouldCreateObject_withMultiplePermission(){
        Mockito.when(component.requiredPermissions()).thenReturn(multiplePermissions);
        RuntimePermissionChecker permissionChecker = new RuntimePermissionChecker(component);
        Assert.assertNotNull(permissionChecker);
    }

    @Test(expected = IllegalArgumentException.class)
    public void shouldThrowIllegalArgumentException_forNullParameter() {
        new RuntimePermissionChecker(null);
    }

    @Test(expected = IllegalStateException.class)
    public void shouldThrowIllegalStateException_forNullPermissions() {
        Mockito.when(component.requiredPermissions()).thenReturn(null);
        new RuntimePermissionChecker(component);
    }

    @Test(expected = IllegalStateException.class)
    public void shouldThrowIllegalStateException_forEmptyPermissions() {
        String[] empty = {};
        Mockito.when(component.requiredPermissions()).thenReturn(empty);
        new RuntimePermissionChecker(component);
    }


}

@@ -639,39 +639,34 @@
 s;%0A%0A
+%0A
 import 
+org.
 junit.
-framework.
 Assert;%0A
 %0Aimp
@@ -661,17 +661,16 @@
 Assert;%0A
-%0A
 import o
@@ -873,32 +873,38 @@
 t;%0A%0A    private 
+final 
 String%5B%5D singleP
@@ -947,16 +947,22 @@
 private 
+final 
 String%5B%5D
@@ -1355,36 +1355,32 @@
 missionChecker =
- new
  RuntimePermissi
@@ -1380,32 +1380,44 @@
 ermissionChecker
+.newInstance
 (component);%0A   
@@ -1679,20 +1679,16 @@
 hecker =
- new
  Runtime
@@ -1696,32 +1696,44 @@
 ermissionChecker
+.newInstance
 (component);%0A   
@@ -1911,36 +1911,32 @@
 ter() %7B%0A        
-new 
 RuntimePermissio
@@ -1943,16 +1943,28 @@
 nChecker
+.newInstance
 (null);%0A
@@ -2164,36 +2164,32 @@
 (null);%0A        
-new 
 RuntimePermissio
@@ -2188,32 +2188,44 @@
 ermissionChecker
+.newInstance
 (component);%0A   
@@ -2465,12 +2465,8 @@
     
-new 
 Runt
@@ -2485,16 +2485,28 @@
 nChecker
+.newInstance
 (compone

update test case