Skip to content

Commit

Permalink
#24: Fixed NPE in log storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Invictum committed Jun 22, 2018
1 parent b393ba7 commit 01448c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/github/invictum/reportportal/LogStorage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.invictum.reportportal;

import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.Logs;

import java.util.ArrayList;
Expand Down Expand Up @@ -30,10 +31,13 @@ public void collect(Logs seleniumLogs) {
}
// Collect all available logs
types.get().ifPresent(types -> types.forEach(type -> {
List<EnhancedLogEntry> typedLogs = seleniumLogs.get(type).getAll().stream()
.map(log -> new EnhancedLogEntry(type, log.getLevel(), log.getTimestamp(), log.getMessage()))
.collect(Collectors.toList());
logs.get().addAll(typedLogs);
LogEntries logEntries = seleniumLogs.get(type);
if (logEntries != null) {
List<EnhancedLogEntry> typedLogs = logEntries.getAll().stream()
.map(log -> new EnhancedLogEntry(type, log.getLevel(), log.getTimestamp(), log.getMessage()))
.collect(Collectors.toList());
logs.get().addAll(typedLogs);
}
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public void collectAvailableTypesOnlyOnceTest() {
storage.collect(logsMock);
Mockito.verify(logsMock, Mockito.times(1)).getAvailableLogTypes();
}

@Test
public void skipCollectionIfNull() {
Mockito.when(logsMock.get("data")).thenReturn(null);
storage.collect(logsMock);
Assert.assertTrue(storage.query(item -> true).isEmpty());
}
}

0 comments on commit 01448c2

Please sign in to comment.