### Question:
SchemaUtil { public static int getFieldIndexByName(final Schema schema, final String fieldName) { if (schema.fields() == null) { return -1; } for (int i = 0; i < schema.fields().size(); i++) { Field field = schema.fields().get(i); int dotIndex = field.name().indexOf('.'); if (dotIndex == -1) { if (field.name().equals(fieldName)) { return i; } } else { if (dotIndex < fieldName.length()) { String fieldNameWithDot = fieldName.substring(0, dotIndex) + "." + fieldName.substring(dotIndex + 1); if (field.name().equals(fieldNameWithDot)) { return i; } } } } return -1; }  static Class getJavaType(final Schema schema); static Optional<Field> getFieldByName(final Schema schema, final String fieldName); static Schema getTypeSchema(final String sqlType); static int getFieldIndexByName(final Schema schema, final String fieldName); static Schema buildSchemaWithAlias(final Schema schema, final String alias); static String getSchemaFieldName(Field field); static String getJavaCastString(Schema schema); static Schema addImplicitRowTimeRowKeyToSchema(Schema schema); static Schema removeImplicitRowTimeRowKeyFromSchema(Schema schema); static Set<Integer> getRowTimeRowKeyIndexes(Schema schema); static String getSchemaDefinitionString(Schema schema); static String getSqlTypeName(Schema schema); static String buildAvroSchema(final Schema schema, String name); static Schema getAvroSerdeKsqlSchema(Schema schema); static String getFieldNameWithNoAlias(Field field); static Schema getSchemaWithNoAlias(Schema schema); static int getIndexInSchema(final String fieldName, final Schema schema); static final String ARRAY; static final String MAP; static final String ROWKEY_NAME; static final String ROWTIME_NAME; static final int ROWKEY_NAME_INDEX; }### Answer:
@Test public void shouldGetTheCorrectFieldIndex() { int index1 = SchemaUtil.getFieldIndexByName(schema, "orderid".toUpperCase()); int index2 = SchemaUtil.getFieldIndexByName(schema, "itemid".toUpperCase()); int index3 = SchemaUtil.getFieldIndexByName(schema, "mapcol".toUpperCase()); assertThat("Incorrect index.", index1, equalTo(1)); assertThat("Incorrect index.", index2, equalTo(2)); assertThat("Incorrect index.", index3, equalTo(5)); }
@Test public void shouldHandleInvalidFieldIndexCorrectly() { int index = SchemaUtil.getFieldIndexByName(schema, "mapcol1".toUpperCase()); assertThat("Incorrect index.", index, equalTo(-1)); }