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);
        }
    }
}

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.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class FindNonShortCircuitTest {
    private AnalysisContext ctx;
    private FindNonShortCircuit check;

    @Before
    public void setup() {
        PrintingBugReporter bugReporter = new PrintingBugReporter();
        ctx = AnalysisContext.currentAnalysisContext();
        if (ctx == null) {
            AnalysisContext.setCurrentAnalysisContext(new AnalysisContext(new Project()));
        }
        check = new FindNonShortCircuit(bugReporter);
    }

    @After
    public void tearDown() {
        AnalysisContext.setCurrentAnalysisContext(ctx);
    }

    @Test
    public void testDefaultBugTypeAndPriority() {
        BugInstance bug = check.createBugInstance();
        assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());
        assertEquals(Priorities.LOW_PRIORITY, bug.getPriority());
    }

    @Test
    public void testBugTypeAndPriorityDangerOld() {
        check.sawDangerOld = true;
        BugInstance bug = check.createBugInstance();
        assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());
        assertEquals(Priorities.NORMAL_PRIORITY, bug.getPriority());
    }

    @Test
    public void testBugTypeAndPriorityNullTestOld() {
        check.sawDangerOld = true;
        check.sawNullTestVeryOld = true;
        BugInstance bug = check.createBugInstance();
        assertEquals(FindNonShortCircuit.NS_NON_SHORT_CIRCUIT, bug.getType());
        assertEquals(Priorities.HIGH_PRIORITY, bug.getPriority());
    }

    @Test
    public void testBugTypeAndPriorityMethodCallOld() {
        check.sawDangerOld = true;
        check.sawMethodCallOld = true;
        BugInstance bug = check.createBugInstance();
        assertEquals(FindNonShortCircuit.NS_DANGEROUS_NON_SHORT_CIRCUIT, bug.getType());
        assertEquals(Priorities.HIGH_PRIORITY, bug.getPriority());
    }
}

test refactor