Search in sources :

Example 1 with SdkSuppress

use of androidx.test.filters.SdkSuppress in project AnkiChinaAndroid by ankichinateam.

the class ImportTest method testCsv.

@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv() throws IOException {
    String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-2fields.txt");
    TextImporter i = new TextImporter(testCol, file);
    i.initMapping();
    i.run();
    if (TestEnvironment.isDisplayingDefaultEnglishStrings()) {
        assertThat(i.getLog(), contains("‘多すぎる too many fields’ had 3 fields, expected 2", "‘not, enough, fields’ had 1 fields, expected 2", "Appeared twice in file: 飲む", "Empty first field:  to play", "5 notes added, 0 notes updated, 0 notes unchanged."));
    } else {
        assertThat(i.getLog(), hasSize(5));
    }
    assertEquals(5, i.getTotal());
    // if we run the import again, it should update instead
    i.run();
    if (TestEnvironment.isDisplayingDefaultEnglishStrings()) {
        assertThat(i.getLog(), contains("‘多すぎる too many fields’ had 3 fields, expected 2", "‘not, enough, fields’ had 1 fields, expected 2", "Appeared twice in file: 飲む", "Empty first field:  to play", "0 notes added, 0 notes updated, 5 notes unchanged.", "First field matched: 食べる", "First field matched: 飲む", "First field matched: テスト", "First field matched: to eat", "First field matched: 遊ぶ"));
    } else {
        assertThat(i.getLog(), hasSize(10));
    }
    assertEquals(5, i.getTotal());
    // but importing should not clobber tags if they're unmapped
    Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
    n.addTag("test");
    n.flush();
    i.run();
    n.load();
    assertThat(n.getTags(), contains("test"));
    assertThat(n.getTags(), hasSize(1));
    // if add-only mode, count will be 0
    i.setImportMode(NoteImporter.ImportMode.IGNORE_MODE);
    i.run();
    assertEquals(0, i.getTotal());
    // and if dupes mode, will reimport everything
    assertEquals(5, testCol.cardCount());
    i.setImportMode(NoteImporter.ImportMode.ADD_MODE);
    i.run();
    // includes repeated field
    assertEquals(6, i.getTotal());
    assertEquals(11, testCol.cardCount());
}
Also used : Note(com.ichi2.libanki.Note) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 2 with SdkSuppress

use of androidx.test.filters.SdkSuppress in project AnkiChinaAndroid by ankichinateam.

the class ImportTest method testCsvWithByteOrderMark.

@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsvWithByteOrderMark() throws IOException {
    String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-utf8-bom.txt");
    TextImporter i = new TextImporter(testCol, file);
    i.initMapping();
    i.run();
    Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
    assertThat(Arrays.asList(n.getFields()), contains("Hello", "world"));
}
Also used : Note(com.ichi2.libanki.Note) TextImporter(com.ichi2.libanki.importer.TextImporter) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 3 with SdkSuppress

use of androidx.test.filters.SdkSuppress in project AnkiChinaAndroid by ankichinateam.

the class ImportTest method testUcs2CsvWithByteOrderMark.

@Test
@Ignore("Not yet handled")
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testUcs2CsvWithByteOrderMark() throws IOException {
    String file = Shared.getTestFilePath(InstrumentationRegistry.getInstrumentation().getTargetContext(), "text-ucs2-be-bom.txt");
    TextImporter i = new TextImporter(testCol, file);
    i.initMapping();
    i.run();
    Note n = testCol.getNote(testCol.getDb().queryLongScalar("select id from notes"));
    assertThat(Arrays.asList(n.getFields()), contains("Hello", "world"));
}
Also used : Note(com.ichi2.libanki.Note) TextImporter(com.ichi2.libanki.importer.TextImporter) Ignore(org.junit.Ignore) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 4 with SdkSuppress

use of androidx.test.filters.SdkSuppress in project growingio-sdk-android-autotracker by growingio.

the class ViewClickEventsTest method toolBarClickTest.

@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP)
public void toolBarClickTest() {
    final AtomicBoolean receivedEvent = new AtomicBoolean(false);
    getEventsApiServer().setOnReceivedEventListener(new OnReceivedViewClickEventsListener(receivedEvent, new ViewElementEvent.Builder().setPath("/ToolBarActivity").setXpath("/Page/MenuView/MenuItem#navigation_home").setTextValue("Home").setIndex(-1).build(), new ViewElementEvent.Builder().setPath("/ToolBarActivity").setXpath("/Page/MenuView/MenuItem#navigation_dashboard").setTextValue("Dashboard").setIndex(-1).build(), new ViewElementEvent.Builder().setPath("/ToolBarActivity").setXpath("/Page/MenuView/MenuItem#navigation_notifications").setTextValue("Notifications").setIndex(-1).build()));
    ActivityScenario<ToolBarActivity> scenario = ActivityScenario.launch(ToolBarActivity.class);
    openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
    onView(withText("Home")).perform(click());
    openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
    onView(withText("Dashboard")).perform(click());
    openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext());
    onView(withText("Notifications")).perform(click());
    Awaiter.untilTrue(receivedEvent);
    scenario.close();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ViewElementEvent(com.growingio.android.sdk.track.events.ViewElementEvent) ToolBarActivity(com.gio.test.three.autotrack.activity.ToolBarActivity) EventsTest(com.growingio.autotest.EventsTest) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Example 5 with SdkSuppress

use of androidx.test.filters.SdkSuppress in project android-sdk by optimizely.

the class OptimizelyManagerTest method injectOptimizelyNullListener.

@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP)
public void injectOptimizelyNullListener() {
    Context context = mock(Context.class);
    PackageManager packageManager = mock(PackageManager.class);
    when(context.getPackageName()).thenReturn("com.optly");
    when(context.getApplicationContext()).thenReturn(context);
    when(context.getApplicationContext().getPackageManager()).thenReturn(packageManager);
    try {
        when(packageManager.getPackageInfo("com.optly", 0)).thenReturn(mock(PackageInfo.class));
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    UserProfileService userProfileService = mock(UserProfileService.class);
    ServiceScheduler serviceScheduler = mock(ServiceScheduler.class);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    ArgumentCaptor<DefaultUserProfileService.StartCallback> callbackArgumentCaptor = ArgumentCaptor.forClass(DefaultUserProfileService.StartCallback.class);
    optimizelyManager.setOptimizelyStartListener(null);
    optimizelyManager.injectOptimizely(context, userProfileService, minDatafile);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    ServiceScheduler.PendingIntentFactory pendingIntentFactory = new ServiceScheduler.PendingIntentFactory(context);
    Intent intent = new Intent(context, DatafileService.class);
    intent.putExtra(DatafileService.EXTRA_DATAFILE_CONFIG, optimizelyManager.getDatafileConfig().toJSONString());
    serviceScheduler.schedule(intent, optimizelyManager.getDatafileDownloadInterval() * 1000);
    try {
        executor.awaitTermination(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        fail("Timed out");
    }
    verify(logger).info("No listener to send Optimizely to");
    verify(serviceScheduler).schedule(captor.capture(), eq(TimeUnit.HOURS.toMillis(1L)));
    Intent intent2 = captor.getValue();
    assertTrue(intent2.getComponent().getShortClassName().contains("DatafileService"));
    assertEquals(optimizelyManager.getDatafileConfig().toJSONString(), intent2.getStringExtra(DatafileService.EXTRA_DATAFILE_CONFIG));
}
Also used : Context(android.content.Context) PackageInfo(android.content.pm.PackageInfo) DefaultUserProfileService(com.optimizely.ab.android.user_profile.DefaultUserProfileService) UserProfileService(com.optimizely.ab.bucketing.UserProfileService) Intent(android.content.Intent) ServiceScheduler(com.optimizely.ab.android.shared.ServiceScheduler) PackageManager(android.content.pm.PackageManager) AlarmManager(android.app.AlarmManager) DefaultUserProfileService(com.optimizely.ab.android.user_profile.DefaultUserProfileService) Test(org.junit.Test) SdkSuppress(androidx.test.filters.SdkSuppress)

Aggregations

SdkSuppress (androidx.test.filters.SdkSuppress)49 Test (org.junit.Test)48 Note (com.ichi2.libanki.Note)12 TextImporter (com.ichi2.libanki.importer.TextImporter)12 Intent (android.content.Intent)7 Theme (android.content.res.Resources.Theme)7 LargeTest (androidx.test.filters.LargeTest)7 InstrumentedTest (com.ichi2.anki.tests.InstrumentedTest)6 View (android.view.View)5 Config (org.robolectric.annotation.Config)5 TextView (android.widget.TextView)4 UiThreadTest (androidx.test.annotation.UiThreadTest)4 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)4 Typeface (android.graphics.Typeface)3 MediumTest (androidx.test.filters.MediumTest)2 ViewElementEvent (com.growingio.android.sdk.track.events.ViewElementEvent)2 EventsTest (com.growingio.autotest.EventsTest)2 Model (com.ichi2.libanki.Model)2 JSONObject (com.ichi2.utils.JSONObject)2 Cache (com.optimizely.ab.android.shared.Cache)2