CssBackgroundUtils { public static BackgroundPropertyType resolveBackgroundPropertyType(final String value) { final String url = "url("; if (value.startsWith(url) && value.indexOf('(', url.length()) == -1 && value.indexOf(')') == value.length() - 1) { return BackgroundPropertyType.BACKGROUND_IMAGE; } if (CssGradientUtil.isCssLinearGradientValue(value) || CommonCssConstants.NONE.equals(value)) { return BackgroundPropertyType.BACKGROUND_IMAGE; } if (CommonCssConstants.BACKGROUND_REPEAT_VALUES.contains(value)) { return BackgroundPropertyType.BACKGROUND_REPEAT; } if (CommonCssConstants.BACKGROUND_ATTACHMENT_VALUES.contains(value)) { return BackgroundPropertyType.BACKGROUND_ATTACHMENT; } if (CommonCssConstants.BACKGROUND_POSITION_X_VALUES.contains(value) && !CommonCssConstants.CENTER.equals(value)) { return BackgroundPropertyType.BACKGROUND_POSITION_X; } if (CommonCssConstants.BACKGROUND_POSITION_Y_VALUES.contains(value) && !CommonCssConstants.CENTER.equals(value)) { return BackgroundPropertyType.BACKGROUND_POSITION_Y; } if (CommonCssConstants.CENTER.equals(value)) { return BackgroundPropertyType.BACKGROUND_POSITION; } if (((Integer) 0).equals(CssUtils.parseInteger(value)) || CssUtils.isMetricValue(value) || CssUtils.isRelativeValue(value)) { return BackgroundPropertyType.BACKGROUND_POSITION_OR_SIZE; } if (CommonCssConstants.BACKGROUND_SIZE_VALUES.contains(value)) { return BackgroundPropertyType.BACKGROUND_SIZE; } if (CssUtils.isColorProperty(value)) { return BackgroundPropertyType.BACKGROUND_COLOR; } if (CommonCssConstants.BACKGROUND_ORIGIN_OR_CLIP_VALUES.contains(value)) { return BackgroundPropertyType.BACKGROUND_ORIGIN_OR_CLIP; } return BackgroundPropertyType.UNDEFINED; } private  CssBackgroundUtils(); static String getBackgroundPropertyNameFromType(BackgroundPropertyType propertyType); static BackgroundPropertyType resolveBackgroundPropertyType(final String value);  }
@Test public void resolveBackgroundPropertyTypeTest() { Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED, CssBackgroundUtils.resolveBackgroundPropertyType("jaja")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED, CssBackgroundUtils.resolveBackgroundPropertyType("ul(rock_texture.jpg)")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED, CssBackgroundUtils.resolveBackgroundPropertyType("url(rock_texture.jpg")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED, CssBackgroundUtils.resolveBackgroundPropertyType("url(rock(_texture.jpg)")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED, CssBackgroundUtils.resolveBackgroundPropertyType("url(rock_t(ext)ure.jpg)")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED, CssBackgroundUtils.resolveBackgroundPropertyType("url(url(rock_texture.jpg)")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_IMAGE, CssBackgroundUtils.resolveBackgroundPropertyType("url(rock_texture.jpg)")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_IMAGE, CssBackgroundUtils.resolveBackgroundPropertyType("linear-gradient(#e66465, #9198e5)")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_IMAGE, CssBackgroundUtils.resolveBackgroundPropertyType("none")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_REPEAT, CssBackgroundUtils.resolveBackgroundPropertyType("repeat-x")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_X, CssBackgroundUtils.resolveBackgroundPropertyType("left")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_Y, CssBackgroundUtils.resolveBackgroundPropertyType("bottom")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION, CssBackgroundUtils.resolveBackgroundPropertyType("center")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_OR_SIZE, CssBackgroundUtils.resolveBackgroundPropertyType("10%")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE, CssBackgroundUtils.resolveBackgroundPropertyType("contain")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN_OR_CLIP, CssBackgroundUtils.resolveBackgroundPropertyType("padding-box")); Assert.assertEquals(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ATTACHMENT, CssBackgroundUtils.resolveBackgroundPropertyType("fixed")); }