package org.ccci.gto.android.common.db;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import android.support.annotation.NonNull;

import org.junit.Test;

public class TableTest {
    private final TestDao dao = new TestDao();

    @Test
    public void testBuildSqlName() throws Exception {
        final Table<Obj1> t1 = Table.forClass(Obj1.class);
        final Table<Obj2> t2 = Table.forClass(Obj2.class);

        assertEquals(Obj1.TABLE_NAME, t1.sqlTable(dao));
        assertEquals(Obj1.TABLE_NAME + " AS a", t1.as("a").sqlTable(dao));
        assertEquals(Obj1.TABLE_NAME + " AS abcde", t1.as("abcde").sqlTable(dao));
        assertNotEquals(Obj2.TABLE_NAME, t1.sqlTable(dao));

        assertEquals(Obj2.TABLE_NAME, t2.sqlTable(dao));
        assertEquals(Obj2.TABLE_NAME + " AS b", t2.as("b").sqlTable(dao));
    }

    static class Obj1 {
        final static String TABLE_NAME = "Table1";
    }

    static class Obj2 {
        final static String TABLE_NAME = "Table2";
    }

    private static class TestDao extends AbstractDao {
        @SuppressWarnings("ConstantConditions")
        protected TestDao() {
            super(null);
        }

        @NonNull
        @Override
        protected String getTable(@NonNull final Class<?> clazz) {
            if (Obj1.class.equals(clazz)) {
                return Obj1.TABLE_NAME;
            } else if (Obj2.class.equals(clazz)) {
                return Obj2.TABLE_NAME;
            } else {
                return super.getTable(clazz);
            }
        }
    }
}

@@ -34,16 +34,40 @@
 on.db;%0A%0A
+import org.junit.Test;%0A%0A
 import s
@@ -156,76 +156,8 @@
 s;%0A%0A
-import android.support.annotation.NonNull;%0A%0Aimport org.junit.Test;%0A%0A
 publ
@@ -1157,368 +1157,145 @@
     
-%7D%0A%0A        @NonNull%0A        @Override%0A        protected String getTable(@NonNull final Class%3C?%3E clazz) %7B%0A            if (Obj1.class.equals(clazz)) %7B%0A                return Obj1.TABLE_NAME;%0A            %7D else if (Obj2.class.equals(clazz)) %7B%0A                return Obj2.TABLE_NAME;%0A            %7D else %7B%0A                return super.getTable(clazz);%0A            %7D
+    registerType(Obj1.class, Obj1.TABLE_NAME, null, null, null);%0A            registerType(Obj2.class, Obj2.TABLE_NAME, null, null, null);
 %0A   

switch TableTest to new registerType method