Wrote first gtasks unit test, first unit test passes.

pull/14/head
Tim Su 14 years ago
parent 0cf572de59
commit d00a35bf58

@ -52,7 +52,7 @@ public class GtasksDecorationExposer implements TaskDecorationExposer {
RemoteViews decoration = new RemoteViews(ContextManager.getContext().getPackageName(),
R.layout.gtasks_decoration);
decoration.setInt(R.id.indent, "setWidth", indentation * 20); //$NON-NLS-1$
decoration.setInt(R.id.indent, "setMinWidth", indentation * 20); //$NON-NLS-1$
return new TaskDecoration(decoration, TaskDecoration.POSITION_LEFT, 0);
}

@ -36,6 +36,10 @@ public class MilkDetailExposer extends BroadcastReceiver {
@Autowired private MilkMetadataService milkMetadataService;
@Autowired private MilkListService milkListService;
static {
MilkDependencyInjector.initialize();
}
@Override
public void onReceive(Context context, Intent intent) {
ContextManager.setContext(context);

@ -40,6 +40,10 @@ public class MilkFilterExposer extends BroadcastReceiver {
@Autowired private MilkListService milkListService;
static {
MilkDependencyInjector.initialize();
}
private Filter filterFromList(Context context, StoreObject list) {
String listName = list.getValue(MilkListFields.NAME);
String title = context.getString(R.string.rmilk_FEx_list_title,

@ -11,6 +11,7 @@ import java.util.HashSet;
import java.util.List;
import org.weloveastrid.rmilk.MilkBackgroundService;
import org.weloveastrid.rmilk.MilkDependencyInjector;
import org.weloveastrid.rmilk.MilkLoginActivity;
import org.weloveastrid.rmilk.MilkPreferences;
import org.weloveastrid.rmilk.MilkUtilities;
@ -64,6 +65,10 @@ public class MilkSyncProvider extends SyncProvider<MilkTaskContainer> {
@Autowired private MilkMetadataService milkMetadataService;
@Autowired private MilkListService milkListService;
static {
MilkDependencyInjector.initialize();
}
// ----------------------------------------------------------------------
// ------------------------------------------------------- public methods
// ----------------------------------------------------------------------

@ -1,7 +1,5 @@
package com.todoroo.andlib.test;
import android.test.AndroidTestCase;
import com.todoroo.andlib.service.TestDependencyInjector;
/**
@ -10,7 +8,7 @@ import com.todoroo.andlib.service.TestDependencyInjector;
* @author Tim Su <tim@todoroo.com>
*
*/
abstract public class TodorooTestCaseWithInjector extends AndroidTestCase {
abstract public class TodorooTestCaseWithInjector extends TodorooTestCase {
protected TestDependencyInjector testInjector;

@ -1,7 +1,6 @@
package com.todoroo.astrid.gtasks;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RemoteViews;
import com.todoroo.astrid.api.Filter;
@ -19,7 +18,7 @@ public class GtasksDecorationExposerTest extends DatabaseTestCase {
private TaskDecoration result;
public void testExposeNotLoggedIn() {
givenLoggedInStatus(true);
givenLoggedInStatus(false);
whenRequestingDecoration(gtasksFilter(), indentedTask(1));
@ -27,7 +26,7 @@ public class GtasksDecorationExposerTest extends DatabaseTestCase {
}
public void testExposeLoggedInButNormalFilter() {
givenLoggedInStatus(false);
givenLoggedInStatus(true);
whenRequestingDecoration(nonGtasksFilter(), indentedTask(1));
@ -42,7 +41,7 @@ public class GtasksDecorationExposerTest extends DatabaseTestCase {
thenExpectDecoration(1);
}
public void testExposeIndentationWithNormalTask() {
public void testExposeIndentationWithTopLevelTask() {
givenLoggedInStatus(true);
whenRequestingDecoration(gtasksFilter(), nonIndentedTask());
@ -63,13 +62,14 @@ public class GtasksDecorationExposerTest extends DatabaseTestCase {
private void thenExpectWiderThan(Task otherTask) {
assertNotNull(result);
RemoteViews view = result.decoration;
FrameLayout parent = new FrameLayout(getContext());
View inflated = view.apply(getContext(), parent);
int width = inflated.getWidth();
View inflated = view.apply(getContext(), null);
inflated.measure(100, 100);
int width = inflated.getMeasuredWidth();
result = new GtasksDecorationExposer().expose(gtasksFilter(), otherTask);
View otherInflated = result.decoration.apply(getContext(), parent);
int otherWidth = otherInflated.getWidth();
View otherInflated = result.decoration.apply(getContext(), null);
otherInflated.measure(100, 100);
int otherWidth = otherInflated.getMeasuredWidth();
assertTrue(width + " > " + otherWidth, width > otherWidth);
}
@ -84,9 +84,9 @@ public class GtasksDecorationExposerTest extends DatabaseTestCase {
private void thenExpectDecoration(int minWidth) {
assertNotNull(result);
RemoteViews view = result.decoration;
FrameLayout parent = new FrameLayout(getContext());
View inflated = view.apply(getContext(), parent);
assertTrue("actual: " + inflated.getWidth(), inflated.getWidth() > minWidth);
View inflated = view.apply(getContext(), null);
inflated.measure(100, 100);
assertTrue("actual: " + inflated.getMeasuredWidth(), inflated.getMeasuredWidth() > minWidth);
}
private Filter gtasksFilter() {
@ -101,13 +101,13 @@ public class GtasksDecorationExposerTest extends DatabaseTestCase {
PluginServices.getTaskService().save(task);
Metadata metadata = GtasksMetadata.createEmptyMetadata();
metadata.setValue(GtasksMetadata.INDENTATION, indentation);
metadata.setValue(Metadata.TASK, task.getId());
PluginServices.getMetadataService().save(metadata);
return task;
}
private Filter nonGtasksFilter() {
return CoreFilterExposer.buildInboxFilter(getContext().getResources());
}
@Override

@ -15,12 +15,12 @@ import com.todoroo.astrid.service.AstridDependencyInjector;
*/
public class DatabaseTestCase extends TodorooTestCaseWithInjector {
public static Database database = new TestDatabase();
static {
AstridDependencyInjector.initialize();
}
public static Database database = new TestDatabase();
@Override
protected void addInjectables() {
testInjector.addInjectable("database", database);

Loading…
Cancel
Save