package hudson.plugins.emailext.plugins.content;

import hudson.Extension;
import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.test.AbstractTestResultAction;
import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;

import java.io.IOException;

/**
 * Displays the number of tests.
 *
 * @author Seiji Sogabe
 */
@Extension
public class TestCountsContent extends DataBoundTokenMacro {

    public static final String MACRO_NAME = "TEST_COUNTS";
    private static final String VAR_DEFAULT_VALUE = "total";

    @Parameter
    public String var = VAR_DEFAULT_VALUE;
    
    @Override
    public boolean acceptsMacroName(String macroName) {
        return macroName.equals(MACRO_NAME);
    }
   
    @Override
    public String evaluate(AbstractBuild<?, ?> build, TaskListener listener, String macroName)
            throws MacroEvaluationException, IOException, InterruptedException {
        return evaluate(build, build.getWorkspace(), listener, macroName);
    }

    @Override
    public String evaluate(Run<?, ?> run, FilePath workspace, TaskListener listener, String macroName)
            throws MacroEvaluationException, IOException, InterruptedException {

        AbstractTestResultAction<?> action = run.getAction(AbstractTestResultAction.class);
        if (action == null) {
            return "";
        }

        var = var.toLowerCase();
        
        if ("total".equals(var)) {
            return String.valueOf(action.getTotalCount());
        } else if ("pass".equals(var)) {
            return String.valueOf(action.getTotalCount()-action.getFailCount()-action.getSkipCount());
        } else if ("fail".equals(var)) {
            return String.valueOf(action.getFailCount());
        } else if ("skip".equals(var)) {
            return String.valueOf(action.getSkipCount());
        }

        return "";
    }
}

@@ -1525,35 +1525,53 @@
     
-if (%22total%22.equals(var)) %7B%0A
+switch (var) %7B%0A            case %22total%22:%0A    
     
@@ -1637,41 +1637,29 @@
     
-%7D else if (%22pass%22.equals(var)) %7B%0A
+    case %22pass%22:%0A    
     
@@ -1702,33 +1702,35 @@
 .getTotalCount()
--
+ - 
 action.getFailCo
@@ -1734,17 +1734,19 @@
 lCount()
--
+ - 
 action.g
@@ -1773,41 +1773,29 @@
     
-%7D else if (%22fail%22.equals(var)) %7B%0A
+    case %22fail%22:%0A    
     
@@ -1860,41 +1860,29 @@
     
-%7D else if (%22skip%22.equals(var)) %7B%0A
+    case %22skip%22:%0A    
     

Replace if with switch