<T extends MaterialConfig> T getExistingOrDefaultMaterial(T defaultMaterial) {
        for (MaterialConfig material : this) {
            if (material.getClass().isAssignableFrom(defaultMaterial.getClass())) {
                return (T) material;
            }
        }
        return defaultMaterial;
    }
@Test
    public void shouldGetExistingOrDefaultMaterialCorrectly() {
        SvnMaterialConfig svn = svn("http://test.com", false);
        PackageMaterialConfig p1 = new PackageMaterialConfig("p1");
        PackageMaterialConfig p2 = new PackageMaterialConfig("p2");

        assertThat(new MaterialConfigs(svn, p2).getExistingOrDefaultMaterial(p1).getPackageId()).isEqualTo("p2");

        assertThat(new MaterialConfigs(svn).getExistingOrDefaultMaterial(p1).getPackageId()).isEqualTo("p1");
    }