| 27 | public class TestSchema { |
| 28 | |
| 29 | @Test |
| 30 | public void testEquals() { |
| 31 | final ColumnSchema col1 = new ColumnSchema.ColumnSchemaBuilder("c0", Type.INT32) |
| 32 | .nullable(false) |
| 33 | .key(true) |
| 34 | .build(); |
| 35 | final ColumnSchema col2 = new ColumnSchema.ColumnSchemaBuilder("c1", Type.INT32) |
| 36 | .nullable(false) |
| 37 | .build(); |
| 38 | |
| 39 | ArrayList<ColumnSchema> columns = new ArrayList<>(); |
| 40 | columns.add(col1); |
| 41 | columns.add(col2); |
| 42 | final Schema schema = new Schema(columns); |
| 43 | |
| 44 | ArrayList<ColumnSchema> columns1 = new ArrayList<>(); |
| 45 | columns1.add(col1); |
| 46 | columns1.add(col2); |
| 47 | final Schema schema1 = new Schema(columns1); |
| 48 | |
| 49 | // Two objects are the same. |
| 50 | assertTrue(schema1.equals(schema1)); |
| 51 | // One of object is not type of 'Schema'. |
| 52 | assertFalse(schema1.equals(columns1)); |
| 53 | // Two schemas are the same structure. |
| 54 | assertTrue(schema1.equals(schema)); |
| 55 | |
| 56 | final ColumnSchema col3 = new ColumnSchema.ColumnSchemaBuilder("c2", Type.INT32) |
| 57 | .nullable(false) |
| 58 | .key(true) |
| 59 | .build(); |
| 60 | |
| 61 | ArrayList<ColumnSchema> columns2 = new ArrayList<>(); |
| 62 | columns2.add(col1); |
| 63 | columns2.add(col3); |
| 64 | final Schema schema2 = new Schema(columns2); |
| 65 | |
| 66 | // Two schemas have different number of primary keys. |
| 67 | assertFalse(schema1.equals(schema2)); |
| 68 | |
| 69 | ArrayList<ColumnSchema> columns3 = new ArrayList<>(); |
| 70 | columns3.add(col1); |
| 71 | columns3.add(col2); |
| 72 | columns3.add(col3); |
| 73 | final Schema schema3 = new Schema(columns3); |
| 74 | |
| 75 | // Two schemas have different number of columns. |
| 76 | assertFalse(schema1.equals(schema3)); |
| 77 | |
| 78 | final ColumnSchema col4 = new ColumnSchema.ColumnSchemaBuilder("c3", Type.INT32) |
| 79 | .nullable(false) |
| 80 | .build(); |
| 81 | |
| 82 | ArrayList<ColumnSchema> columns4 = new ArrayList<>(); |
| 83 | columns4.add(col1); |
| 84 | columns4.add(col2); |
| 85 | columns4.add(col4); |
| 86 | final Schema schema4 = new Schema(columns4); |