SettingActivity extends PreferenceActivity { @Background public void loadProject() { try { projectUserRelationDao.delete(projectUserRelationDao.queryForAll()); List<Status> statuses = backlogService.getStatuses(); for (Status status : statuses) { statusDao.createOrUpdate(status); Ln.d("put status id:%d", status.id); } List<Priority> priorities = backlogService.getPriorities(); for (Priority priority : priorities) { priorityDao.createOrUpdate(priority); Ln.d("put priority id:%d", priority.id); } List<Resolution> resolutions = backlogService.getResolutions(); for (Resolution resolution : resolutions) { resolutionDao.createOrUpdate(resolution); Ln.d("put resolution id:%d", resolution.id); } List<Project> projects = backlogService.getProjects(); int projectSize = projects.size(); setProgressMax(projectSize); for (Project project : projects) { projectDao.createOrUpdate(project); Ln.d("put project id:%d", project.id); List<IssueType> issueTypes = backlogService.getIssueTypes(project.id); for (IssueType issueType : issueTypes) { issueTypeDao.createOrUpdate(issueType); Ln.d("put issueType id:%d name:%s color:%s", issueType.id, issueType.name, issueType.color); } List<Component> components = backlogService.getComponents(project.id); for (Component component : components) { componentDao.createOrUpdate(component); Ln.d("put component id:%d", component.id); } List<Version> versions = backlogService.getVersions(project.id); for (Version version : versions) { versionDao.createOrUpdate(version); Ln.d("put version id:%d", version.id); } List<User> users = backlogService.getUsers(project.id); for (User user : users) { userDao.createOrUpdate(user); ProjectUserRelation rel = new ProjectUserRelation(); rel.project = project; rel.user = user; projectUserRelationDao.create(rel); Ln.d("put user id:%d", user.id); } incrementProgress(); } Ln.d("finish setup"); finishSetup(); } catch (XMLRPCException e) { failSetup(e); } catch (SQLException e) { failSetup(e); } }  @Override boolean onKeyUp(int keyCode, KeyEvent event); @Background void loadProject(); @UiThread void failSetup(Exception e); @UiThread void finishSetup();  }
@Test public void testLoadProject() throws Exception { Robolectric.application.onCreate(); SettingActivity activity = new SettingActivity(); assertThat(activity, is(notNullValue())); ((RoboApplication)Robolectric.application).getInjector().injectMembers(activity); assertThat(activity.priorityDao , is(notNullValue())); BacklogService backlogService = createMockBacklogService(); activity.backlogService = backlogService; activity.loadProject(); assertThat(activity.statusDao.queryForId(-1) , is(notNullValue())); assertThat(activity.priorityDao.queryForId(-2) , is(notNullValue())); assertThat(activity.resolutionDao.queryForId(-3) , is(notNullValue())); assertThat(activity.projectDao.queryForId(-4) , is(notNullValue())); assertThat(activity.issueTypeDao.queryForId(-5) , is(notNullValue())); assertThat(activity.componentDao.queryForId(-6) , is(notNullValue())); assertThat(activity.versionDao.queryForId(-7) , is(notNullValue())); assertThat(activity.userDao.queryForId(-8) , is(notNullValue())); assertThat(activity.projectUserRelationDao.queryBuilder().where().eq("user_id" , -8).and().eq("project_id" , -4).query().size() , is(1)); List<ProjectUserRelation> relationList = activity.projectUserRelationDao.queryBuilder().where().eq("user_id" , -8).and().eq("project_id" , -4).query(); }