UpgraderFactory { @Nullable public DatabaseUpgrader createUpgrader(int upgradingFromVersion, DatabaseHelper helper, SQLiteDatabase db) { UpgraderVisitor databaseUpgrader = new UpgraderVisitor(); switch (upgradingFromVersion) { case DatabaseHelper.VER_RESPONSE_ITERATION: databaseUpgrader.addUpgrader(new ResponsesUpgrader(helper, db)); case DatabaseHelper.VER_TRANSMISSION_ITERATION: databaseUpgrader.addUpgrader(new TransmissionsUpgrader(helper, db)); case DatabaseHelper.VER_DATA_POINT_ASSIGNMENTS_ITERATION: databaseUpgrader.addUpgrader(new AssignmentsUpgrader(helper, db)); case DatabaseHelper.VER_DATA_POINT_ASSIGNMENTS_ITERATION_2: databaseUpgrader.addUpgrader(new Assignments2Upgrader(db, new DataPointDownloadTable())); case DatabaseHelper.VER_CURSOR_ITERATION: databaseUpgrader.addUpgrader(new CursorUpgrader(helper, db)); case DatabaseHelper.VER_SURVEY_VIEWED: databaseUpgrader.addUpgrader(new SurveyViewedUpgrader(helper, db)); default: break; } return databaseUpgrader; }  @Nullable DatabaseUpgrader createUpgrader(int upgradingFromVersion, DatabaseHelper helper,
                                           SQLiteDatabase db);  }
@Test public void createUpgraderShouldCreateCorrectUpgraderWhenResponse() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_RESPONSE_ITERATION, mockDbHelper, mockDb); assertEquals(6, upgrader.getUpgraders().size()); assertTrue(containsResponsesUpgrader(upgrader.getUpgraders())); }
@Test public void createUpgraderShouldCreateCorrectUpgraderWhenTransmissionsIteration() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_TRANSMISSION_ITERATION, mockDbHelper, mockDb); assertEquals(5, upgrader.getUpgraders().size()); }
@Test public void createUpgraderShouldCreateCorrectUpgraderWhenAssignmentIteration() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_DATA_POINT_ASSIGNMENTS_ITERATION, mockDbHelper, mockDb); assertEquals(4, upgrader.getUpgraders().size()); }
@Test public void createUpgraderShouldCreateCorrectUpgraderWhenAssignmentIteration2() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_DATA_POINT_ASSIGNMENTS_ITERATION_2, mockDbHelper, mockDb); assertEquals(3, upgrader.getUpgraders().size()); }
@Test public void createUpgraderShouldCreateCorrectUpgraderWhenCursorIteration() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_CURSOR_ITERATION, mockDbHelper, mockDb); assertEquals(2, upgrader.getUpgraders().size()); }
@Test public void createUpgraderShouldCreateCorrectUpgraderWhenSurveyViewedIteration() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_SURVEY_VIEWED, mockDbHelper, mockDb); assertEquals(1, upgrader.getUpgraders().size()); }
@Test public void createUpgraderShouldCreateNoUpgraderWhenDataPointStatusIteration() { UpgraderFactory upgraderFactory = new UpgraderFactory(); UpgraderVisitor upgrader = (UpgraderVisitor) upgraderFactory .createUpgrader(DatabaseHelper.VER_DATAPOINT_STATUS, mockDbHelper, mockDb); assertEquals(0, upgrader.getUpgraders().size()); }