### Question:
CassandraLog4JManager extends AbstractManager { @SuppressWarnings("SameParameterValue") void upgradeAddColIfMissing(CqlSession session, String tableName, String colName, String type) { Metadata metadata = session.getMetadata(); Optional<KeyspaceMetadata> jj_logging = metadata.getKeyspace("jj_logging"); jj_logging.ifPresent((keySpace) -> { Optional<TableMetadata> fault_tolerant = keySpace.getTable(tableName); fault_tolerant.ifPresent((table) -> { Optional<ColumnMetadata> error_count = table.getColumn(colName); if (error_count.isEmpty()) { System.out.println("Upgrading existing table to add error_count column."); String replace = UPGRADE_FT_TABLE_ADD_COL .replace("<T>", tableName) .replace("<C>", colName) .replace("<Y>", type); logger().info(replace); session.execute(replace); session.checkSchemaAgreement(); } }); }); } protected  CassandraLog4JManager(String name); boolean isReady(); static final String CREATE_LOG_KEYSPACE; static final String CREATE_LOG_TABLE; static final String CREATE_FT_TABLE; static final String UPGRADE_FT_TABLE_ADD_COL; static final String FTI_STATUS_INDEX; static final String FTI_SCANNER_INDEX; }### Answer:
@Test public void testUpgradeAddColIfMissingNoKeyspace() { expect(sessionMock.getMetadata()).andReturn(metaMock); expect(metaMock.getKeyspace("jj_logging")).andReturn(Optional.empty()); replay(); manager.upgradeAddColIfMissing(sessionMock, "foo", "bar", "int"); }
@Test public void testUpgradeAddColIfMissingNoTable() { expect(sessionMock.getMetadata()).andReturn(metaMock); expect(metaMock.getKeyspace("jj_logging")).andReturn(Optional.of(ksMock)); expect(ksMock.getTable("foo")).andReturn(Optional.empty()); replay(); manager.upgradeAddColIfMissing(sessionMock, "foo", "bar", "int"); }
@Test public void testUpgradeAddColIfMissingNoCol() { expect(sessionMock.getMetadata()).andReturn(metaMock); expect(metaMock.getKeyspace("jj_logging")).andReturn(Optional.of(ksMock)); expect(ksMock.getTable("foo")).andReturn(Optional.of(tableMock)); expect(tableMock.getColumn("bar")).andReturn(Optional.empty()); expect(sessionMock.execute("ALTER TABLE jj_logging.foo ADD bar int")).andReturn(rsMock); expect(sessionMock.checkSchemaAgreement()).andReturn(true); replay(); manager.upgradeAddColIfMissing(sessionMock, "foo", "bar", "int"); }
@Test public void testUpgradeAddColIfMissingColExists() { expect(sessionMock.getMetadata()).andReturn(metaMock); expect(metaMock.getKeyspace("jj_logging")).andReturn(Optional.of(ksMock)); expect(ksMock.getTable("foo")).andReturn(Optional.of(tableMock)); expect(tableMock.getColumn("bar")).andReturn(Optional.of(colMock)); replay(); manager.upgradeAddColIfMissing(sessionMock, "foo", "bar", "int"); }