From cb5ff8f4cffcfa8ec5cd1996a0dbbc8a48ab573b Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 4 Aug 2013 16:38:01 +0000 Subject: [PATCH] Adjust build.xml to run JaCoCo coverage when running unit tests when flag coverage.enabled is set to true, download necessary jars, add jacoco:coverage to junit targets and a testcoveragereport target which produces the coverage report. Also fix a test that is affected by JaCoCo and add slightly more coverage in another test. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1510243 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 268 +++++++++++++----- .../util/ExcelAntWorkbookUtilTestHelper.java | 4 - .../util/TestExcelAntWorkbookUtil.java | 18 ++ .../hwpf/model/TestDocumentProperties.java | 9 + 4 files changed, 218 insertions(+), 81 deletions(-) diff --git a/build.xml b/build.xml index 1fc0d4cf4f..ace10eb2e8 100644 --- a/build.xml +++ b/build.xml @@ -151,6 +151,12 @@ under the License. + + + + + + @@ -164,6 +170,11 @@ under the License. + + + + + @@ -255,6 +266,13 @@ under the License. + + + + + + + @@ -316,6 +334,8 @@ under the License. + + @@ -349,6 +369,19 @@ under the License. + + + + + + + + + + + + + @@ -622,9 +655,77 @@ under the License. - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -634,24 +735,27 @@ under the License. - - - - - - - - - - - - - - - - + depends="compile-main, -test-main-check,jacocotask" xmlns:jacoco="antlib:org.jacoco.ant"> + + + + + + + + + + + + + + + + + + + @@ -672,28 +776,31 @@ under the License. - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -709,29 +816,33 @@ under the License. - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + @@ -754,10 +865,10 @@ under the License. - + - + @@ -771,21 +882,24 @@ under the License. - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java index a8c7f01cf8..16189f1d50 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilTestHelper.java @@ -30,23 +30,19 @@ public class ExcelAntWorkbookUtilTestHelper extends ExcelAntWorkbookUtil { public ExcelAntWorkbookUtilTestHelper(String fName) { super(fName); - // TODO Auto-generated constructor stub } public ExcelAntWorkbookUtilTestHelper(Workbook wb) { super(wb); - // TODO Auto-generated constructor stub } @Override public UDFFinder getFunctions() { - // TODO Auto-generated method stub return super.getFunctions(); } @Override public FormulaEvaluator getEvaluator(String excelFileName) { - // TODO Auto-generated method stub return super.getEvaluator(excelFileName); } diff --git a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java index ad95c4307b..ae346fe25c 100644 --- a/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java +++ b/src/excelant/testcases/org/apache/poi/ss/excelant/util/TestExcelAntWorkbookUtil.java @@ -16,14 +16,21 @@ ==================================================================== */ package org.apache.poi.ss.excelant.util; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import junit.framework.TestCase; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.examples.formula.CalculateMortgageFunction; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.FormulaEvaluator; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.tools.ant.BuildException; public class TestExcelAntWorkbookUtil extends TestCase { @@ -43,6 +50,17 @@ public class TestExcelAntWorkbookUtil extends TestCase { assertNotNull( fixture ) ; } + + public void testWorkbookConstructor() throws InvalidFormatException, IOException { + File workbookFile = new File(mortgageCalculatorFileName); + FileInputStream fis = new FileInputStream(workbookFile); + Workbook workbook = WorkbookFactory.create(fis); + + fixture = new ExcelAntWorkbookUtilTestHelper( workbook ) ; + + assertNotNull( fixture ) ; + + } public void testAddFunction() { fixture = new ExcelAntWorkbookUtilTestHelper( diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java index 5de8e75ba4..cca2022a79 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java @@ -46,6 +46,11 @@ public final class TestDocumentProperties for (int x = 0; x < fields.length; x++) { + // JaCoCo Code Coverage adds it's own field, don't look at this one here + if(fields[x].getName().equals("$jacocoData")) { + continue; + } + if (!fields[x].getType().isArray()) { assertEquals(fields[x].get(_documentProperties), @@ -53,6 +58,10 @@ public final class TestDocumentProperties } else { + // ensure that the class was not changed/enhanced, e.g. by code instrumentation like coverage tools + assertEquals("Invalid type for field: " + fields[x].getName(), + "[B", fields[x].getType().getName()); + byte[] buf1 = (byte[])fields[x].get(_documentProperties); byte[] buf2 = (byte[])fields[x].get(newDocProperties); Arrays.equals(buf1, buf2); -- 2.39.5