TextPrinter implements Printer { @Override public byte[] getCommand() { return print( data ); } private  TextPrinter( final List<ControlSequence> controlSequences, final CodePage codePage, final String data ); static Printer create( final List<ControlSequence> controlSequences, final CodePage codePage, final String data ); @Override byte[] getCommand();  }
@Test public void testPrintPlain() throws Exception { final Printer printer = TextPrinterBuilder .aPrinterBuilder() .buildPrinter( "test" ); final byte[] command = printer.getCommand(); Assert.assertEquals( "[116, 101, 115, 116, 10, 0]", Arrays.toString( command ) ); }
@Test public void testPrintCodePage() throws Exception { final Printer printer = TextPrinterBuilder .aPrinterBuilder() .withCodePage( CodePage.CP_852_LATIN2 ) .buildPrinter( "test" ); final byte[] command = printer.getCommand(); Assert.assertEquals( "[27, 116, 18, 116, 101, 115, 116, 10, 0]", Arrays.toString( command ) ); }
@Test public void testPrintAlignment() throws Exception { final Printer printer = TextPrinterBuilder .aPrinterBuilder() .withGeneralControlSequence( Alignment.LEFT ) .buildPrinter( "test" ); final byte[] command = printer.getCommand(); Assert.assertEquals( "[27, 97, 0, 116, 101, 115, 116, 10, 0]", Arrays.toString( command ) ); }
@Test public void testPrintFontB() throws Exception { final Printer printer = TextPrinterBuilder .aPrinterBuilder() .withTextControlSequence( DeviceFont.DEVICE_FONT_B ) .buildPrinter( "test" ); final byte[] command = printer.getCommand(); Assert.assertEquals( "[8, 77, 0, 66, 116, 101, 115, 116, 10, 0]", Arrays.toString( command ) ); }
@Test public void testPrintCombine() throws Exception { final Printer leftPrinter = TextPrinterBuilder .aPrinterBuilder() .withGeneralControlSequence( Alignment.LEFT ) .buildPrinter( "test" ); final Printer combinedPrinter = TextPrinterBuilder .aPrinterBuilder() .withControlSequences( leftPrinter ) .withControlSequences( TextPrinterBuilder .aPrinterBuilder() .withGeneralControlSequence( Alignment.RIGHT ) .buildPrinter( "test" ) ) .buildPrinter( "test" ); final byte[] command = combinedPrinter.getCommand(); Assert.assertEquals( "[27, 97, 0, 116, 101, 115, 116, 10, 0, 27, 97, 2, 116, 101, 115, 116, 10, 0, 116, 101, 115, 116, 10, 0]", Arrays.toString( command ) ); }
@Test public void testPrintCombineMultiplePrinters() throws Exception { final Printer textLeftPrinter = TextPrinterBuilder .aPrinterBuilder() .withGeneralControlSequence( Alignment.LEFT ) .buildPrinter( "test" ); final Printer qrPrinter = QrPrinterBuilder .aPrinterBuilder() .withQrControlSequence( QrCodeModel.MODEL2 ) .withQrControlSequence( QrCodeSize.SIZE7 ) .withQrControlSequence( QrCodeErrorCorrectionLevel.L ) .buildPrinter( "223175087923687075112234402528973166755123456781508151013321" ); final Printer combinedPrinter = TextPrinterBuilder .aPrinterBuilder() .withControlSequences( textLeftPrinter ) .withControlSequences( qrPrinter ) .buildPrinter( "test" ); final byte[] command = combinedPrinter.getCommand(); Assert.assertEquals( "[27, 97, 0, 116, 101, 115, 116, 10, 0, 29, 40, 107, 4, 0, 49, 65, 50, 0, 29, 40, 107, 3, 0, 49, 67, 6, 29, 40, 107, 3, 0, 49, 69, 48, 29, 40, 107, 63, 0, 49, 80, 48, 50, 50, 51, 49, 55, 53, 48, 56, 55, 57, 50, 51, 54, 56, 55, 48, 55, 53, 49, 49, 50, 50, 51, 52, 52, 48, 50, 53, 50, 56, 57, 55, 51, 49, 54, 54, 55, 53, 53, 49, 50, 51, 52, 53, 54, 55, 56, 49, 53, 48, 56, 49, 53, 49, 48, 49, 51, 51, 50, 49, 29, 40, 107, 3, 0, 49, 81, 48, 116, 101, 115, 116, 10, 0]", Arrays.toString( command ) ); }