Repository: apache/kafka
File: clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java (Java)

Code before:

    @Test
    public void testConvertValueToStringShort() {
        assertEquals("32767", ConfigDef.convertToString(Short.MAX_VALUE, Type.SHORT));
        assertNull(ConfigDef.convertToString(null, Type.SHORT));
    }

    @Test
    public void testConvertValueToStringInt() {
        assertEquals("2147483647", ConfigDef.convertToString(Integer.MAX_VALUE, Type.INT));
        assertNull(ConfigDef.convertToString(null, Type.INT));
    }

    @Test
    public void testConvertValueToStringLong() {
        assertEquals("9223372036854775807", ConfigDef.convertToString(Long.MAX_VALUE, Type.LONG));
        assertNull(ConfigDef.convertToString(null, Type.LONG));
    }

    @Test
    public void testConvertValueToStringDouble() {
        assertEquals("3.125", ConfigDef.convertToString(3.125, Type.DOUBLE));
        assertNull(ConfigDef.convertToString(null, Type.DOUBLE));
    }

    @Test
    public void testConvertValueToStringString() {
        assertEquals("foobar", ConfigDef.convertToString("foobar", Type.STRING));
        assertNull(ConfigDef.convertToString(null, Type.STRING));
    }

    @Test
    public void testConvertValueToStringPassword() {
        assertEquals(Password.HIDDEN, ConfigDef.convertToString(new Password("foobar"), Type.PASSWORD));
        assertEquals("foobar", ConfigDef.convertToString("foobar", Type.PASSWORD));
        assertNull(ConfigDef.convertToString(null, Type.PASSWORD));
    }

    @Test
    public void testConvertValueToStringList() {
        assertEquals("a,bc,d", ConfigDef.convertToString(Arrays.asList("a", "bc", "d"), Type.LIST));
        assertNull(ConfigDef.convertToString(null, Type.LIST));
    }

    @Test
    public void testConvertValueToStringClass() throws ClassNotFoundException {
        String actual = ConfigDef.convertToString(ConfigDefTest.class, Type.CLASS);
        assertEquals("org.apache.kafka.common.config.ConfigDefTest", actual);
        // Additionally validate that we can look up this class by this name
        assertEquals(ConfigDefTest.class, Class.forName(actual));
        assertNull(ConfigDef.convertToString(null, Type.CLASS));

Review comment (suggestion):
I just realized we don't have a test for `type=null`. we'll  file a patch to add it

Code after:

    @Test
    public void testConvertValueToStringShort() {
        assertEquals("32767", ConfigDef.convertToString(Short.MAX_VALUE, Type.SHORT));
        assertNull(ConfigDef.convertToString(null, Type.SHORT));
    }

    @Test
    public void testConvertValueToStringInt() {
        assertEquals("2147483647", ConfigDef.convertToString(Integer.MAX_VALUE, Type.INT));
        assertNull(ConfigDef.convertToString(null, Type.INT));
    }

    @Test
    public void testConvertValueToStringLong() {
        assertEquals("9223372036854775807", ConfigDef.convertToString(Long.MAX_VALUE, Type.LONG));
        assertNull(ConfigDef.convertToString(null, Type.LONG));
    }

    @Test
    public void testConvertValueToStringDouble() {
        assertEquals("3.125", ConfigDef.convertToString(3.125d, Type.DOUBLE));
        assertEquals("1.7976931348623157E308", ConfigDef.convertToString(Double.MAX_VALUE, Type.DOUBLE));
        assertEquals("1.024E8",  ConfigDef.convertToString(102400000d, Type.DOUBLE));
        assertEquals("-1.024E8",  ConfigDef.convertToString(-102400000d, Type.DOUBLE));
        assertNull(ConfigDef.convertToString(null, Type.DOUBLE));
    }

    @Test
    public void testConvertValueToStringString() {
        assertEquals("foobar", ConfigDef.convertToString("foobar", Type.STRING));
        assertNull(ConfigDef.convertToString(null, Type.STRING));
    }

    @Test
    public void testConvertValueToStringPassword() {
        assertEquals(Password.HIDDEN, ConfigDef.convertToString(new Password("foobar"), Type.PASSWORD));
        assertEquals("foobar", ConfigDef.convertToString("foobar", Type.PASSWORD));
        assertNull(ConfigDef.convertToString(null, Type.PASSWORD));
    }

    @Test
    public void testConvertValueToStringList() {
        assertEquals("a,bc,d", ConfigDef.convertToString(Arrays.asList("a", "bc", "d"), Type.LIST));
        assertNull(ConfigDef.convertToString(null, Type.LIST));
    }

    @Test
    public void testConvertValueToStringClass() throws ClassNotFoundException {
        String actual = ConfigDef.convertToString(ConfigDefTest.class, Type.CLASS);
        assertEquals("org.apache.kafka.common.config.ConfigDefTest", actual);