Convert DI, SQL tests to robolectric

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

@ -5,12 +5,20 @@
*/ */
package com.todoroo.andlib.service; 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; 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() { public void testNoAutowire() {
DependencyInjectionService service = new DependencyInjectionService(); DependencyInjectionService service = new DependencyInjectionService();
@ -18,6 +26,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
service.inject(test); service.inject(test);
} }
@Test
public void testSimpleStringInjectionAutowire() { public void testSimpleStringInjectionAutowire() {
DependencyInjectionService service = new DependencyInjectionService(); DependencyInjectionService service = new DependencyInjectionService();
service.addInjector( service.addInjector(
@ -94,6 +103,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
assertNull( test.toString()); assertNull( test.toString());
} }
@Test
public void testHierarchicalStringInjectionAutowire() { public void testHierarchicalStringInjectionAutowire() {
DependencyInjectionService service = new DependencyInjectionService(); DependencyInjectionService service = new DependencyInjectionService();
service.addInjector( service.addInjector(
@ -141,6 +151,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
assertEquals("malarkey", test.toString()); assertEquals("malarkey", test.toString());
} }
@Test
public void testMissingInjection() { public void testMissingInjection() {
DependencyInjectionService service = new DependencyInjectionService(); DependencyInjectionService service = new DependencyInjectionService();
service.addInjector( service.addInjector(
@ -175,6 +186,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
assertNull(test.toString()); assertNull(test.toString());
} }
@Test
public void testMultipleInjection() { public void testMultipleInjection() {
DependencyInjectionService service = new DependencyInjectionService(); DependencyInjectionService service = new DependencyInjectionService();
service.addInjector( service.addInjector(
@ -223,6 +235,7 @@ public class DependencyInjectionTests extends AndroidTestCase {
protected String bar; protected String bar;
} }
@Test
public void testInheritedInjection() { public void testInheritedInjection() {
DependencyInjectionService service = new DependencyInjectionService(); DependencyInjectionService service = new DependencyInjectionService();
service.addInjector( service.addInjector(

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

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