forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! Too big error message JabRef#4827 (adding unit tests)
- Loading branch information
dpolishc
committed
May 14, 2019
1 parent
4865eae
commit b9641f9
Showing
3 changed files
with
47 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/jabref/logic/util/strings/StringFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.jabref.logic.util.strings; | ||
|
||
public class StringFormatter { | ||
|
||
public String formatErrorMessage(Exception e) { | ||
String message = e.getMessage(); | ||
StringBuilder errorFormatter = new StringBuilder(); | ||
int wordCounter = 0; | ||
for (int i = 0; i < message.length(); i++) { | ||
if (message.charAt(i) == ' ' && ++wordCounter % 25 == 0) { | ||
errorFormatter.append(" ").append(System.lineSeparator()); | ||
continue; | ||
} | ||
errorFormatter.append(message.charAt(i)); | ||
} | ||
return errorFormatter.toString(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/java/org/jabref/logic/util/strings/StringFormatterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.jabref.logic.util.strings; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class StringFormatterTest { | ||
|
||
private String error = "The server time zone value 'MSK' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support."; | ||
|
||
@Test | ||
void formatErrorMessage() { | ||
StringFormatter stringFormatter = new StringFormatter(); | ||
Exception exceptionUnderTest = new Exception(error); | ||
String errorToBeThrown = stringFormatter.formatErrorMessage(exceptionUnderTest); | ||
String[] lines = errorToBeThrown.split(System.lineSeparator()); | ||
for (int i = 0; i < lines.length; i++) { | ||
String line = lines[i]; | ||
String[] split = line.split("\\s+"); | ||
if (i != lines.length - 1) { | ||
assertEquals(25, split.length); | ||
} | ||
} | ||
|
||
} | ||
} |