### Question:
ComponentProcessor { static void applyDlStereochemistryToCarbohydrateConfigurationalPrefix(Element elementToApplyTo, String dlStereochemistryValue) throws ComponentGenerationException { if (dlStereochemistryValue.equals("d") || dlStereochemistryValue.equals("dg")) { } else if (dlStereochemistryValue.equals("l") || dlStereochemistryValue.equals("lg")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/", -1); StringBuilder sb = new StringBuilder(); for (String value : values) { if (value.equals("r")){ sb.append("l"); } else if (value.equals("l")){ sb.append("r"); } else{ throw new RuntimeException("OPSIN Bug: Invalid carbohydrate prefix value: " + elementToApplyTo.getAttributeValue(VALUE_ATR)); } sb.append("/"); } String newVal = sb.toString().substring(0, sb.length()-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else if (dlStereochemistryValue.equals("dl")) { String[] values = elementToApplyTo.getAttributeValue(VALUE_ATR).split("/"); String newVal = "?" + StringTools.multiplyString("/?", values.length-1); elementToApplyTo.getAttribute(VALUE_ATR).setValue(newVal); } else{ throw new ComponentGenerationException("Unexpected value for D/L stereochemistry found before carbohydrate prefix: " + dlStereochemistryValue ); } } ComponentProcessor(BuildState state, SuffixApplier suffixApplier);   }### Answer:
@Test public void testDStereochemistryDOnCarbohydratePrefix() throws ComponentGenerationException, StructureBuildingException{ Element prefix = new TokenEl(STEREOCHEMISTRY_EL); prefix.addAttribute(new Attribute(TYPE_ATR, CARBOHYDRATECONFIGURATIONPREFIX_TYPE_VAL)); prefix.addAttribute(new Attribute(VALUE_ATR, "l/r")); ComponentProcessor.applyDlStereochemistryToCarbohydrateConfigurationalPrefix(prefix, "d"); assertEquals("l/r", prefix.getAttributeValue(VALUE_ATR)); }
@Test public void testLStereochemistryDOnCarbohydratePrefix() throws ComponentGenerationException, StructureBuildingException{ Element prefix = new TokenEl(STEREOCHEMISTRY_EL); prefix.addAttribute(new Attribute(TYPE_ATR, CARBOHYDRATECONFIGURATIONPREFIX_TYPE_VAL)); prefix.addAttribute(new Attribute(VALUE_ATR, "r/l")); ComponentProcessor.applyDlStereochemistryToCarbohydrateConfigurationalPrefix(prefix, "l"); assertEquals("l/r", prefix.getAttributeValue(VALUE_ATR)); }
@Test public void testDLStereochemistryDOnCarbohydratePrefix() throws ComponentGenerationException, StructureBuildingException{ Element prefix = new TokenEl(STEREOCHEMISTRY_EL); prefix.addAttribute(new Attribute(TYPE_ATR, CARBOHYDRATECONFIGURATIONPREFIX_TYPE_VAL)); prefix.addAttribute(new Attribute(VALUE_ATR, "l/r")); ComponentProcessor.applyDlStereochemistryToCarbohydrateConfigurationalPrefix(prefix, "dl"); assertEquals("?/?", prefix.getAttributeValue(VALUE_ATR)); }