Mehr zum Thema RevealJS können Sie hier lesen:
This file contains hidden or 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
public class MemoryAppenderAssertion extends AbstractAssert<MemoryAppenderAssertion, MemoryAppender> { | |
protected MemoryAppenderAssertion(MemoryAppender memoryAppender) { | |
super(memoryAppender, MemoryAppenderAssertion.class); | |
} | |
public static MemoryAppenderAssertion assertThat(MemoryAppender memoryAppender) { | |
return new MemoryAppenderAssertion(memoryAppender); | |
} | |
This file contains hidden or 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
assertThat(memoryAppender) | |
.containsException(ConcurrentModificationException.class) | |
.contains("My exception message", Level.ERROR); |
This file contains hidden or 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
Class<ConcurrentModificationException> expectedEx = ConcurrentModificationException.class; | |
assertThat(memoryAppender.containsException(expectedEx)) | |
.describedAs(String.format("should have found stack trace with %s in the log", | |
expectedEx.getCanonicalName())) | |
.isTrue(); | |
String expectedMsg = "My exception message"; | |
Level expectedLevel = Level.ERROR; | |
assertThat(memoryAppender.contains(expectedMsg, expectedLevel)) | |
.describedAs(String.format("%s-level log messages expected to contain '%s'", expectedLevel, expectedMsg)) | |
.isTrue(); |
Mehr zum Thema Clean Code können Sie hier lesen:
Mehr zum Thema Tests können Sie hier lesen:
This file contains hidden or 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
List queryResults = query.getResultList(); | |
if (queryResults.size() > 1) { | |
throw new NonUniqueResultException( | |
"Got multiple records with the same workspace root: " + workspaceName); | |
} | |
Optional<DirectoryBean> workspaceRootDir = queryResults.stream().findFirst(); | |
if (workspaceRootDir.isEmpty()) { | |
if (create) { |
This file contains hidden or 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
Optional<DirectoryBean> workspaceRootDir = query.getResultList().stream().findFirst(); | |
if (workspaceRootDir.isEmpty()) { | |
if (create) { | |
// Workspace existiert nicht: anlegen! | |
workspaceRootDir = Optional.of(createWorkspaceRootDir(null, workspaceName, false)); | |
} else { | |
throw new FileNotFoundException("Unknown workspace root: " + workspaceName); | |
} | |
} |
This file contains hidden or 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
DirectoryBean workspaceRootDir; | |
try { | |
workspaceRootDir = (DirectoryBean) query.getSingleResult(); | |
} catch (NoResultException nre) { | |
if (create) { | |
// Workspace existiert nicht: anlegen! | |
workspaceRootDir = createWorkspaceRootDir(null, workspaceName, false); | |
} else { | |
throw new FileNotFoundException("Unknown workspace root: " + workspaceName); | |
} |
Der vorliegende Artikel ist Teil einer Serie zum Thema Exception Handling. Mehr können Sie hier lesen: