Skip to content

Commit

Permalink
Fixed Checkstyle warnings and spotless:apply.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-Draeger committed Nov 29, 2024
1 parent c7c321a commit 72eb26b
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@

package com.draeger.medical.sdccc.util;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicBoolean;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.jupiter.api.Test;

/**
* Unit tests for the {@linkplain TriggerOnErrorOrWorseLogAppender}
* Unit tests for the {@linkplain TriggerOnErrorOrWorseLogAppender}.
*/
public class TriggerOnErrorOrWorseLogAppenderTest {

/**
* Test if the append method handles all Log Levels appropriately.
*/
@Test
public void testAppendWithDifferentLogLevels() {
testAppend(Level.ALL, false);
Expand All @@ -36,16 +38,20 @@ public void testAppendWithDifferentLogLevels() {
testAppend(Level.OFF, true);
}

public void testAppend(Level level, boolean expectHandlerCall) {
/**
* Used by the unit test testAppendWithDifferentLogLevels().
* @param level the Log Level to test
* @param expectHandlerCall true if it is expected that the Handler is called, false otherwise.
*/
private void testAppend(final Level level, final boolean expectHandlerCall) {

AtomicBoolean flag = new AtomicBoolean(false);
final AtomicBoolean flag = new AtomicBoolean(false);

// given
Filter filter = mock(Filter.class);
TriggerOnErrorOrWorseLogAppender classUnderTest = new TriggerOnErrorOrWorseLogAppender("log",
filter);
final Filter filter = mock(Filter.class);
final TriggerOnErrorOrWorseLogAppender classUnderTest = new TriggerOnErrorOrWorseLogAppender("log", filter);
classUnderTest.setOnErrorOrWorseHandler((LogEvent event) -> flag.set(true));
LogEvent event = mock(LogEvent.class);
final LogEvent event = mock(LogEvent.class);
when(event.getLevel()).thenReturn(level);

// when
Expand All @@ -58,5 +64,4 @@ public void testAppend(Level level, boolean expectHandlerCall) {
assertFalse(flag.get());
}
}

}

0 comments on commit 72eb26b

Please sign in to comment.