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

import android.support.test.runner.AndroidJUnit4;
import android.test.InstrumentationTestCase;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.ccci.gto.android.common.db.TestDao.TestContract.RootTable;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

@RunWith(AndroidJUnit4.class)
public class ExpressionTest extends InstrumentationTestCase {

    private TestDao getDao() {
        return new TestDao(getInstrumentation().getContext());
    }

    @Test
    public void testEqualsSql() {
        final TestDao dao = getDao();

        Expression equalsExpression = RootTable.FIELD_TEST.eq("1");
        assertThat(equalsExpression.buildSql(dao).first, is("(root.test == ?)"));
    }

    @Test
    public void testNotEqualsSql() {
        final TestDao dao = getDao();

        Expression notEqualsExpression = RootTable.FIELD_TEST.not().eq("1");
        assertThat(notEqualsExpression.buildSql(dao).first, is("(NOT (root.test) == ?)"));
    }
}

@@ -1045,11 +1045,502 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testCount() %7B%0A        final TestDao dao = getDao();%0A%0A        Expression countExpression = RootTable.FIELD_TEST.count();%0A        assertThat(countExpression.buildSql(dao).first, is(%22COUNT (root.test)%22));%0A    %7D%0A%0A    @Test%0A    public void testCountInHaving() %7B%0A        final TestDao dao = getDao();%0A%0A        Expression countExpression = RootTable.FIELD_TEST.count().eq(1);%0A        assertThat(countExpression.buildSql(dao).first, is(%22(COUNT (root.test) == 1)%22));%0A    %7D
 %0A%7D%0A

Add test for count method