package com.orm.query;

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

import static junit.framework.Assert.assertEquals;

public class SelectTest {

    @Test
    public void testMergeCondition(){
        Select where = Select.from(TestRecord.class).where(Condition.prop("test").eq("satya"));
        assertEquals("test = ? ", where.getWhereCond());
        assertEquals(1, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);

        where = Select.from(TestRecord.class).where(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2));
        assertEquals("test = ?  AND prop = ? ", where.getWhereCond());
        assertEquals(2, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);
        assertEquals("2", where.getArgs()[1]);
    }


    @Test
    public void testWhere(){
        Select where = Select.from(TestRecord.class).where(Condition.prop("test").eq("satya"));
        assertEquals("test = ? ", where.getWhereCond());
        assertEquals(1, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);

        where = Select.from(TestRecord.class).where(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2));
        assertEquals("test = ?  AND prop = ? ", where.getWhereCond());
        assertEquals(2, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);
        assertEquals("2", where.getArgs()[1]);
    }


    @Test
    public void testWhereOr(){
        Select where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"));
        assertEquals("test = ? ", where.getWhereCond());
        assertEquals(1, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);

        where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"), Condition.prop("prop").eq(2));
        assertEquals("test = ?  OR prop = ? ", where.getWhereCond());
        assertEquals(2, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);
        assertEquals("2", where.getArgs()[1]);
    }

    @Test
    public void testAnd(){
        Select where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"));
        assertEquals("test = ? ", where.getWhereCond());
        assertEquals(1, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);

        where.and(Condition.prop("prop").eq(2));

        assertEquals("test = ?  AND prop = ? ", where.getWhereCond());
        assertEquals(2, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);
        assertEquals("2", where.getArgs()[1]);
    }

    @Test
    public void testOr(){
        Select where = Select.from(TestRecord.class).whereOr(Condition.prop("test").eq("satya"));
        assertEquals("test = ? ", where.getWhereCond());
        assertEquals(1, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);

        where.or(Condition.prop("prop").eq(2));

        assertEquals("test = ?  OR prop = ? ", where.getWhereCond());
        assertEquals(2, where.getArgs().length);
        assertEquals("satya", where.getArgs()[0]);
        assertEquals("2", where.getArgs()[1]);
    }


}

@@ -43,41 +43,8 @@
 est;
-%0Aimport org.junit.runner.RunWith;
 %0A%0Aim
@@ -278,32 +278,33 @@
   assertEquals(%22
+(
 test = ? %22, wher
@@ -288,32 +288,33 @@
 uals(%22(test = ? 
+)
 %22, where.getWher
@@ -557,32 +557,33 @@
   assertEquals(%22
+(
 test = ?  AND pr
@@ -581,32 +581,33 @@
 ?  AND prop = ? 
+)
 %22, where.getWher
@@ -920,32 +920,33 @@
   assertEquals(%22
+(
 test = ? %22, wher
@@ -930,32 +930,33 @@
 uals(%22(test = ? 
+)
 %22, where.getWher
@@ -1199,32 +1199,33 @@
   assertEquals(%22
+(
 test = ?  AND pr
@@ -1223,32 +1223,33 @@
 ?  AND prop = ? 
+)
 %22, where.getWher
@@ -1566,32 +1566,33 @@
   assertEquals(%22
+(
 test = ? %22, wher
@@ -1576,32 +1576,33 @@
 uals(%22(test = ? 
+)
 %22, where.getWher
@@ -1847,32 +1847,33 @@
   assertEquals(%22
+(
 test = ?  OR pro
@@ -1870,32 +1870,33 @@
  ?  OR prop = ? 
+)
 %22, where.getWher
@@ -2208,32 +2208,33 @@
   assertEquals(%22
+(
 test = ? %22, wher
@@ -2218,32 +2218,33 @@
 uals(%22(test = ? 
+)
 %22, where.getWher
@@ -2418,32 +2418,33 @@
   assertEquals(%22
+(
 test = ?  AND pr
@@ -2428,37 +2428,39 @@
 uals(%22(test = ? 
+)
  AND 
+(
 prop = ? %22, wher
@@ -2444,32 +2444,33 @@
 ) AND (prop = ? 
+)
 %22, where.getWher
@@ -2781,32 +2781,33 @@
   assertEquals(%22
+(
 test = ? %22, wher
@@ -2795,24 +2795,25 @@
 (%22(test = ? 
+)
 %22, where.get
@@ -2998,16 +2998,17 @@
 Equals(%22
+(
 test = ?
@@ -3000,36 +3000,38 @@
 uals(%22(test = ? 
+)
  OR 
+(
 prop = ? %22, wher
@@ -3023,16 +3023,17 @@
 rop = ? 
+)
 %22, where

Fix up some library tests