Repository: apache/flink
File: flink-table/flink-table-common/src/test/java/org/apache/flink/types/ColumnListTest.java (Java)

Code before:
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Mismatch between data types and names");
    }

    @Test
    void testNullElementInNamesThrowsException() {
        final List<String> names = Arrays.asList("a", null, "c");

        assertThatThrownBy(() -> ColumnList.of(names))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Names must not contain null elements");
    }

    @Test
    void testNullElementInDataTypesThrowsException() {
        final List<String> names = Arrays.asList("a", "b", "c");
        final List<DataType> dataTypes = Arrays.asList(DataTypes.INT(), null, DataTypes.BOOLEAN());

        assertThatThrownBy(() -> ColumnList.of(names, dataTypes))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Data types must not contain null elements");
    }

    @Test
    void testImmutabilityOfNames() {
        final List<String> names = new ArrayList<>(Arrays.asList("a", "b"));
        final ColumnList columnList = ColumnList.of(names);

        names.add("c");

        assertThat(columnList.getNames()).containsExactly("a", "b");
    }

    @Test
    void testImmutabilityOfDataTypes() {
        final List<String> names = new ArrayList<>(Arrays.asList("a", "b"));
        final List<DataType> dataTypes =
                new ArrayList<>(Arrays.asList(DataTypes.INT(), DataTypes.STRING()));
        final ColumnList columnList = ColumnList.of(names, dataTypes);

        dataTypes.add(DataTypes.BOOLEAN());

        assertThat(columnList.getDataTypes()).hasSize(2);
    }
}


Review comment (suggestion):
```suggestion
        final List<String> names = List.of("a", "b"));
```

Code after:
    }

    @Test
    void testNullElementInNamesThrowsException() {
        final List<String> names = Arrays.asList("a", null, "c");

        assertThatThrownBy(() -> ColumnList.of(names))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Names must not contain null elements");
    }

    @Test
    void testNullElementInDataTypesThrowsException() {
        final List<String> names = List.of("a", "b", "c");
        final List<DataType> dataTypes = Arrays.asList(DataTypes.INT(), null, DataTypes.BOOLEAN());

        assertThatThrownBy(() -> ColumnList.of(names, dataTypes))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Data types must not contain null elements");
    }

    @Test
    void testImmutabilityOfNames() {
        final List<String> names = new ArrayList<>(List.of("a", "b"));
        final ColumnList columnList = ColumnList.of(names);

        names.add("c");

        assertThat(columnList.getNames()).containsExactly("a", "b");
    }

    @Test
    void testImmutabilityOfDataTypes() {
        final List<String> names = new ArrayList<>(List.of("a", "b"));
        final List<DataType> dataTypes =
                new ArrayList<>(List.of(DataTypes.INT(), DataTypes.STRING()));
        final ColumnList columnList = ColumnList.of(names, dataTypes);

        dataTypes.add(DataTypes.BOOLEAN());

        assertThat(columnList.getDataTypes()).hasSize(2);
    }
}