Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #81 from skivol/feature/consider-maven-surefire-de…
Browse files Browse the repository at this point in the history
…bug-property-while-deciding-if-we-are-debugging

Consider also "maven.surefire.debug" environment variable while decid…
  • Loading branch information
splitfeed authored Sep 4, 2018
2 parents ee10159 + 0af5b0a commit b226ee5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
* Utilities for debugging in the development environment.
*/
public class DebugUtil {
public static final boolean IS_DEBUG = isIdePresent();
public static final boolean IS_DEBUG = isIdePresent(DebugUtil.class.getClassLoader()) || isMavenDebug();

/**
* Checks for the presence of an IDE, currently just IntelliJ.
* @param classLoader to use for the check
*/
private static boolean isIdePresent() {
ClassLoader classLoader = DebugUtil.class.getClassLoader();
static boolean isIdePresent(ClassLoader classLoader) {
return classLoader.getResource("com/intellij") != null;
}

static boolean isMavenDebug() {
return Boolean.getBoolean("maven.surefire.debug");
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package se.fortnox.reactivewizard.util;

import org.junit.Test;
import org.mockito.Mockito;

import java.net.MalformedURLException;
import java.net.URL;

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;

public class DebugUtilTest {

@Test
public void testIsIdePresent() {
assertThat(DebugUtil.IS_DEBUG).isNotNull();
public void testIsDebug() {
assertThat(DebugUtil.IS_DEBUG).isNotNull(); // will be true if running from Intellij IDEA and false from command line
}

@Test
public void testIsIdePresent() throws MalformedURLException {
ClassLoader classLoaderWithIdeaDebugger = Mockito.mock(ClassLoader.class);
when(classLoaderWithIdeaDebugger.getResource(eq("com/intellij")))
.thenReturn(new URL("jar:file:/path/to/debugger-agent-storage.jar!/com/intellij"));

assertThat(DebugUtil.isIdePresent(classLoaderWithIdeaDebugger)).isTrue();
}

@Test
public void testIsMavenDebug() {
String debugPropName = "maven.surefire.debug";
boolean originalSurefireDebugProp = Boolean.getBoolean(debugPropName);
System.setProperty(debugPropName, "true");

assertThat(DebugUtil.isMavenDebug()).isTrue();

// Clean up
System.setProperty(debugPropName, String.valueOf(originalSurefireDebugProp));
}
}

0 comments on commit b226ee5

Please sign in to comment.