@Override
    public void setConfigAttributes(Object attributes) {
        clear();
        if (attributes == null) {
            return;
        }
        Map attributeMap = (Map) attributes;
        String materialType = (String) attributeMap.get(AbstractMaterialConfig.MATERIAL_TYPE);
        if (SvnMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getSvnMaterial(), (Map) attributeMap.get(SvnMaterialConfig.TYPE));
        } else if (HgMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getHgMaterial(), (Map) attributeMap.get(HgMaterialConfig.TYPE));
        } else if (GitMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getGitMaterial(), (Map) attributeMap.get(GitMaterialConfig.TYPE));
        } else if (P4MaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getP4Material(), (Map) attributeMap.get(P4MaterialConfig.TYPE));
        } else if (DependencyMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getDependencyMaterial(), (Map) attributeMap.get(DependencyMaterialConfig.TYPE));
        } else if (TfsMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getTfsMaterial(), (Map) attributeMap.get(TfsMaterialConfig.TYPE));
        } else if (PackageMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getPackageMaterial(), (Map) attributeMap.get(PackageMaterialConfig.TYPE));
        } else if (PluggableSCMMaterialConfig.TYPE.equals(materialType)) {
            addMaterialConfig(getSCMMaterial(), (Map) attributeMap.get(PluggableSCMMaterialConfig.TYPE));
        }
    }
@Test
    public void shouldSetP4ConfigAttributesForMaterial() {
        MaterialConfigs materialConfigs = new MaterialConfigs();

        Map<String, String> hashMap = new HashMap<>();
        hashMap.put(P4MaterialConfig.SERVER_AND_PORT, "localhost:1666");
        hashMap.put(P4MaterialConfig.USERNAME, "username");
        hashMap.put(P4MaterialConfig.PASSWORD, "password");
        hashMap.put(P4MaterialConfig.VIEW, "foo");

        Map<String, Object> attributeMap = new HashMap<>();
        attributeMap.put(AbstractMaterialConfig.MATERIAL_TYPE, P4MaterialConfig.TYPE);
        attributeMap.put(P4MaterialConfig.TYPE, hashMap);
        materialConfigs.setConfigAttributes(attributeMap);

        assertThat(materialConfigs).hasSize(1);
        P4MaterialConfig expected = p4("localhost:1666", "foo", "username");
        expected.setPassword("password");
        assertThat(materialConfigs.first()).isEqualTo(expected);
    }