### Question:
CqlFilesMigrationService implements SchemaInstaller, MigrationService { @Override public void migrate(Version currentVersion, Version toVersion) { String schema = schemaProducer.schema(currentVersion, toVersion); if (Strings.isNullOrEmpty(schema)) { logger.info("No CQL migration found from version {} to {}", currentVersion.get(), toVersion.get()); } else { logger.info("Executing CQL migration from version {} to {}", currentVersion.get(), toVersion.get()); executeCQL(schema); } } @Inject @VisibleForTesting  CqlFilesMigrationService(
			@Named(LoggerModule.MIGRATION) Logger logger,
			SchemaProducer schemaProducer,
			Provider<Session> sessionProvider); @Override void install(Version latestVersionUpdate); @Override void migrate(Version currentVersion, Version toVersion);  }### Answer:
@Test public void update() { Version fromVersion = Version.of(1); Version toVersion = Version.of(2); String schema = "schema"; expect(schemaProducer.schema(fromVersion, toVersion)).andReturn(schema); expect(session.execute(schema)).andReturn(null); logger.info("Executing CQL migration from version {} to {}", fromVersion.get(), toVersion.get()); expectLastCall(); logger.debug("CQL: {}", schema); expectLastCall(); mocks.replay(); testee.migrate(fromVersion, toVersion); mocks.verify(); }
@Test(expected=InvalidQueryException.class) public void updateInvalidScript() { Version fromVersion = Version.of(1); Version toVersion = Version.of(2); String schema = "schema"; expect(schemaProducer.schema(fromVersion, toVersion)).andReturn(schema); expect(session.execute(schema)).andThrow(new InvalidQueryException("expected message")); logger.info("Executing CQL migration from version {} to {}", fromVersion.get(), toVersion.get()); expectLastCall(); logger.debug("CQL: {}", schema); expectLastCall(); mocks.replay(); try { testee.migrate(fromVersion, toVersion); } catch (Exception e) { mocks.verify(); throw e; } }
@Test(expected=NoHostAvailableException.class) public void updateNoHostAvailable() { Version fromVersion = Version.of(1); Version toVersion = Version.of(2); String schema = "schema"; expect(schemaProducer.schema(fromVersion, toVersion)).andReturn(schema); expect(session.execute(schema)).andThrow(new NoHostAvailableException(ImmutableMap.<InetSocketAddress, Throwable> of())); logger.info("Executing CQL migration from version {} to {}", fromVersion.get(), toVersion.get()); expectLastCall(); logger.debug("CQL: {}", schema); expectLastCall(); mocks.replay(); try { testee.migrate(fromVersion, toVersion); } catch (Exception e) { mocks.verify(); throw e; } }
@Test public void updateShouldProduceMeaningfulLogsWhenEmptyCQL() { Version fromVersion = Version.of(1); Version toVersion = Version.of(2); String schema = ""; expect(schemaProducer.schema(fromVersion, toVersion)).andReturn(schema); logger.info("No CQL migration found from version {} to {}", fromVersion.get(), toVersion.get()); expectLastCall(); mocks.replay(); testee.migrate(fromVersion, toVersion); mocks.verify(); }
@Test public void updateShouldProduceMeaningfulLogsWhenNullCQL() { Version fromVersion = Version.of(1); Version toVersion = Version.of(2); String schema = null; expect(schemaProducer.schema(fromVersion, toVersion)).andReturn(schema); logger.info("No CQL migration found from version {} to {}", fromVersion.get(), toVersion.get()); expectLastCall(); mocks.replay(); testee.migrate(fromVersion, toVersion); mocks.verify(); }