Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.Enumeration;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.shell.core.CommandResult;
Expand All @@ -36,6 +41,25 @@ public void before() {
testString = "This is a test string.";
}

@After
public void after() {
// This removes and cleans up the LogWrapper instance so that subsequent tests don't fail.
removeLogWrapper();
}

void removeLogWrapper() {
Logger rootLogger = LogManager.getLogManager().getLogger("");

for (Enumeration<String> enumeration = LogManager.getLogManager().getLoggerNames(); enumeration
.hasMoreElements();) {
String loggerName = enumeration.nextElement();
Logger logger = Logger.getLogger(loggerName);
if (logger.getParent() != null && logger.getParent().getName().endsWith(".LogWrapper")) {
logger.setParent(rootLogger);
}
}
}

@Test
public void testWrapTest() {
assertThat(Gfsh.wrapText(testString, 0, -1)).isEqualTo(testString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.junit.Before;
import org.junit.Test;


public class GfshConsoleModeIntegrationTest {
public class GfshConsoleModeUnitTest extends GfshAbstractUnitTest {

@Override
@Before
public void before() {
super.before();
gfsh = new Gfsh(true, null, new GfshConfig());
}

/**
* This test should remain an integration test as it checks the state of various Loggers.
* If run in conjunction with other (Gfsh) tests, these checks may fail.
*/
@Test
public void consoleModeShouldRedirectOnlyJDKLoggers() {
Gfsh gfsh = new Gfsh(true, null, new GfshConfig());
gfsh = new Gfsh(true, null, new GfshConfig());
LogManager logManager = LogManager.getLogManager();
Enumeration<String> loggerNames = logManager.getLoggerNames();
// when initialized in console mode, all log messages will show up in console
Expand Down