diff --git a/src/androidTest/java/org/ligi/passandroid/BaseTest.java b/src/androidTest/java/org/ligi/passandroid/BaseTest.java index 5ce20f53..0445f649 100644 --- a/src/androidTest/java/org/ligi/passandroid/BaseTest.java +++ b/src/androidTest/java/org/ligi/passandroid/BaseTest.java @@ -1,13 +1,11 @@ package org.ligi.passandroid; -import android.app.Activity; -import android.test.ActivityInstrumentationTestCase2; +import android.test.InstrumentationTestCase; -public class BaseTest extends ActivityInstrumentationTestCase2 { +public class BaseTest extends InstrumentationTestCase { public BaseTest() { - super(Activity.class); + super(); } - } diff --git a/src/androidTest/java/org/ligi/passandroid/TheBarcodeHelper.java b/src/androidTest/java/org/ligi/passandroid/TheBarcodeHelper.java index b8408b2f..e7993c0c 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheBarcodeHelper.java +++ b/src/androidTest/java/org/ligi/passandroid/TheBarcodeHelper.java @@ -13,30 +13,49 @@ import static org.fest.assertions.api.Assertions.assertThat; public class TheBarcodeHelper extends BaseTest { - public static final BarcodeFormat PDF_417 = BarcodeFormat.PDF_417; - @SmallTest - public void QRShouldWork() throws Exception { - testFormat(BarcodeFormat.QR_CODE); + public void testQRBitmatrixHasCorrectSize() throws Exception { + testBitMatrixSize(BarcodeFormat.QR_CODE); } @SmallTest - public void PDF417ShouldWork() { - testFormat(BarcodeFormat.PDF_417); + public void testQRBitmapHasCorrectSize() throws Exception { + testBitmapSize(BarcodeFormat.QR_CODE); } @SmallTest - public void AZTECFormatShouldWork() { - testFormat(BarcodeFormat.AZTEC); - + public void testPDF417BitmapHasCorrectSize() { + testBitmapSize(BarcodeFormat.PDF_417); } - public void testFormat(BarcodeFormat format) { + @SmallTest + public void testPDF417BitmatrixHasCorrectSize() { + testBitMatrixSize(BarcodeFormat.PDF_417); + } + + @SmallTest + public void testAZTECBitmapHasCorrectSize() { + testBitmapSize(BarcodeFormat.AZTEC); + } + + @SmallTest + public void testAZTECBitMatrixHasCorrectSize() { + testBitMatrixSize(BarcodeFormat.AZTEC); + } + + public void testBitMatrixSize(final BarcodeFormat format) { try { BitMatrix tested = BarcodeHelper.getBitMatrix("foo-data", format, 42); assertThat(tested.getWidth()).isGreaterThanOrEqualTo(42); + } catch (Exception e) { + fail("could not create barcode " + e); + } + } + + public void testBitmapSize(final BarcodeFormat format) { + try { Bitmap tested2 = BarcodeHelper.generateBarCodeBitmap("foo-data", format, 42); assertThat(tested2.getWidth()).isGreaterThanOrEqualTo(42); diff --git a/src/androidTest/java/org/ligi/passandroid/TheCategoryHelper.java b/src/androidTest/java/org/ligi/passandroid/TheCategoryHelper.java index 644de0c2..3de9bdde 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheCategoryHelper.java +++ b/src/androidTest/java/org/ligi/passandroid/TheCategoryHelper.java @@ -14,7 +14,7 @@ import static org.fest.assertions.api.Assertions.assertThat; public class TheCategoryHelper extends BaseTest { @SmallTest - public void test_all_categories_should_b_translated() { + public void testAllCategoriesAreTranslated() { final Set probe = new HashSet<>(); diff --git a/src/androidTest/java/org/ligi/passandroid/TheEmptyTicketList.java b/src/androidTest/java/org/ligi/passandroid/TheEmptyTicketList.java index 76af3a6e..6471203e 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheEmptyTicketList.java +++ b/src/androidTest/java/org/ligi/passandroid/TheEmptyTicketList.java @@ -30,7 +30,7 @@ public class TheEmptyTicketList extends BaseIntegration { } @MediumTest - public void test_that_empty_view_is_there_without_passes() { + public void testEmptyViewIsThereWhenThereAreNoPasses() { onView(withId(R.id.emptyView)).check(matches(isDisplayed())); diff --git a/src/androidTest/java/org/ligi/passandroid/TheFullscreenBarcodeActivity.java b/src/androidTest/java/org/ligi/passandroid/TheFullscreenBarcodeActivity.java index 7ee4a029..a8ea8815 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheFullscreenBarcodeActivity.java +++ b/src/androidTest/java/org/ligi/passandroid/TheFullscreenBarcodeActivity.java @@ -9,8 +9,8 @@ import com.squareup.spoon.Spoon; import org.ligi.passandroid.helper.BarcodeDecoder; import org.ligi.passandroid.injections.FixedPassListPassStore; -import org.ligi.passandroid.model.PassImpl; import org.ligi.passandroid.model.Pass; +import org.ligi.passandroid.model.PassImpl; import org.ligi.passandroid.ui.FullscreenBarcodeActivity; import org.ligi.tracedroid.TraceDroid; @@ -32,7 +32,6 @@ public class TheFullscreenBarcodeActivity extends BaseIntegration { } @SmallTest - public void test_that_help_is_there() { + public void testHelpIsThere() { onView(withId(R.id.help_tv)).check(matches(isDisplayed())); Spoon.screenshot(getActivity(), "help"); } + /* + depends on this: http://stackoverflow.com/questions/23985181/click-home-icon-with-espresso @SmallTest public void test_that_help_finishes_on_home() { - //onView(withId(android.R.id.home)).perform(click()); + onView(withId(android.R.id.home)).perform(click()); } + */ } diff --git a/src/androidTest/java/org/ligi/passandroid/TheTicketListActivity.java b/src/androidTest/java/org/ligi/passandroid/TheTicketListActivity.java index 1c65bc9f..d0cf700b 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheTicketListActivity.java +++ b/src/androidTest/java/org/ligi/passandroid/TheTicketListActivity.java @@ -6,8 +6,8 @@ import android.test.suitebuilder.annotation.MediumTest; import com.squareup.spoon.Spoon; import org.ligi.passandroid.injections.FixedPassListPassStore; -import org.ligi.passandroid.model.PassImpl; import org.ligi.passandroid.model.Pass; +import org.ligi.passandroid.model.PassImpl; import org.ligi.passandroid.ui.TicketListActivity; import java.util.ArrayList; @@ -40,29 +40,30 @@ public class TheTicketListActivity extends BaseIntegration { } @MediumTest - public void test_that_list_is_there() { + public void testListIsThere() { onView(withId(R.id.content_list)).check(matches(isDisplayed())); Spoon.screenshot(getActivity(), "list"); } @MediumTest - public void test_help_goes_to_help() { + public void testHelpMenuBringsUsToHelp() { onView(withId(R.id.menu_help)).perform(click()); onView(withId(R.id.help_tv)).check(matches(isDisplayed())); } @MediumTest - public void test_that_navigation_drawer_usualy_not_shown() { + public void testNavigationDrawerIsUsuallyNotShown() { onView(withId(R.id.left_drawer)).check(matches(not(isDisplayed()))); } + /* @MediumTest - - public void test_that_navigation_drawer_opens() { + public void testThatNavigationDrawerOpens() { //onView(withId(android.R.id.home)).perform(click()); //onView(withId(R.id.left_drawer)).check(matches(isDisplayed())); Spoon.screenshot(getActivity(), "open_drawer"); } + */ } diff --git a/src/androidTest/java/org/ligi/passandroid/TheTicketViewActivity.java b/src/androidTest/java/org/ligi/passandroid/TheTicketViewActivity.java index b50187fc..9493f417 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheTicketViewActivity.java +++ b/src/androidTest/java/org/ligi/passandroid/TheTicketViewActivity.java @@ -7,8 +7,8 @@ import com.google.common.base.Optional; import org.joda.time.DateTime; import org.ligi.passandroid.injections.FixedPassListPassStore; -import org.ligi.passandroid.model.PassImpl; import org.ligi.passandroid.model.Pass; +import org.ligi.passandroid.model.PassImpl; import org.ligi.passandroid.ui.TicketViewActivity; import java.util.ArrayList; @@ -86,7 +86,7 @@ public class TheTicketViewActivity extends BaseIntegration { } @MediumTest - public void test_click_on_barcode_opens_fullscreen_barcode() { + public void testClickOnBarcodeOpensFullscreenImage() { getActivity(); onView(withId(R.id.barcode_img)).perform(click()); diff --git a/src/androidTest/java/org/ligi/passandroid/TheUnzipPassController.java b/src/androidTest/java/org/ligi/passandroid/TheUnzipPassController.java index 7219a44a..32222012 100644 --- a/src/androidTest/java/org/ligi/passandroid/TheUnzipPassController.java +++ b/src/androidTest/java/org/ligi/passandroid/TheUnzipPassController.java @@ -5,32 +5,44 @@ import android.test.suitebuilder.annotation.SmallTest; import org.ligi.passandroid.model.InputStreamWithSource; import org.ligi.passandroid.ui.UnzipPassController; +import org.mockito.MockitoAnnotations; import java.io.InputStream; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + public class TheUnzipPassController extends BaseIntegration { + @MockitoAnnotations.Mock + UnzipPassController.FailCallback failCallback; + + @MockitoAnnotations.Mock + UnzipPassController.SuccessCallback successCallback; + + @Override + public void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + } + public TheUnzipPassController() { super(Activity.class); } @SmallTest - public void test_should_decompress_all_passes() { + public void testShouldFailForBrokenPass() { try { + final InputStream inputStream = getInstrumentation().getContext().getResources().getAssets().open("passes/broken/fail.pkpass"); final InputStreamWithSource inputStreamWithSource = new InputStreamWithSource("none", inputStream); - UnzipPassController.processInputStream(inputStreamWithSource, getInstrumentation().getTargetContext(), new UnzipPassController.SuccessCallback() { - @Override - public void call(String pathToPassbook) { - TheUnzipPassController.fail("should not succeed for broken pass"); - } - }, new UnzipPassController.FailCallback() { - @Override - public void fail(String reason) { + UnzipPassController.processInputStream(inputStreamWithSource, getInstrumentation().getTargetContext(), successCallback, failCallback); + + verify(successCallback, never()).call(any(String.class)); + verify(failCallback).fail(any(String.class)); - } - }); } catch (Exception e) { fail("should be able to load file"); }