Skip to content

Commit

Permalink
Add assumptions for Spoon tests to be ignored on API 21+
Browse files Browse the repository at this point in the history
  • Loading branch information
jraska committed Jul 27, 2016
1 parent db5b095 commit aff304d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.jraska.falcon.sample;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import org.junit.Assume;

import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;

public final class Assumptions {
public static void assumeNoCI() {
Assume.assumeThat("Test should not run on CI server.", isContinuousIntegration(), is(false));
}

public static boolean isContinuousIntegration() {
return BuildConfig.CI_BUILD;
}

public static void assumeSpoonPermissions() {
// TODO: 28/07/16 PULL WELCOME: grant permissions to test application on API 21+
Assume.assumeThat("Spoon cannot take screenshots on API 21+" +
" without granted WRITE_EXTERNAL_STORAGE permission",
Build.VERSION.SDK_INT, lessThan(Build.VERSION_CODES.LOLLIPOP));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.test.runner.AndroidJUnit4;
import com.jraska.falcon.FalconSpoon;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -18,10 +19,9 @@
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.jraska.falcon.sample.CICheck.assumeNoCI;
import static android.support.test.espresso.matcher.ViewMatchers.*;
import static com.jraska.falcon.sample.Assumptions.assumeNoCI;
import static com.jraska.falcon.sample.Assumptions.assumeSpoonPermissions;
import static com.jraska.falcon.sample.asserts.BitmapFileAssert.assertThatFile;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -43,6 +43,12 @@ public class EspressoSpoonTest {

//region Setup Methods

@Before
public void before() throws Exception {
assumeNoCI();
assumeSpoonPermissions();
}

@After
public void after() throws Exception {
for (File screenshot : takenScreenshots) {
Expand All @@ -56,8 +62,6 @@ public void after() throws Exception {

@Test
public void dialogTakenInScreenshot() throws Exception {
assumeNoCI();

SampleActivity activity = _activityRule.getActivity();

File screenshotWithoutDialogFile = FalconSpoon.screenshot(activity, "No_dialog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.jraska.falcon.sample.CICheck.assumeNoCI;
import static com.jraska.falcon.sample.Assumptions.assumeNoCI;
import static com.jraska.falcon.sample.asserts.BitmapAssert.assertThatBitmap;

public class FalconDialogInOnCreateTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.jraska.falcon.sample.CICheck.assumeNoCI;
import static com.jraska.falcon.sample.Assumptions.assumeNoCI;
import static com.jraska.falcon.sample.asserts.BitmapAssert.assertThatBitmap;
import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import android.support.test.runner.AndroidJUnit4;
import com.jraska.falcon.FalconSpoon;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;

import static com.jraska.falcon.sample.Assumptions.assumeSpoonPermissions;
import static com.jraska.falcon.sample.asserts.BitmapFileAssert.assertThatFile;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -31,6 +33,11 @@ public class FalconSpoonTest {

//region Setup Methods

@Before
public void before() throws Exception {
assumeSpoonPermissions();
}

@After
public void after() throws Exception {
if (_screenshotFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.jraska.falcon.sample.CICheck.assumeNoCI;
import static com.jraska.falcon.sample.Assumptions.assumeNoCI;
import static com.jraska.falcon.sample.asserts.BitmapAssert.assertThatBitmap;
import static com.jraska.falcon.sample.asserts.BitmapFileAssert.assertThatFile;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ private static int decideBitmapTraversalStep(Bitmap bitmap) {
return 1;
} else if (countOfPixels < 1024 * 768) {
return 2;
} else {
} else if (countOfPixels < 1600 * 1200) {
return 4;
} else {
return 8;
}
}
}

0 comments on commit aff304d

Please sign in to comment.