Skip to content

Commit

Permalink
Use String.format in Tap13Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Feb 15, 2017
1 parent 36a469b commit 25fdee0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions tap4j/src/main/java/org/tap4j/parser/Tap13Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public class Tap13Parser implements Parser {
private static final Logger LOGGER = Logger.getLogger(Tap13Parser.class
.getCanonicalName());

/**
* UTF-8 encoding constant.
*/
private static final String UTF8_ENCODING = "UTF-8";

/**
* Stack of stream status information bags. Every bag stores state of the parser
* related to certain indentation level. This is to support subtest feature.
Expand Down Expand Up @@ -129,7 +134,7 @@ public Tap13Parser(String encoding, boolean enableSubtests, boolean planRequired
this.decoder = Charset.forName(encoding).newDecoder();
}
} catch (UnsupportedCharsetException uce) {
throw new ParserException("Invalid encoding: " + encoding, uce);
throw new ParserException(String.format("Invalid encoding: %s", encoding), uce);
}
this.planRequired = planRequired;
}
Expand All @@ -143,7 +148,7 @@ public Tap13Parser(String encoding, boolean enableSubtests, boolean planRequired
* @param enableSubtests Whether subtests are enabled or not
*/
public Tap13Parser(boolean enableSubtests) {
this("UTF-8", enableSubtests);
this(UTF8_ENCODING, enableSubtests);
}

/**
Expand All @@ -154,7 +159,7 @@ public Tap13Parser(boolean enableSubtests) {
* recognize subtests.
*/
public Tap13Parser() {
this("UTF-8", false);
this(UTF8_ENCODING, false);
}

/**
Expand Down Expand Up @@ -192,8 +197,9 @@ public TestSet parseFile(File tapFile) {
} catch (FileNotFoundException e) {
throw new ParserException("TAP file not found: " + tapFile, e);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to close file stream: " + e.getMessage(), e);
throw new ParserException(String.format("Failed to close file stream for file %s: %s: ", tapFile, e.getMessage()), e);
LOGGER.log(Level.SEVERE, String.format("Failed to close file stream: %s", e.getMessage()), e);
throw new ParserException(String.format("Failed to close file stream for file %s: %s: ",
tapFile, e.getMessage()), e);
}
}

Expand All @@ -213,8 +219,7 @@ public TestSet parseTapStream(Readable tapStream) {
}
onFinish();
} catch (Exception e) {
throw new ParserException("Error parsing TAP Stream: "
+ e.getMessage(), e);
throw new ParserException(String.format("Error parsing TAP Stream: %s", e.getMessage()), e);
}

return state.getTestSet();
Expand Down Expand Up @@ -250,8 +255,8 @@ public void parseLine(String tapLine) {
} else {
if (trimmedLine.equals("---")) {
if (text.getIndentation() < baseIndentation) {
throw new ParserException("Invalid indentation. "
+ "Check your TAP Stream. Line: " + tapLine);
throw new ParserException(String.format("Invalid indentation. Check your TAP Stream. Line: %s",
tapLine));
}
state.setInYaml(true);
state.setYamlIndentation(text.getIndentationString());
Expand Down Expand Up @@ -413,9 +418,8 @@ private void parseDiagnostics() {
.load(state.getDiagnosticBuffer().toString());
state.getLastParsedElement().setDiagnostic(metaIterable);
} catch (Exception ex) {
throw new ParserException("Error parsing YAML ["
+ state.getDiagnosticBuffer().toString() + "]: "
+ ex.getMessage(), ex);
throw new ParserException(String.format("Error parsing YAML [%s]: %s",
state.getDiagnosticBuffer().toString(), ex.getMessage()), ex);
}
this.state.getDiagnosticBuffer().setLength(0);
}
Expand Down

0 comments on commit 25fdee0

Please sign in to comment.