Skip to content

Commit

Permalink
Add ability to track and verify error logs in tests. Verify invalid i…
Browse files Browse the repository at this point in the history
…nclude dir error message
  • Loading branch information
evie-lau committed Oct 27, 2023
1 parent e1820ae commit ece394f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ private Set<File> getAdditionalJsons() {
*/
public abstract void error(String msg, Throwable e);

/**
* Check if any of the logged errors contain the given string.
*
* @param msg
* @return
*/
public abstract boolean containsErrorMessage(String msg);

/**
* Returns whether debug is enabled by the current logger
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class BaseInstallFeatureUtilTest {
public File installDir;
public File buildDir;
public String verify = "enforce";

private ArrayList<String> errorMessages = new ArrayList<String>();

@Rule
public TemporaryFolder temp = new TemporaryFolder();
Expand Down Expand Up @@ -87,13 +89,24 @@ public void info(String msg) {
@Override
public void error(String msg) {
// not needed for tests
errorMessages.add(msg);
}

@Override
public void error(String msg, Throwable e) {
// not needed for tests
}

@Override
public boolean containsErrorMessage(String msg) {
for (String error : errorMessages) {
if (error.contains(msg)) {
return true;
}
}
return false;
}

@Override
public boolean isDebugEnabled() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ public void testInvalidIncludeDir() throws Exception {
expected.add("orig");

verifyServerFeatures(expected);
util.containsErrorMessage("Path specified a file, but resource exists as a directory (path=includeDir)");
}

@Test
Expand Down

0 comments on commit ece394f

Please sign in to comment.