improve the tests
This commit is contained in:
parent
ee0ade4050
commit
90870af15f
9 changed files with 75 additions and 44 deletions
|
@ -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<Activity> {
|
||||
public class BaseTest extends InstrumentationTestCase {
|
||||
|
||||
public BaseTest() {
|
||||
super(Activity.class);
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Integer> probe = new HashSet<>();
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class TheEmptyTicketList extends BaseIntegration<TicketListActivity> {
|
|||
}
|
||||
|
||||
@MediumTest
|
||||
public void test_that_empty_view_is_there_without_passes() {
|
||||
public void testEmptyViewIsThereWhenThereAreNoPasses() {
|
||||
|
||||
onView(withId(R.id.emptyView)).check(matches(isDisplayed()));
|
||||
|
||||
|
|
|
@ -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<FullscreenBarc
|
|||
super(FullscreenBarcodeActivity.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -45,11 +44,10 @@ public class TheFullscreenBarcodeActivity extends BaseIntegration<FullscreenBarc
|
|||
App.getPassStore().setCurrentPass(list.get(0));
|
||||
|
||||
TraceDroid.deleteStacktraceFiles();
|
||||
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void test_that_pdf417_barcode_works() {
|
||||
public void testPDF417BarcodeIsShown() {
|
||||
testWithBarcodeFormat(BarcodeFormat.PDF_417);
|
||||
|
||||
Spoon.screenshot(getActivity(), "pdf417_barcode");
|
||||
|
@ -57,7 +55,7 @@ public class TheFullscreenBarcodeActivity extends BaseIntegration<FullscreenBarc
|
|||
|
||||
|
||||
@MediumTest
|
||||
public void test_that_aztec_barcode_works() {
|
||||
public void testAztecBarcodeIsShown() {
|
||||
testWithBarcodeFormat(BarcodeFormat.AZTEC);
|
||||
|
||||
Spoon.screenshot(getActivity(), "aztec_barcode");
|
||||
|
@ -65,7 +63,7 @@ public class TheFullscreenBarcodeActivity extends BaseIntegration<FullscreenBarc
|
|||
|
||||
|
||||
@MediumTest
|
||||
public void test_that_qr_barcode_works() {
|
||||
public void testQRCodeIsShown() {
|
||||
testWithBarcodeFormat(BarcodeFormat.QR_CODE);
|
||||
|
||||
Spoon.screenshot(getActivity(), "qr_barcode");
|
||||
|
|
|
@ -25,14 +25,17 @@ public class TheHelpActivity extends BaseIntegration<HelpActivity> {
|
|||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -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<TicketListActivity> {
|
|||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -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<TicketViewActivity> {
|
|||
}
|
||||
|
||||
@MediumTest
|
||||
public void test_click_on_barcode_opens_fullscreen_barcode() {
|
||||
public void testClickOnBarcodeOpensFullscreenImage() {
|
||||
getActivity();
|
||||
onView(withId(R.id.barcode_img)).perform(click());
|
||||
|
||||
|
|
|
@ -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<Activity> {
|
||||
|
||||
@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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue