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());
}
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"));
}
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"));
}
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();
}
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));
}
Aggregations