Splitter { public static void main(String[] args) { CommandLine commandLine = new CommandLine(args); String inputFileName = commandLine.getPosition(0); String outputFileNamePattern = commandLine.getOption("o"); if (outputFileNamePattern == null) badArgs(); Reader inputReader = establishInput(inputFileName); Splitter ediSplitter = new Splitter(inputReader, outputFileNamePattern); try { ediSplitter.run(); } catch (SAXException | IOException e) { System.out.print(e); throw new RuntimeException(e.getMessage()); } catch (Exception e) { e.printStackTrace(System.out); throw new RuntimeException(e.getMessage()); } } Splitter(Reader inputReader, String outputFileNamePattern); void run(); void split(InputSource inputSource); static void main(String[] args); static int getCount();  }
@Test public void testMain() throws Exception { PrintStream systemOut = System.out; final ByteArrayOutputStream redirectedOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(redirectedOut)); FileUtil.stringToFile(EDITestData.getAnsiInterchange(2), "toSplit.edi"); String[] args = new String[]{"toSplit.edi", "-o", getTestresultsPath() + "x12/split-0000.xml"}; EDISplitter.main(args); System.setOut(systemOut); assertEquals("Did not produce expected System.out", NEW_LINE + "EDI input parsed into 2 XML output files" + NEW_LINE, redirectedOut.toString()); assertEquals("Did not produce expected number of output files", 2, EDISplitter.getCount()); File file = new File(getTestresultsPath() + "x12/split-0002.xml"); assertNotNull("Could not form expected output file name", file); assertTrue("Expected output file does not exist", file.exists()); InputSource inputSource = new InputSource(new FileReader(file)); DocumentUtil util = DocumentUtil.getInstance(); Document dom = util.buildDocumentFromXml(inputSource); assertNotNull("Could not build DOM from XML output", dom); Element element = DocumentUtil.position(dom.getDocumentElement(), new String[]{"interchange"}); String controlAttribute = element.getAttribute("Control"); assertEquals("Interchange control number is wrong in XML output", "000038449", controlAttribute); element = DocumentUtil.position(element, new String[]{"sender", "address"}); String qualAttribute = element.getAttribute("Qual"); assertEquals("Sender qualifier is wrong in XML output", "ZZ", qualAttribute); }