package edu.umd.cs.findbugs.detect;

import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.PrintingBugReporter;
import edu.umd.cs.findbugs.Priorities;
import edu.umd.cs.findbugs.Project;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import org.junit.Test;

import static org.junit.Assert.*;

public class FindNonShortCircuitTest {

    @Test
    public void testBugTypeAndPriority() {
        PrintingBugReporter bugReporter = new PrintingBugReporter();
        AnalysisContext ctx = AnalysisContext.currentAnalysisContext();
        try {
            if (ctx == null) {
                AnalysisContext.setCurrentAnalysisContext(new AnalysisContext(new Project()));
            }
            FindNonShortCircuit check = new FindNonShortCircuit(bugReporter);
            BugInstance bug = check.createBugInstance();
            assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());
            assertEquals(Priorities.LOW_PRIORITY, bug.getPriority());

            check.sawDangerOld = true;
            bug = check.createBugInstance();
            assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());
            assertEquals(Priorities.NORMAL_PRIORITY, bug.getPriority());

            check.sawNullTestVeryOld = true;
            bug = check.createBugInstance();
            assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());
            assertEquals(Priorities.HIGH_PRIORITY, bug.getPriority());

            check.sawNullTestVeryOld = false;
            check.sawMethodCallOld = true;
            bug = check.createBugInstance();
            assertEquals(FindNonShortCircuit.NS_DANGEROUS_NON_SHORT_CIRCUIT, bug.getType());
            assertEquals(Priorities.HIGH_PRIORITY, bug.getPriority());
        } finally {
            AnalysisContext.setCurrentAnalysisContext(ctx);
        }
    }
}

@@ -243,24 +243,75 @@
 isContext;%0D%0A
+import org.junit.After;%0D%0Aimport org.junit.Before;%0D%0A
 import org.j
@@ -405,59 +405,118 @@
  %7B%0D%0A
-%0D%0A    @Test%0D%0A    public void testBugTypeAndPriority
+    private AnalysisContext ctx;%0D%0A    private FindNonShortCircuit check;%0D%0A%0D%0A    @Before%0D%0A    public void setup
 () %7B
@@ -595,32 +595,16 @@
         
-AnalysisContext 
 ctx = An
@@ -648,27 +648,8 @@
 );%0D%0A
-        try %7B%0D%0A    
     
@@ -668,28 +668,24 @@
 == null) %7B%0D%0A
-    
             
@@ -776,46 +776,18 @@
     
-    %7D%0D%0A            FindNonShortCircuit
+%7D%0D%0A       
  che
@@ -826,32 +826,207 @@
 Reporter);%0D%0A    
+%7D%0D%0A%0D%0A    @After%0D%0A    public void tearDown() %7B%0D%0A        AnalysisContext.setCurrentAnalysisContext(ctx);%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void testDefaultBugTypeAndPriority() %7B%0D%0A
         BugInsta
@@ -1055,36 +1055,32 @@
 BugInstance();%0D%0A
-    
         assertEq
@@ -1143,36 +1143,32 @@
 pe());%0D%0A        
-    
 assertEquals(Pri
@@ -1202,38 +1202,105 @@
 etPriority());%0D%0A
-%0D%0A
     
+%7D%0D%0A%0D%0A    @Test%0D%0A    public void testBugTypeAndPriorityDangerOld() %7B%0D%0A
         check.sa
@@ -1319,35 +1319,43 @@
  true;%0D%0A        
-   
+BugInstance
  bug = check.cre
@@ -1365,36 +1365,32 @@
 BugInstance();%0D%0A
-    
         assertEq
@@ -1453,36 +1453,32 @@
 pe());%0D%0A        
-  
-  
 assertEquals(Pri
@@ -1515,38 +1515,143 @@
 etPriority());%0D%0A
-%0D%0A
     
+%7D%0D%0A%0D%0A    @Test%0D%0A    public void testBugTypeAndPriorityNullTestOld() %7B%0D%0A        check.sawDangerOld = true;%0D%0A
         check.sa
@@ -1676,35 +1676,43 @@
  true;%0D%0A        
-   
+BugInstance
  bug = check.cre
@@ -1730,36 +1730,32 @@
 nce();%0D%0A        
- 
-   
 assertEquals(Fin
@@ -1810,36 +1810,32 @@
 pe());%0D%0A        
-    
 assertEquals(Pri
@@ -1878,22 +1878,93 @@
 ty());%0D%0A
-%0D%0A
     
+%7D%0D%0A%0D%0A    @Test%0D%0A    public void testBugTypeAndPriorityMethodCallOld() %7B%0D%0A
         
@@ -1976,38 +1976,27 @@
 .saw
-NullTestV
+Dang
 er
-y
 Old = 
-false;%0D%0A    
+true;%0D%0A
     
@@ -2039,19 +2039,27 @@
         
-   
+BugInstance
  bug = c
@@ -2081,28 +2081,24 @@
 nstance();%0D%0A
-    
         asse
@@ -2179,28 +2179,24 @@
 );%0D%0A        
-    
 assertEquals
@@ -2247,101 +2247,8 @@
 );%0D%0A
-        %7D finally %7B%0D%0A            AnalysisContext.setCurrentAnalysisContext(ctx);%0D%0A        %7D%0D%0A
     

test refactor