package com.orm.record;

import com.orm.app.ClientApp;
import com.orm.dsl.BuildConfig;
import com.orm.model.IntegerFieldAnnotatedModel;
import com.orm.model.IntegerFieldExtendedModel;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static com.orm.SugarRecord.save;
import static com.orm.SugarRecord.findById;

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

@RunWith(RobolectricGradleTestRunner.class)
@Config(sdk = 18, constants = BuildConfig.class, application = ClientApp.class, packageName = "com.orm.model", manifest = Config.NONE)
public final class IntegerFieldTests {
    private Integer integer = 25;

    @Test
    public void nullIntegerExtendedTest() {
        save(new IntegerFieldExtendedModel());
        IntegerFieldExtendedModel model = findById(IntegerFieldExtendedModel.class, 1);
        assertNull(model.getInteger());
    }

    @Test
    public void nullIntExtendedTest() {
        save(new IntegerFieldExtendedModel());
        IntegerFieldExtendedModel model = findById(IntegerFieldExtendedModel.class, 1);
        assertEquals(0, model.getInt());
    }

    @Test
    public void nullIntegerAnnotatedTest() {
        save(new IntegerFieldAnnotatedModel());
        IntegerFieldAnnotatedModel model = findById(IntegerFieldAnnotatedModel.class, 1);
        assertNull(model.getInteger());
    }

    @Test
    public void nullIntAnnotatedTest() {
        save(new IntegerFieldAnnotatedModel());
        IntegerFieldAnnotatedModel model = findById(IntegerFieldAnnotatedModel.class, 1);
        assertEquals(0, model.getInt());
    }

    @Test
    public void integerExtendedTest() {
        save(new IntegerFieldExtendedModel(integer));
        IntegerFieldExtendedModel model = findById(IntegerFieldExtendedModel.class, 1);
        assertEquals(integer, model.getInteger());
    }

    @Test
    public void intExtendedTest() {
        save(new IntegerFieldExtendedModel(integer.intValue()));
        IntegerFieldExtendedModel model = findById(IntegerFieldExtendedModel.class, 1);
        assertEquals(integer.intValue(), model.getInt());
    }

    @Test
    public void integerAnnotatedTest() {
        save(new IntegerFieldAnnotatedModel(integer));
        IntegerFieldAnnotatedModel model = findById(IntegerFieldAnnotatedModel.class, 1);
        assertEquals(integer, model.getInteger());
    }

    @Test
    public void intAnnotatedTest() {
        save(new IntegerFieldAnnotatedModel(integer.intValue()));
        IntegerFieldAnnotatedModel model = findById(IntegerFieldAnnotatedModel.class, 1);
        assertEquals(integer.intValue(), model.getInt());
    }
}

@@ -329,16 +329,60 @@
 onfig;%0A%0A
+import static com.orm.SugarRecord.findById;%0A
 import s
@@ -447,26 +447,20 @@
 rRecord.
-findById;%0A
+sum;
 %0Aimport 
@@ -2775,10 +2775,984 @@
 ;%0A    %7D%0A
+%0A%0A    @Test%0A    public void sumTest() %7B%0A        save(new IntegerFieldAnnotatedModel(integer.intValue()));%0A        save(new IntegerFieldAnnotatedModel(integer.intValue()));%0A        assertEquals(2 * integer, sum(IntegerFieldAnnotatedModel.class, %22raw_integer%22));%0A    %7D%0A%0A    @Test%0A    public void whereSumTest() %7B%0A        save(new IntegerFieldAnnotatedModel(integer.intValue()));%0A        save(new IntegerFieldAnnotatedModel(integer.intValue()));%0A        assertEquals((long) integer, sum(IntegerFieldAnnotatedModel.class,%0A                %22raw_integer%22, %22id = ?%22, new String%5B%5D%7B%221%22%7D));%0A    %7D%0A%0A    @Test%0A    public void noSumTest() %7B%0A        assertEquals(0, sum(IntegerFieldAnnotatedModel.class, %22raw_integer%22));%0A    %7D%0A%0A    @Test%0A    public void brokenSumTest() %7B%0A        save(new IntegerFieldAnnotatedModel(integer.intValue()));%0A        save(new IntegerFieldAnnotatedModel(integer.intValue()));%0A        assertEquals(-1, sum(IntegerFieldAnnotatedModel.class, %22wrongfield%22));%0A    %7D%0A
 %7D%0A

Add tests for sum()