Convert DI, SQL tests to robolectric

pull/46/head
Alex Baker 11 years ago
parent 292f418c5c
commit 20fc7c51eb

@ -5,12 +5,20 @@
*/
package com.todoroo.andlib.service;
import android.test.AndroidTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import java.lang.reflect.Field;
public class DependencyInjectionTests extends AndroidTestCase {
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
@RunWith(RobolectricTestRunner.class)
public class DependencyInjectionTest {
@Test
public void testNoAutowire() {
DependencyInjectionService service = new DependencyInjectionService();
@ -18,6 +26,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
service.inject(test);
}
@Test
public void testSimpleStringInjectionAutowire() {
DependencyInjectionService service = new DependencyInjectionService();
service.addInjector(
@ -94,6 +103,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
assertNull( test.toString());
}
@Test
public void testHierarchicalStringInjectionAutowire() {
DependencyInjectionService service = new DependencyInjectionService();
service.addInjector(
@ -141,6 +151,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
assertEquals("malarkey", test.toString());
}
@Test
public void testMissingInjection() {
DependencyInjectionService service = new DependencyInjectionService();
service.addInjector(
@ -175,6 +186,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
assertNull(test.toString());
}
@Test
public void testMultipleInjection() {
DependencyInjectionService service = new DependencyInjectionService();
service.addInjector(
@ -223,6 +235,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
protected String bar;
}
@Test
public void testInheritedInjection() {
DependencyInjectionService service = new DependencyInjectionService();
service.addInjector(

@ -5,18 +5,24 @@
*/
package com.todoroo.andlib.sql;
import android.test.AndroidTestCase;
import com.todoroo.andlib.sql.Query.QueryTemplateHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task;
public class QueryTemplateHelperTest extends AndroidTestCase {
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertEquals;
@RunWith(RobolectricTestRunner.class)
public class QueryTemplateHelperTest {
public StringBuilder selection = new StringBuilder();
public StringBuilder order = new StringBuilder();
public StringBuilder groupBy = new StringBuilder();
@Test
public void testBasic() {
QueryTemplateHelper.queryForContentResolver("",
selection, order, groupBy);
@ -25,6 +31,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "");
}
@Test
public void testSelection() {
QueryTemplateHelper.queryForContentResolver("WHERE foo = bar",
selection, order, groupBy);
@ -33,6 +40,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "");
}
@Test
public void testOrder() {
QueryTemplateHelper.queryForContentResolver("ORDER BY cats",
selection, order, groupBy);
@ -41,6 +49,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "");
}
@Test
public void testWhereOrder() {
QueryTemplateHelper.queryForContentResolver("WHERE foo = bar ORDER BY cats",
selection, order, groupBy);
@ -49,6 +58,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "");
}
@Test
public void testGroupBy() {
QueryTemplateHelper.queryForContentResolver("GROUP BY dogs",
selection, order, groupBy);
@ -57,6 +67,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "dogs");
}
@Test
public void testWhereGroupBy() {
QueryTemplateHelper.queryForContentResolver("WHERE foo = bar GROUP BY dogs",
selection, order, groupBy);
@ -65,6 +76,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "dogs");
}
@Test
public void testOrderGroupBy() {
QueryTemplateHelper.queryForContentResolver("GROUP BY dogs ORDER BY cats",
selection, order, groupBy);
@ -72,6 +84,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "dogs");
}
@Test
public void testWhereGroupByAndOrder() {
QueryTemplateHelper.queryForContentResolver("WHERE foo = bar GROUP BY dogs ORDER BY cats",
selection, order, groupBy);
@ -80,6 +93,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(groupBy.toString(), "dogs");
}
@Test
public void testRealQueryTemplate() {
QueryTemplateHelper.queryForContentResolver(
new QueryTemplate().where(TaskCriteria.completed()).
@ -90,6 +104,7 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals("", groupBy.toString());
}
@Test
public void testRealQueryTemplateTwo() {
QueryTemplateHelper.queryForContentResolver(
new QueryTemplate().where(TaskCriteria.isActive()).
@ -99,7 +114,4 @@ public class QueryTemplateHelperTest extends AndroidTestCase {
assertEquals(Order.asc(Task.ELAPSED_SECONDS).toString(), order.toString());
assertEquals(Task.NOTES.toString(), groupBy.toString());
}
}

@ -5,12 +5,18 @@
*/
package com.todoroo.astrid.service;
import android.test.AndroidTestCase;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
public class AstridDependencyInjectorTests extends AndroidTestCase {
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.assertTrue;
@RunWith(RobolectricTestRunner.class)
public class AstridDependencyInjectorTest {
protected static class Helper {
public Object getObject() {
@ -18,16 +24,15 @@ public class AstridDependencyInjectorTests extends AndroidTestCase {
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
// in case some state from other unit tests overwrote injector
DependencyInjectionService.getInstance().addInjector(
new AstridDependencyInjector()
);
}
@Test
public void testWithString() {
Helper helper = new Helper() {
@Autowired
@ -43,6 +48,7 @@ public class AstridDependencyInjectorTests extends AndroidTestCase {
assertTrue(((String)helper.getObject()).length() > 0);
}
@Test
public void testWithClass() {
Helper helper = new Helper() {
Loading…
Cancel
Save