Repository: apache/dubbo
File: dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java (Java)

Code before:
        String application = "vic.zk.md";
        MetadataIdentifier providerMetadataIdentifier =
                new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
        Assertions.assertEquals(
                providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.PATH),
                "metadata" + PATH_SEPARATOR + interfaceName + PATH_SEPARATOR
                        + (version == null ? "" : (version + PATH_SEPARATOR))
                        + (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE + PATH_SEPARATOR
                        + application);
        Assertions.assertEquals(
                providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY),
                interfaceName
                        + MetadataConstants.KEY_SEPARATOR
                        + (version == null ? "" : version)
                        + MetadataConstants.KEY_SEPARATOR
                        + (group == null ? "" : group)
                        + MetadataConstants.KEY_SEPARATOR
                        + PROVIDER_SIDE
                        + MetadataConstants.KEY_SEPARATOR
                        + application);
    }

    @Test
    void testPutDuplicateIdentifier() {
        ConcurrentHashMap<MetadataIdentifier, Object> map = new ConcurrentHashMap<>();
        map.put(new MetadataIdentifier("com.ServiceInterface", "1.0.0", "gray", "consumer", "testApp"), null);
        map.put(new MetadataIdentifier("com.ServiceInterface", "1.0.0", "gray", "consumer", "testApp"), null);
        map.put(new MetadataIdentifier("com.ServiceInterface", "1.0.0", "gray", "consumer", "testApp"), null);
        Assertions.assertEquals(map.size(), 1);
    }
}


Review comment (refactor):
Could not put null value to ConcurrentHashMap since
```
public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
    implements ConcurrentMap<K,V>, Serializable {
    ... 
    final V putVal(K key, V value, boolean onlyIfAbsent) {
        if (key == null || value == null) throw new NullPointerException();
        ...
```

Code after:
        String application = "vic.zk.md";
        MetadataIdentifier providerMetadataIdentifier =
                new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
        Assertions.assertEquals(
                providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.PATH),
                "metadata" + PATH_SEPARATOR + interfaceName + PATH_SEPARATOR
                        + (version == null ? "" : (version + PATH_SEPARATOR))
                        + (group == null ? "" : (group + PATH_SEPARATOR)) + PROVIDER_SIDE + PATH_SEPARATOR
                        + application);
        Assertions.assertEquals(
                providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY),
                interfaceName
                        + MetadataConstants.KEY_SEPARATOR
                        + (version == null ? "" : version)
                        + MetadataConstants.KEY_SEPARATOR
                        + (group == null ? "" : group)
                        + MetadataConstants.KEY_SEPARATOR
                        + PROVIDER_SIDE
                        + MetadataConstants.KEY_SEPARATOR
                        + application);
    }

    @Test
    void testPutDuplicateIdentifier() {
        ConcurrentHashMap<MetadataIdentifier, Object> map = new ConcurrentHashMap<>();
        map.put(new MetadataIdentifier("com.ServiceInterface", "1.0.0", "gray", "consumer", "testApp"), new Object());
        map.put(new MetadataIdentifier("com.ServiceInterface", "1.0.0", "gray", "consumer", "testApp"), new Object());
        map.put(new MetadataIdentifier("com.ServiceInterface", "1.0.0", "gray", "consumer", "testApp"), new Object());
        Assertions.assertEquals(map.size(), 1);
    }
}