1 /* 2 * Copyright (C) 2023 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 com.android.ondevicepersonalization.services.data.events; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertThrows; 21 22 import org.junit.Test; 23 import org.junit.runner.RunWith; 24 import org.junit.runners.JUnit4; 25 26 @RunWith(JUnit4.class) 27 public class ColumnSchemaTest { 28 @Test testBuilderAndEquals()29 public void testBuilderAndEquals() { 30 String columnName = "column"; 31 int sqlType = ColumnSchema.SQL_DATA_TYPE_INTEGER; 32 ColumnSchema columnSchema1 = new ColumnSchema.Builder().setName(columnName).setType( 33 sqlType).build(); 34 35 assertEquals(columnSchema1.getName(), columnName); 36 assertEquals(columnSchema1.getType(), sqlType); 37 38 ColumnSchema columnSchema2 = new ColumnSchema.Builder( 39 columnName, sqlType) 40 .build(); 41 assertEquals(columnSchema1, columnSchema2); 42 assertEquals(columnSchema1.hashCode(), columnSchema2.hashCode()); 43 } 44 45 @Test testToString()46 public void testToString() { 47 String columnName = "column"; 48 ColumnSchema columnSchema = new ColumnSchema.Builder().setName(columnName).setType( 49 ColumnSchema.SQL_DATA_TYPE_INTEGER).build(); 50 assertEquals(columnName + " " + "INTEGER", columnSchema.toString()); 51 52 columnSchema = new ColumnSchema.Builder().setName(columnName).setType( 53 ColumnSchema.SQL_DATA_TYPE_REAL).build(); 54 assertEquals(columnName + " " + "REAL", columnSchema.toString()); 55 56 columnSchema = new ColumnSchema.Builder().setName(columnName).setType( 57 ColumnSchema.SQL_DATA_TYPE_TEXT).build(); 58 assertEquals(columnName + " " + "TEXT", columnSchema.toString()); 59 60 columnSchema = new ColumnSchema.Builder().setName(columnName).setType( 61 ColumnSchema.SQL_DATA_TYPE_BLOB).build(); 62 assertEquals(columnName + " " + "BLOB", columnSchema.toString()); 63 64 65 } 66 67 @Test testBuildTwiceThrows()68 public void testBuildTwiceThrows() { 69 String columnName = "column"; 70 int sqlType = ColumnSchema.SQL_DATA_TYPE_INTEGER; 71 ColumnSchema.Builder builder = new ColumnSchema.Builder().setName(columnName).setType( 72 sqlType); 73 74 builder.build(); 75 assertThrows(IllegalStateException.class, builder::build); 76 } 77 } 78