/** Test format with attributes and an element. */ public void testFormatAttributesAndElement() { JDOMFactory factory = new DefaultJDOMFactory(); Attribute attr; List attributes = new ArrayList(); attr = factory.attribute("device", "PC"); attributes.add(attr); attr = factory.attribute("pixelsX", "100"); attributes.add(attr); attr = factory.attribute("pixelsY", "200"); attributes.add(attr); attr = factory.attribute("pixelDepth", "24"); attributes.add(attr); attr = factory.attribute("rendering", "color"); attributes.add(attr); String message = "{value}, {element}, {assetGroup}, {device}, " + "{rendering}, {pixelDepth}bits, {pixelsX}x{pixelsY}px, " + "{widthHint}"; PolicyAttributesDetails details = new PolicyAttributesDetails("imageComponent", true); AttributesMessageFormatter attributesMessageFormatter = new AttributesMessageFormatter(details); String formatted = attributesMessageFormatter.format(attributes, message, "Device Specific Image"); assertEquals("Device Specific Image, PC, Color, 24bits, 100x200px", formatted); }
/** * Test the removal of 'px' if no value for pixels and there is a previous non-empty value in the * list. */ public void testFormatAttributesNoOtherElements() { JDOMFactory factory = new DefaultJDOMFactory(); Attribute attr; List attributes = new ArrayList(); attr = factory.attribute("pixelsX", "100"); attributes.add(attr); String message = "{pixelDepth}bits, {pixelsX}x{pixelsY}px"; PolicyAttributesDetails details = new PolicyAttributesDetails("imageComponent", true); AttributesMessageFormatter attributesMessageFormatter = new AttributesMessageFormatter(details); String formatted = attributesMessageFormatter.format(attributes, message, ""); assertEquals("Result is: '" + formatted + "'", "100x", formatted); }
/** Test the missing first bracket (or char) if no value present. */ public void testFormatAttributesMissingGridOpenBracket() { JDOMFactory factory = new DefaultJDOMFactory(); Attribute attr; List attributes = new ArrayList(); attr = factory.attribute("rows", "1"); attributes.add(attr); attr = factory.attribute("columns", "2"); attributes.add(attr); String message = "{element}: ''{name}'' ({rows}x{columns})"; PolicyAttributesDetails details = new PolicyAttributesDetails("imageComponent", true); AttributesMessageFormatter attributesMessageFormatter = new AttributesMessageFormatter(details); String formatted = attributesMessageFormatter.format(attributes, message, "elementName"); assertEquals("Result is: '" + formatted + "'", "elementName: ''(1x2)", formatted); }