### Question:
ColumnMeta { public static int getColumnIndexByName(String columnName, List<String> columnNames) throws InitializationException { for (int i = 0; i < columnNames.size(); i++) { if (columnName.equals(columnNames.get(i))) { return i; } } throw new InitializationException("Column index not detected for column \"" + columnName + "\""); } ColumnMeta(String columnMappingString, List<String> sourceColumnNames); List<String> getTargetColumnNames(); List<String> getSourceColumnNames(); List<ColumnInfo> getColumnMapping(); static int getColumnIndexByName(String columnName, List<String> columnNames); ToStringHelper toStringHelper(Object self); @Override String toString(); static final char TAG_SEPARATOR; static final char MAPPING_COLUMN_SEPARATOR; static final int TAG_COLUMN_INDEX; }### Answer:
@Test public void getColumnIndexByName() throws InitializationException { final List<String> columns = Lists.newArrayList("sCol1", "sCol2", "sCol3", "sCol4"); assertEquals(0, ColumnMeta.getColumnIndexByName("sCol1", columns)); assertEquals(1, ColumnMeta.getColumnIndexByName("sCol2", columns)); assertEquals(3, ColumnMeta.getColumnIndexByName("sCol4", columns)); try { ColumnMeta.getColumnIndexByName("NotFound", columns); throw new RuntimeException("Test failed"); } catch (InitializationException e) { } }