Coverage Report - org.jbehave.core.reporters.IdeOnlyConsoleOutput
 
Classes in this File Line Coverage Branch Coverage Complexity
IdeOnlyConsoleOutput
86%
13/15
75%
6/8
2.2
 
 1  
 package org.jbehave.core.reporters;
 2  
 
 3  
 import static java.util.Arrays.asList;
 4  
 
 5  
 import java.io.ByteArrayOutputStream;
 6  
 import java.io.PrintStream;
 7  
 import java.util.List;
 8  
 import java.util.Properties;
 9  
 
 10  
 import org.jbehave.core.configuration.Keywords;
 11  
 
 12  
 /**
 13  
  * Outputs to the console only if running in an IDE. Command line builds (Maven,
 14  
  * Ant) will produce nothing for this particular PrintStreamOutput
 15  
  * specialisation.
 16  
  */
 17  
 public class IdeOnlyConsoleOutput extends TxtOutput {
 18  
 
 19  
     public IdeOnlyConsoleOutput() {
 20  1
         super(output());
 21  1
     }
 22  
 
 23  
     public IdeOnlyConsoleOutput(Keywords keywords) {
 24  3
         super(output(), keywords);
 25  3
     }
 26  
 
 27  
     public IdeOnlyConsoleOutput(Properties outputPatterns, Keywords keywords, boolean reportErrors) {
 28  1
         super(output(), outputPatterns, keywords, reportErrors);
 29  1
     }
 30  
 
 31  
     static PrintStream output() {
 32  5
         if (inIDE()) {
 33  0
             return System.out;
 34  
         }
 35  5
         return new PrintStream(new ByteArrayOutputStream());
 36  
     }
 37  
 
 38  
     static boolean inIDE() {
 39  5
         List<String> idePackages = asList("com.intellij", "org.eclipse");
 40  183
         for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
 41  178
             for (String idePackage : idePackages) {
 42  356
                 if (ste.getClassName().startsWith(idePackage)) {
 43  0
                     return true;
 44  
                 }
 45  
             }
 46  
         }
 47  5
         return false;
 48  
     }
 49  
 }