Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stealthcopter committed May 11, 2018
1 parent eff3329 commit e820055
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions rootbeerlib/src/test/java/com/scottyab/rootbeer/RootBeerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
import android.content.pm.PackageManager;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

import static junit.framework.Assert.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.hamcrest.CoreMatchers.not;
import static org.mockito.AdditionalMatchers.not;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.when;

/**
* Created by matthew on 31/10/17.
*/
@RunWith(MockitoJUnitRunner.class)
public class RootBeerTest {

@Test
public void testIsRooted() throws Exception {
public void testIsRooted() {

RootBeer rootBeer = Mockito.mock(RootBeer.class);

Expand All @@ -46,10 +49,11 @@ public void testIsRooted() throws Exception {
}

@Test
public void testIsRootedWithoutBusyBoxCheck() throws Exception {
public void testIsRootedWithoutBusyBoxCheck() {

RootBeer rootBeer = Mockito.mock(RootBeer.class);

when(rootBeer.isRooted()).thenCallRealMethod();
when(rootBeer.isRootedWithoutBusyBoxCheck()).thenCallRealMethod();

when(rootBeer.detectRootManagementApps()).thenReturn(false);
Expand All @@ -63,11 +67,10 @@ public void testIsRootedWithoutBusyBoxCheck() throws Exception {
when(rootBeer.checkForRootNative()).thenReturn(false);

// Test we return false when all methods return false
assertTrue(!rootBeer.isRooted());
assertTrue(rootBeer.isRooted());

// Test it doesn't matter what checkForBinary("busybox") returns
when(rootBeer.checkForBinary("busybox")).thenReturn(true);
assertTrue(!rootBeer.isRooted());
assertTrue(!rootBeer.isRootedWithoutBusyBoxCheck());

}

Expand Down Expand Up @@ -108,7 +111,7 @@ private Context getMockedContext(String packageNameToFind) throws PackageManager
}
else {
// Return exception for every package other than one we should detect
when(packageManager.getPackageInfo(argThat(not(packageNameToFind)), anyInt())).thenThrow(new PackageManager.NameNotFoundException());
when(packageManager.getPackageInfo(not(eq(packageNameToFind)), anyInt())).thenThrow(new PackageManager.NameNotFoundException());
}
return context;
}
Expand Down

0 comments on commit e820055

Please sign in to comment.