Search in sources :

Example 1 with SdkSuppress

use of android.support.test.filters.SdkSuppress in project material-components-android by material-components.

the class CoordinatorLayoutTest method testSetFitSystemWindows.

@Test
@TargetApi(21)
@SdkSuppress(minSdkVersion = 21)
public void testSetFitSystemWindows() throws Throwable {
    final CoordinatorLayout col = activityTestRule.getActivity().mCoordinatorLayout;
    final View view = new View(col.getContext());
    // Create a mock which calls the default impl of onApplyWindowInsets()
    final CoordinatorLayout.Behavior<View> mockBehavior = mock(CoordinatorLayout.Behavior.class);
    doCallRealMethod().when(mockBehavior).onApplyWindowInsets(same(col), same(view), any(WindowInsetsCompat.class));
    // Assert that the CoL is currently not set to fitSystemWindows
    assertFalse(col.getFitsSystemWindows());
    // Now add a view with our mocked behavior to the CoordinatorLayout
    view.setFitsSystemWindows(true);
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final CoordinatorLayout.LayoutParams lp = col.generateDefaultLayoutParams();
            lp.setBehavior(mockBehavior);
            col.addView(view, lp);
        }
    });
    getInstrumentation().waitForIdleSync();
    // Now request some insets and wait for the pass to happen
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            col.requestApplyInsets();
        }
    });
    getInstrumentation().waitForIdleSync();
    // Verify that onApplyWindowInsets() has not been called
    verify(mockBehavior, never()).onApplyWindowInsets(same(col), same(view), any(WindowInsetsCompat.class));
    // Now enable fits system windows and wait for a pass to happen
    activityTestRule.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            col.setFitsSystemWindows(true);
        }
    });
    getInstrumentation().waitForIdleSync();
    // Verify that onApplyWindowInsets() has been called with some insets
    verify(mockBehavior, atLeastOnce()).onApplyWindowInsets(same(col), same(view), any(WindowInsetsCompat.class));
}
Also used : WindowInsetsCompat(android.support.v4.view.WindowInsetsCompat) ImageView(android.widget.ImageView) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 2 with SdkSuppress

use of android.support.test.filters.SdkSuppress in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteAndTriggerWithMultipleTables.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteAndTriggerWithMultipleTables() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.NAME + " = 'Zach'");
    final RecordingObserver managerObserver = new RecordingObserver();
    db.createQuery(TABLE_MANAGER, SELECT_MANAGER_LIST).subscribe(managerObserver);
    managerObserver.assertCursor().hasRow("Eve Evenson", "Alice Allison").isExhausted();
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    final Set<String> employeeAndManagerTables = Collections.unmodifiableSet(new HashSet<>(BOTH_TABLES));
    db.executeUpdateDelete(employeeAndManagerTables, statement);
    o.assertCursor().hasRow("alice", "Zach").hasRow("bob", "Zach").hasRow("eve", "Zach").isExhausted();
    managerObserver.assertCursor().hasRow("Zach", "Zach").isExhausted();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 3 with SdkSuppress

use of android.support.test.filters.SdkSuppress in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteThrowsAndDoesNotTrigger.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteThrowsAndDoesNotTrigger() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.USERNAME + " = 'alice'");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).skip(// Skip initial
    1).subscribe(o);
    try {
        db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
        fail();
    } catch (SQLException ignored) {
    }
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 4 with SdkSuppress

use of android.support.test.filters.SdkSuppress in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteAndTriggerWithNoTables.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteAndTriggerWithNoTables() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.NAME + " = 'Zach'");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    db.executeUpdateDelete(Collections.<String>emptySet(), statement);
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 5 with SdkSuppress

use of android.support.test.filters.SdkSuppress in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteAndTrigger.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteAndTrigger() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.NAME + " = 'Zach'");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
    o.assertCursor().hasRow("alice", "Zach").hasRow("bob", "Zach").hasRow("eve", "Zach").isExhausted();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Aggregations

SdkSuppress (android.support.test.filters.SdkSuppress)11 Test (org.junit.Test)11 TargetApi (android.annotation.TargetApi)9 SQLiteStatement (android.database.sqlite.SQLiteStatement)7 SQLException (android.database.SQLException)2 UiObject2 (android.support.test.uiautomator.UiObject2)2 Espresso.onView (android.support.test.espresso.Espresso.onView)1 MediumTest (android.support.test.filters.MediumTest)1 WindowInsetsCompat (android.support.v4.view.WindowInsetsCompat)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 Transaction (com.squareup.sqlbrite.BriteDatabase.Transaction)1 Employee (com.squareup.sqlbrite.TestDb.Employee)1 CountDownLatch (java.util.concurrent.CountDownLatch)1