Skip to content

Instantly share code, notes, and snippets.

View dsmf's full-sized avatar

Matthias Fischer dsmf

  • doubleSlash Net-Business GmbH
View GitHub Profile
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);
}
assertThat(memoryAppender)
.containsException(ConcurrentModificationException.class)
.contains("My exception message", Level.ERROR);
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();
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) {
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);
}
}
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);
}