• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.util;
2 
3 import android.content.ContentValues;
4 import android.database.sqlite.SQLiteDatabase;
5 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.junit.runner.RunWith;
9 
10 import java.sql.SQLException;
11 
12 import static com.xtremelabs.robolectric.util.SQLite.buildInsertString;
13 import static org.hamcrest.CoreMatchers.equalTo;
14 import static org.junit.Assert.assertThat;
15 
16 @DatabaseConfig.UsingDatabaseMap(H2Map.class)
17 @RunWith(WithTestDefaultsRunner.class)
18 public class H2Test {
19     ContentValues values;
20     @Before
21 
setUp()22     public void setUp() throws Exception {
23         String byteString = "byte_string";
24         byte[] byteData = byteString.getBytes();
25 
26         values = new ContentValues();
27         values.put("name", "Chuck");
28         values.put("int_value", 33);
29         values.put("float_value", (float) 1.5);
30         values.put("byte_data", byteData);
31     }
32 
33     @Test
testBuildInsertString()34     public void testBuildInsertString() throws SQLException {
35         SQLite.SQLStringAndBindings insertString = buildInsertString("table_name", values, SQLiteDatabase.CONFLICT_REPLACE);
36         assertThat(insertString.sql, equalTo("INSERT INTO table_name (float_value, byte_data, name, int_value) VALUES (?, ?, ?, ?);"));
37         SQLiteTestHelper.verifyColumnValues(insertString.columnValues);
38     }
39 }
40