UPCEANLogicImpl { protected void drawSupplemental(ClassicBarcodeLogicHandler logic, String supp) { if (supp == null) { throw new NullPointerException("Supplemental message must not be null"); } if (supp.length() == 2) { drawSupplemental2(logic, supp); } else if (supp.length() == 5) { drawSupplemental5(logic, supp); } else { throw new IllegalArgumentException( "Only supplemental lengths 2 and 5 are allowed: " + supp.length()); } } UPCEANLogicImpl(ChecksumMode mode); ChecksumMode getChecksumMode(); void validateMessage(String msg); char calcChecksum(String msg); abstract void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg);  }
@Test public void testSupplemental2() throws Exception { StringBuilder sb = new StringBuilder(); EAN13LogicImpl logic; String expected; logic = new EAN13LogicImpl(ChecksumMode.CP_AUTO); logic.drawSupplemental(new MockClassicBarcodeLogicHandler(sb), "34"); expected = "<SBG:upc-ean-supp:34>" + "<SBG:upc-ean-guard:null>B1W1B2</SBG>" + "<SBG:msg-char:3>W1B1W4B1</SBG>" + "<SBG:upc-ean-guard:null>W1B1</SBG>" + "<SBG:msg-char:4>W1B1W3B2</SBG>" + "</SBG>"; assertEquals(expected, sb.toString()); }
@Test public void testSupplemental5() throws Exception { StringBuilder sb = new StringBuilder(); EAN13LogicImpl logic; String expected; logic = new EAN13LogicImpl(ChecksumMode.CP_AUTO); logic.drawSupplemental(new MockClassicBarcodeLogicHandler(sb), "51234"); expected = "<SBG:upc-ean-supp:51234>" + "<SBG:upc-ean-guard:null>B1W1B2</SBG>" + "<SBG:msg-char:5>W1B2W3B1</SBG>" + "<SBG:upc-ean-guard:null>W1B1</SBG>" + "<SBG:msg-char:1>W2B2W2B1</SBG>" + "<SBG:upc-ean-guard:null>W1B1</SBG>" + "<SBG:msg-char:2>W2B2W1B2</SBG>" + "<SBG:upc-ean-guard:null>W1B1</SBG>" + "<SBG:msg-char:3>W1B4W1B1</SBG>" + "<SBG:upc-ean-guard:null>W1B1</SBG>" + "<SBG:msg-char:4>W2B3W1B1</SBG>" + "</SBG>"; assertEquals(expected, sb.toString()); }