1 /* 2 * Copyright 2018 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 17 package androidx.sqlite.db; 18 19 import static org.hamcrest.CoreMatchers.is; 20 import static org.hamcrest.MatcherAssert.assertThat; 21 import static org.mockito.Mockito.verify; 22 import static org.mockito.Mockito.verifyNoMoreInteractions; 23 24 import org.junit.Test; 25 import org.junit.runner.RunWith; 26 import org.junit.runners.JUnit4; 27 import org.mockito.Mockito; 28 29 @RunWith(JUnit4.class) 30 public class SimpleSQLiteQueryTestTest { 31 32 @Test 33 public void getSql() { 34 SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo"); 35 assertThat(query.getSql(), is("foo")); 36 } 37 38 @Test 39 public void bindTo_noArgs() { 40 SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo"); 41 SupportSQLiteProgram program = Mockito.mock(SupportSQLiteProgram.class); 42 query.bindTo(program); 43 verifyNoMoreInteractions(program); 44 } 45 46 @Test 47 public void bindTo_withArgs() { 48 byte[] bytes = new byte[3]; 49 SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo", 50 new Object[]{"bar", 2, true, .5f, null, bytes}); 51 SupportSQLiteProgram program = Mockito.mock(SupportSQLiteProgram.class); 52 query.bindTo(program); 53 verify(program).bindString(1, "bar"); 54 verify(program).bindLong(2, 2); 55 verify(program).bindLong(3, 1); 56 verify(program).bindDouble(4, .5f); 57 verify(program).bindNull(5); 58 verify(program).bindBlob(6, bytes); 59 verifyNoMoreInteractions(program); 60 } 61 62 @Test 63 public void getArgCount_withArgs() { 64 SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo", 65 new Object[]{"bar", 2, true}); 66 assertThat(query.getArgCount(), is(3)); 67 } 68 69 @Test 70 public void getArgCount_noArgs() { 71 SimpleSQLiteQuery query = new SimpleSQLiteQuery("foo"); 72 assertThat(query.getArgCount(), is(0)); 73 } 74 } 75