diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-04-05 20:50:40 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-04-05 20:50:40 +0000 |
commit | 65ccec11cb7d8806b0da6c9c8dead6706621c1e7 (patch) | |
tree | c9c5b71607dd745fbea0bc80cbfdd6244ca5cea0 /src/excelant/java | |
parent | d8421364646f195743625f24848205f999cdca53 (diff) | |
download | poi-65ccec11cb7d8806b0da6c9c8dead6706621c1e7.tar.gz poi-65ccec11cb7d8806b0da6c9c8dead6706621c1e7.zip |
Sonar fixes - String literals should not be duplicated
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876163 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/excelant/java')
-rw-r--r-- | src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java | 115 |
1 files changed, 52 insertions, 63 deletions
diff --git a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java index 586f855667..2fd45cab15 100644 --- a/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java +++ b/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java @@ -19,6 +19,7 @@ package org.apache.poi.ss.excelant; import java.util.Iterator; import java.util.LinkedList; +import java.util.function.Supplier; import org.apache.poi.ss.excelant.util.ExcelAntEvaluationResult; import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil; @@ -30,131 +31,126 @@ import org.apache.tools.ant.Task; * This class represents a single test. In order for the test any and all * ExcelAntEvaluateCell evaluations must pass. Therefore it is recommended * that you use only 1 evaluator but you can use more if you choose. - * + * * @author Jon Svede ( jon [at] loquatic [dot] com ) * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov ) * */ +@SuppressWarnings("unused") public class ExcelAntTest extends Task{ private LinkedList<ExcelAntEvaluateCell> evaluators; - + private LinkedList<Task> testTasks; - + private String name; - + private double globalPrecision; - + private boolean showSuccessDetails; - + private boolean showFailureDetail; LinkedList<String> failureMessages; - + private ExcelAntWorkbookUtil workbookUtil; - + private boolean passed = true; - + public ExcelAntTest() { evaluators = new LinkedList<>(); failureMessages = new LinkedList<>(); testTasks = new LinkedList<>(); } - + public void setPrecision( double precision ) { globalPrecision = precision; } - + public void setWorkbookUtil( ExcelAntWorkbookUtil wbUtil ) { workbookUtil = wbUtil; } - - + + public void setShowFailureDetail( boolean value ) { showFailureDetail = value; } - + public void setName( String nm ) { name = nm; } - + public String getName() { return name; } - + public void setShowSuccessDetails( boolean details ) { showSuccessDetails = details; } - + public boolean showSuccessDetails() { return showSuccessDetails; } - + public void addSetDouble( ExcelAntSetDoubleCell setter ) { addSetter( setter ); } - + public void addSetString( ExcelAntSetStringCell setter ){ addSetter( setter ); } - + public void addSetFormula( ExcelAntSetFormulaCell setter ) { addSetter( setter ); } - + public void addHandler( ExcelAntHandlerTask handler ) { testTasks.add( handler ); } - + private void addSetter( ExcelAntSet setter ) { -// setters.add( setter ); testTasks.add( setter ); } - + public void addEvaluate( ExcelAntEvaluateCell evaluator ) { -// evaluators.add( evaluator ); testTasks.add( evaluator ); } - -// public LinkedList<ExcelAntSet> getSetters() { -// return setters; -// } protected LinkedList<ExcelAntEvaluateCell> getEvaluators() { return evaluators; } - + @Override public void execute() throws BuildException { - + Iterator<Task> taskIt = testTasks.iterator(); int testCount = evaluators.size(); int failureCount = 0; - + // roll over all sub task elements in one loop. This allows the - // ordering of the sub elements to be considered. + // ordering of the sub elements to be considered. while( taskIt.hasNext() ) { Task task = taskIt.next(); - + // log( task.getClass().getName(), Project.MSG_INFO ); - + if( task instanceof ExcelAntSet ) { ExcelAntSet set = (ExcelAntSet) task; set.setWorkbookUtil(workbookUtil); set.execute(); } - + if( task instanceof ExcelAntHandlerTask ) { ExcelAntHandlerTask handler = (ExcelAntHandlerTask)task; handler.setEAWorkbookUtil(workbookUtil ); handler.execute(); } - + if (task instanceof ExcelAntEvaluateCell ) { ExcelAntEvaluateCell eval = (ExcelAntEvaluateCell)task; eval.setWorkbookUtil( workbookUtil ); - + if( globalPrecision > 0 ) { log( "setting globalPrecision to " + globalPrecision + " in the evaluator", Project.MSG_VERBOSE ); eval.setGlobalPrecision( globalPrecision ); @@ -163,48 +159,41 @@ public class ExcelAntTest extends Task{ try { eval.execute(); ExcelAntEvaluationResult result = eval.getResult(); - if( result.didTestPass() && - !result.evaluationCompleteWithError()) { + + Supplier<String> details = () -> + result.getCellName() + ". It evaluated to " + + result.getReturnValue() + " when the value of " + + eval.getExpectedValue() + " with precision of " + + eval.getPrecision(); + + if( result.didTestPass() && !result.evaluationCompleteWithError()) { if(showSuccessDetails) { - log("Succeeded when evaluating " + - result.getCellName() + ". It evaluated to " + - result.getReturnValue() + " when the value of " + - eval.getExpectedValue() + " with precision of " + - eval.getPrecision(), Project.MSG_INFO ); + log("Succeeded when evaluating " + details.get(), Project.MSG_INFO ); } } else { if(showFailureDetail) { - failureMessages.add( "\tFailed to evaluate cell " + - result.getCellName() + ". It evaluated to " + - result.getReturnValue() + " when the value of " + - eval.getExpectedValue() + " with precision of " + - eval.getPrecision() + " was expected." ); - + failureMessages.add( "\tFailed to evaluate cell " + details.get() + " was expected." ); } passed = false; failureCount++; - + if(eval.requiredToPass()) { - throw new BuildException( "\tFailed to evaluate cell " + - result.getCellName() + ". It evaluated to " + - result.getReturnValue() + " when the value of " + - eval.getExpectedValue() + " with precision of " + - eval.getPrecision() + " was expected." ); + throw new BuildException( "\tFailed to evaluate cell " + details.get() + " was expected." ); } } } catch( NullPointerException npe ) { // this means the cell reference in the test is bad. - log( "Cell assignment " + eval.getCell() + " in test " + getName() + + log( "Cell assignment " + eval.getCell() + " in test " + getName() + " appears to point to an empy cell. Please check the " + " reference in the ant script.", Project.MSG_ERR ); } } } - + if(!passed) { - log( "Test named " + name + " failed because " + failureCount + - " of " + testCount + " evaluations failed to " + - "evaluate correctly.", + log( "Test named " + name + " failed because " + failureCount + + " of " + testCount + " evaluations failed to " + + "evaluate correctly.", Project.MSG_ERR ); if(showFailureDetail && failureMessages.size() > 0 ) { for (String failureMessage : failureMessages) { @@ -215,7 +204,7 @@ public class ExcelAntTest extends Task{ } public boolean didTestPass() { - + return passed; } } |