1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package androidx.room.integration.testapp.test; 18 19import static org.hamcrest.CoreMatchers.is; 20import static org.hamcrest.MatcherAssert.assertThat; 21 22import android.os.Build; 23import android.support.test.filters.SdkSuppress; 24import android.support.test.filters.SmallTest; 25import android.support.test.runner.AndroidJUnit4; 26 27import androidx.room.integration.testapp.vo.User; 28 29import org.junit.Test; 30import org.junit.runner.RunWith; 31 32import java.util.ArrayList; 33import java.util.Arrays; 34import java.util.List; 35 36@RunWith(AndroidJUnit4.class) 37@SmallTest 38@SdkSuppress(minSdkVersion = Build.VERSION_CODES.LOLLIPOP) 39public class WithClauseTest extends TestDatabaseTest{ 40 @Test 41 public void noSourceOfData() { 42 @SuppressWarnings("ArraysAsListWithZeroOrOneArgument") 43 List<Integer> expected = Arrays.asList(1); 44 List<Integer> actual = mWithClauseDao.getFactorials(0); 45 assertThat(expected, is(actual)); 46 47 expected = Arrays.asList(1, 1, 2, 6, 24); 48 actual = mWithClauseDao.getFactorials(4); 49 assertThat(expected, is(actual)); 50 } 51 52 @Test 53 public void sourceOfData() { 54 List<String> expected = new ArrayList<>(); 55 List<String> actual = mWithClauseDao.getUsersWithFactorialIds(0); 56 assertThat(expected, is(actual)); 57 58 User user = new User(); 59 user.setId(0); 60 user.setName("Zero"); 61 mUserDao.insert(user); 62 actual = mWithClauseDao.getUsersWithFactorialIds(0); 63 assertThat(expected, is(actual)); 64 65 user = new User(); 66 user.setId(1); 67 user.setName("One"); 68 mUserDao.insert(user); 69 expected.add("One"); 70 actual = mWithClauseDao.getUsersWithFactorialIds(0); 71 assertThat(expected, is(actual)); 72 73 user = new User(); 74 user.setId(6); 75 user.setName("Six"); 76 mUserDao.insert(user); 77 actual = mWithClauseDao.getUsersWithFactorialIds(0); 78 assertThat(expected, is(actual)); 79 80 actual = mWithClauseDao.getUsersWithFactorialIds(3); 81 expected.add("Six"); 82 assertThat(expected, is(actual)); 83 } 84} 85