Repository navigation
#2385: Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener #2639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NikoFoutsitzis
wants to merge
44
commits into
devonfw:main
Choose a base branch
from
NikoFoutsitzis:cleanup/2385-IdeLogEntry-and-IdeLogListener-and-IdeGuiLogListener
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−59
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
c246147
Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener
NikoFoutsitzis 27fa9bf
Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener
NikoFoutsitzis dadaeae
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis 21e1d05
Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener
NikoFoutsitzis 39c98da
Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener
NikoFoutsitzis 8e4459b
fixed format violations
NikoFoutsitzis ea40963
Merge remote-tracking branch 'origin/cleanup/2385-IdeLogEntry-and-Ide…
NikoFoutsitzis 5db05ea
#2385 cleanup
NikoFoutsitzis bf5c6fe
fixed violations ConsoleController.java
NikoFoutsitzis a1a1c78
Fixed violations
NikoFoutsitzis 9904dd9
fixed violations
NikoFoutsitzis 062db32
Update gui/src/test/java/com/devonfw/ide/gui/core/context/IdeTestGuiL…
NikoFoutsitzis 52c1ec7
Update cli/src/main/java/com/devonfw/tools/ide/log/IdeLogListener.java
NikoFoutsitzis f9469be
Update gui/src/test/java/com/devonfw/ide/gui/core/mainwindow/console/…
NikoFoutsitzis faa6f4b
Merge remote-tracking branch 'origin/cleanup/2385-IdeLogEntry-and-Ide…
NikoFoutsitzis 889a446
improved Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener
NikoFoutsitzis 1b84d17
Update gui/src/test/java/com/devonfw/ide/gui/core/mainwindow/console/…
NikoFoutsitzis 762abe8
Update gui/src/test/java/com/devonfw/ide/gui/core/context/IdeGuiLogLi…
NikoFoutsitzis b9c974d
Javadoc changes to IdeLogListener
NikoFoutsitzis ead32aa
Merge remote-tracking branch 'origin/cleanup/2385-IdeLogEntry-and-Ide…
NikoFoutsitzis cf813c3
Update gui/src/test/java/com/devonfw/ide/gui/core/context/IdeGuiLogLi…
NikoFoutsitzis 12d5370
added (... && error == null)
NikoFoutsitzis 49bc947
Merge remote-tracking branch 'origin/cleanup/2385-IdeLogEntry-and-Ide…
NikoFoutsitzis 1545c66
fixed IdeGuiLogListenerTest
NikoFoutsitzis 2c462a4
Merge remote-tracking branch 'upstream/main' into cleanup/2385-IdeLog…
NikoFoutsitzis 5202603
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis a517cb8
Update gui/src/main/java/com/devonfw/ide/gui/core/service/CommandletS…
NikoFoutsitzis ddc1c75
Fixed format violations
NikoFoutsitzis 2bcb847
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis 5423db4
Added tests in IdeGuiLogListenerTest, changed IdeGuiLogListener and I…
NikoFoutsitzis 15dd538
Merge remote-tracking branch 'origin/cleanup/2385-IdeLogEntry-and-Ide…
NikoFoutsitzis dc8655e
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis c05e7e3
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis cb1a407
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis d5f78d5
Changed ConsolePanelTest
NikoFoutsitzis f73abe6
Small touch-ups
NikoFoutsitzis b760f26
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis cd221fb
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis 77860d4
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
quando632 3121c0e
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis e9d6050
Added validation for all constructors of IdeLogEntry
NikoFoutsitzis a2c9c13
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis fcd921c
Validate IdeLogEntry and prevent invalid log entries in Slf4jLoggerAd…
NikoFoutsitzis cc2f065
Merge branch 'main' into cleanup/2385-IdeLogEntry-and-IdeLogListener-…
NikoFoutsitzis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
117 changes: 117 additions & 0 deletions
117
gui/src/test/java/com/devonfw/ide/gui/core/context/IdeGuiLogListenerTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package com.devonfw.ide.gui.core.context; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.devonfw.ide.gui.core.event.GuiEventBus; | ||
| import com.devonfw.ide.gui.core.event.console.LogEvent; | ||
| import com.devonfw.tools.ide.context.IdeStartContextImpl; | ||
| import com.devonfw.tools.ide.log.IdeLogEntry; | ||
| import com.devonfw.tools.ide.log.IdeLogLevel; | ||
| import com.devonfw.tools.ide.log.IdeLogListenerNone; | ||
|
|
||
| import io.github.mmm.event.EventListener; | ||
|
|
||
| /** | ||
| * Tests for {@link IdeGuiLogListener}. | ||
| */ | ||
| public class IdeGuiLogListenerTest extends Assertions { | ||
|
|
||
| /** | ||
| * An {@link EventListener} for {@link LogEvent} that records every event published on the {@link GuiEventBus} instead of touching the JavaFX toolkit, so the | ||
| * number of times {@link IdeGuiLogListener#onLog(IdeLogEntry)} sends a message can be counted. | ||
| */ | ||
| private static final class RecordingLogListener implements EventListener<LogEvent> { | ||
|
|
||
| private final List<IdeLogEntry> entries = new ArrayList<>(); | ||
|
|
||
| @Override | ||
| public void onEvent(LogEvent event) { | ||
|
|
||
| this.entries.add(event.logEntry()); | ||
| } | ||
|
|
||
| List<IdeLogEntry> getEntries() { | ||
| return this.entries; | ||
| } | ||
| } | ||
|
|
||
|
NikoFoutsitzis marked this conversation as resolved.
|
||
| /** | ||
| * {@link IdeStartContextImpl} holds its state in a process-wide static field that is (re)assigned by every construction and offers no reset hook. This test | ||
| * installs a buffering {@link IdeGuiLogListener} into that static; without cleanup it would leak into every other gui test running in the same surefire JVM, | ||
| * routing their SLF4J log events into the leftover buffering listener. Restore a neutral, non-buffering no-op context afterwards. | ||
| */ | ||
| @AfterEach | ||
| void resetStartContext() { | ||
|
|
||
| new IdeStartContextImpl(IdeLogLevel.INFO, IdeLogListenerNone.INSTANCE); | ||
| } | ||
|
|
||
| @Test | ||
| void testMessageOnlySendOnce() { | ||
|
quando632 marked this conversation as resolved.
|
||
|
|
||
| GuiEventBus eventBus = new GuiEventBus(); | ||
| RecordingLogListener recorder = new RecordingLogListener(); | ||
| eventBus.addListener(LogEvent.class, recorder); | ||
| IdeGuiLogListener listener = new IdeGuiLogListener(eventBus); | ||
| listener.flushAndEndBuffering(); | ||
|
|
||
| String message = "TestMessage"; | ||
| IdeLogEntry entry = new IdeLogEntry(IdeLogLevel.INFO, message); | ||
| boolean accepted = listener.onLog(entry); | ||
|
|
||
| assertThat(accepted).as("onLog() should accept the entry").isTrue(); | ||
| assertThat(recorder.getEntries()).as("the entry must be forwarded to the console exactly once").hasSize(1); | ||
| assertThat(recorder.getEntries().get(0).message()).isEqualTo(message); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void testBufferedMessageShownOnceAfterFlush() { | ||
|
|
||
| Logger log = LoggerFactory.getLogger(IdeGuiLogListenerTest.class); | ||
| GuiEventBus eventBus = new GuiEventBus(); | ||
| RecordingLogListener recorder = new RecordingLogListener(); | ||
| eventBus.addListener(LogEvent.class, recorder); | ||
| IdeGuiLogListener listener = new IdeGuiLogListener(eventBus); | ||
| new IdeStartContextImpl(IdeLogLevel.INFO, listener); | ||
|
|
||
| log.warn("TestMessage"); | ||
| assertThat(recorder.getEntries()).as("nothing is shown while buffering").isEmpty(); | ||
|
|
||
| listener.flushAndEndBuffering(); | ||
| assertThat(recorder.getEntries()).extracting(IdeLogEntry::message).containsExactly("TestMessage"); | ||
| } | ||
|
NikoFoutsitzis marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| void testNullMessage() { | ||
|
|
||
| Logger log = LoggerFactory.getLogger(IdeGuiLogListenerTest.class); | ||
| assertThatCode(() -> log.warn((String) null)).doesNotThrowAnyException(); | ||
|
|
||
|
NikoFoutsitzis marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Test | ||
| void testEntryWithErrorAndNullMessageIsForwardedUnchanged() { | ||
|
|
||
| GuiEventBus eventBus = new GuiEventBus(); | ||
| RecordingLogListener recorder = new RecordingLogListener(); | ||
| eventBus.addListener(LogEvent.class, recorder); | ||
| IdeGuiLogListener listener = new IdeGuiLogListener(eventBus); | ||
| listener.flushAndEndBuffering(); | ||
|
|
||
| RuntimeException error = new NullPointerException(); | ||
| IdeLogEntry entry = new IdeLogEntry(IdeLogLevel.ERROR, null, null, null, error); | ||
| listener.onLog(entry); | ||
|
|
||
| assertThat(recorder.getEntries()).first().isSameAs(entry); | ||
| assertThat(recorder.getEntries().get(0).error()).isSameAs(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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.