@Test public void testListingParserErrors() throws Exception { final EtmPoint point = mock(EtmPoint.class); mockStatic(PointFactory.class); when(PointFactory.getPoint(ListingParser.class, "parseListing")).thenReturn(point); final File listingFile = new File("target/unit/test_listing.out"); final String firstError = "%CCL-E-6-CCL(2,12)S0L0.0l1{}Unexpected end of line, symbol must start and end on same line."; final List<String> secondError = Arrays.asList("%CCL-E-9-CCL(2,12)S0L0.0p2{<ILLC>}Unexpected symbol found.", "<ILLC>", "Found <ILLC>", "Expecting <INT> <NAME> <REAL> <STRING> $ ( - + IF"); FileUtils.deleteQuietly(listingFile); final List<String> output = new ArrayList<String>(); output.add("1) drop program blech go"); output.add(firstError); output.add(""); output.add("2) set blah = 'bleu'"); output.addAll(secondError); FileUtils.writeLines(listingFile, output); final ListingParseResult parseResult = parser.parseListing(listingFile); assertThat(parseResult.getWarnings()).isEmpty(); final Collection<? extends CclError> errors = parseResult.getErrors(); assertThat(errors).hasSize(2); final Iterator<? extends CclError> errorsIt = errors.iterator(); assertThat(errorsIt.next().getMessage()).isEqualTo(firstError); final StringBuilder messageBuilder = new StringBuilder(secondError.size()); final Iterator<String> secondErrorIt = secondError.iterator(); messageBuilder.append(secondErrorIt.next()); while (secondErrorIt.hasNext()) { messageBuilder.append(String.format("%n%s", secondErrorIt.next())); } assertThat(errorsIt.next().getMessage()).isEqualTo(messageBuilder.toString().trim()); verify(point).collect(); }
public ListingParseResult parseListing(final File listing) throws IOException { if (listing == null) throw new NullPointerException("Listing cannot be null."); final EtmPoint point = PointFactory.getPoint(getClass(), "parseListing"); final Collection<CclError> errors = new ArrayList<CclError>(); final Collection<CclWarning> warnings = new ArrayList<CclWarning>(); try { for (final Iterator<String> it = readFile(listing).iterator(); it.hasNext();) { final String line = it.next(); if (!LINE_NUM_PATTERN.matcher(line).matches()) { if (line.startsWith("%CCL-E")) errors.add(new CclError(parseMessage(line, it))); else if (line.startsWith("%CCL-W")) warnings.add(new CclWarning(parseMessage(line, it))); } } } finally { point.collect(); } return new ListingParseResult(warnings, errors); }
ListingParser { public ListingParseResult parseListing(final File listing) throws IOException { if (listing == null) throw new NullPointerException("Listing cannot be null."); final EtmPoint point = PointFactory.getPoint(getClass(), "parseListing"); final Collection<CclError> errors = new ArrayList<CclError>(); final Collection<CclWarning> warnings = new ArrayList<CclWarning>(); try { for (final Iterator<String> it = readFile(listing).iterator(); it.hasNext();) { final String line = it.next(); if (!LINE_NUM_PATTERN.matcher(line).matches()) { if (line.startsWith("%CCL-E")) errors.add(new CclError(parseMessage(line, it))); else if (line.startsWith("%CCL-W")) warnings.add(new CclWarning(parseMessage(line, it))); } } } finally { point.collect(); } return new ListingParseResult(warnings, errors); } }
ListingParser { public ListingParseResult parseListing(final File listing) throws IOException { if (listing == null) throw new NullPointerException("Listing cannot be null."); final EtmPoint point = PointFactory.getPoint(getClass(), "parseListing"); final Collection<CclError> errors = new ArrayList<CclError>(); final Collection<CclWarning> warnings = new ArrayList<CclWarning>(); try { for (final Iterator<String> it = readFile(listing).iterator(); it.hasNext();) { final String line = it.next(); if (!LINE_NUM_PATTERN.matcher(line).matches()) { if (line.startsWith("%CCL-E")) errors.add(new CclError(parseMessage(line, it))); else if (line.startsWith("%CCL-W")) warnings.add(new CclWarning(parseMessage(line, it))); } } } finally { point.collect(); } return new ListingParseResult(warnings, errors); }  }
ListingParser { public ListingParseResult parseListing(final File listing) throws IOException { if (listing == null) throw new NullPointerException("Listing cannot be null."); final EtmPoint point = PointFactory.getPoint(getClass(), "parseListing"); final Collection<CclError> errors = new ArrayList<CclError>(); final Collection<CclWarning> warnings = new ArrayList<CclWarning>(); try { for (final Iterator<String> it = readFile(listing).iterator(); it.hasNext();) { final String line = it.next(); if (!LINE_NUM_PATTERN.matcher(line).matches()) { if (line.startsWith("%CCL-E")) errors.add(new CclError(parseMessage(line, it))); else if (line.startsWith("%CCL-W")) warnings.add(new CclWarning(parseMessage(line, it))); } } } finally { point.collect(); } return new ListingParseResult(warnings, errors); }  static ListingParser getInstance(); ListingParseResult parseListing(final File listing); }
ListingParser { public ListingParseResult parseListing(final File listing) throws IOException { if (listing == null) throw new NullPointerException("Listing cannot be null."); final EtmPoint point = PointFactory.getPoint(getClass(), "parseListing"); final Collection<CclError> errors = new ArrayList<CclError>(); final Collection<CclWarning> warnings = new ArrayList<CclWarning>(); try { for (final Iterator<String> it = readFile(listing).iterator(); it.hasNext();) { final String line = it.next(); if (!LINE_NUM_PATTERN.matcher(line).matches()) { if (line.startsWith("%CCL-E")) errors.add(new CclError(parseMessage(line, it))); else if (line.startsWith("%CCL-W")) warnings.add(new CclWarning(parseMessage(line, it))); } } } finally { point.collect(); } return new ListingParseResult(warnings, errors); }  static ListingParser getInstance(); ListingParseResult parseListing(final File listing);  }