From 71197022ebd3a7a7f192f6540a690927c0d658bb Mon Sep 17 00:00:00 2001 From: Takayuki Maruyama Date: Tue, 20 Oct 2020 22:01:09 +0900 Subject: [PATCH 1/5] Make WorkbookTest abstract --- src/test/java/org/bbreak/excella/reports/WorkbookTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/bbreak/excella/reports/WorkbookTest.java b/src/test/java/org/bbreak/excella/reports/WorkbookTest.java index 40a424c..71664ad 100644 --- a/src/test/java/org/bbreak/excella/reports/WorkbookTest.java +++ b/src/test/java/org/bbreak/excella/reports/WorkbookTest.java @@ -46,7 +46,7 @@ * @since 1.0 */ @RunWith( Parameterized.class) -public class WorkbookTest { +public abstract class WorkbookTest { /** * ログ From b0a8e80393b6b7c4e99cfaf8a6d3091a602d4dc3 Mon Sep 17 00:00:00 2001 From: Takayuki Maruyama Date: Sun, 25 Oct 2020 13:57:28 +0900 Subject: [PATCH 2/5] Make ReportsWorkbookTest abstract --- .../bbreak/excella/reports/processor/ReportsWorkbookTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java index 9fb05ea..9de2055 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java @@ -42,7 +42,7 @@ import org.bbreak.excella.reports.tag.ReportsTagParser; import org.junit.Assert; -public class ReportsWorkbookTest extends WorkbookTest { +public abstract class ReportsWorkbookTest extends WorkbookTest { /** Excelファイルのバージョン */ protected String version = null; From 47e98ebbb1e0818b6ef316dff242d2fbed120ef6 Mon Sep 17 00:00:00 2001 From: Takayuki Maruyama Date: Sun, 25 Oct 2020 13:58:14 +0900 Subject: [PATCH 3/5] Remove throws/not throws expected `fail()` usage. --- .../bbreak/excella/reports/WorkbookTest.java | 49 +--- .../reports/exporter/ExcelExporterTest.java | 28 +-- .../ExcelOutputStreamExporterTest.java | 39 +--- .../exporter/ReportBookExporterTest.java | 15 +- .../reports/exporter/XLSExporterTest.java | 31 +-- .../reports/exporter/XLSXExporterTest.java | 16 +- .../reports/listener/BreakAdapterTest.java | 22 +- .../reports/listener/RemoveAdapterTest.java | 29 +-- .../reports/others/PrintSettingCopyTest.java | 10 +- .../processor/ReportProcessorTest.java | 150 ++++++++----- .../processor/ReportsCheckException.java | 5 + .../processor/ReportsParserInfoTest.java | 37 +-- .../processor/ReportsWorkbookTest.java | 47 +--- .../tag/BlockColRepeatParamParserTest.java | 31 ++- .../tag/BlockRowRepeatParamParserTest.java | 37 +-- .../reports/tag/BreakParamParserTest.java | 15 +- .../reports/tag/ColRepeatParamParserTest.java | 66 ++---- .../reports/tag/ImageParamParserTest.java | 212 ++++++------------ .../reports/tag/RemoveParamParserTest.java | 15 +- .../reports/tag/RowRepeatParamParserTest.java | 77 ++----- .../reports/tag/SingleParamParserTest.java | 64 ++---- .../reports/tag/SumParamParserTest.java | 21 +- .../excella/reports/util/ReportsUtilTest.java | 67 +++--- 23 files changed, 400 insertions(+), 683 deletions(-) diff --git a/src/test/java/org/bbreak/excella/reports/WorkbookTest.java b/src/test/java/org/bbreak/excella/reports/WorkbookTest.java index 71664ad..63b9d0f 100644 --- a/src/test/java/org/bbreak/excella/reports/WorkbookTest.java +++ b/src/test/java/org/bbreak/excella/reports/WorkbookTest.java @@ -21,9 +21,7 @@ package org.bbreak.excella.reports; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.util.Arrays; @@ -35,7 +33,6 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.Assert; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @@ -77,7 +74,7 @@ public static Collection parameters() { return Arrays.asList( new Object[][] {{"2003"}, {"2007"}}); } - protected Workbook getWorkbook() { + protected Workbook getWorkbook() throws IOException { Workbook workbook = null; @@ -90,41 +87,15 @@ protected Workbook getWorkbook() { } URL url = this.getClass().getResource( filename); - try { - filepath = URLDecoder.decode( url.getFile(), "UTF-8"); - - if ( filepath.endsWith( ".xlsx")) { - try { - workbook = new XSSFWorkbook( filepath); - } catch ( IOException e) { - Assert.fail(); - } - } else if ( filepath.endsWith( ".xls")) { - FileInputStream stream = null; - try { - stream = new FileInputStream( filepath); - } catch ( FileNotFoundException e) { - Assert.fail(); - } - POIFSFileSystem fs = null; - try { - fs = new POIFSFileSystem( stream); - } catch ( IOException e) { - Assert.fail(); - } - try { - workbook = new HSSFWorkbook( fs); - } catch ( IOException e) { - Assert.fail(); - } - try { - stream.close(); - } catch ( IOException e) { - Assert.fail(); - } - } - } catch ( UnsupportedEncodingException e) { - Assert.fail(); + filepath = URLDecoder.decode( url.getFile(), "UTF-8"); + + if ( filepath.endsWith( ".xlsx")) { + workbook = new XSSFWorkbook( filepath); + } else if ( filepath.endsWith( ".xls")) { + FileInputStream stream = new FileInputStream( filepath); + POIFSFileSystem fs = new POIFSFileSystem( stream); + workbook = new HSSFWorkbook( fs); + stream.close(); } return workbook; } diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java index ac82de8..671149f 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java @@ -53,10 +53,13 @@ public class ExcelExporterTest { /** - * {@link org.bbreak.excella.reports.exporter.ExcelExporter#output(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData, org.bbreak.excella.reports.model.ConvertConfiguration)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.exporter.ExcelExporter#output(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData, org.bbreak.excella.reports.model.ConvertConfiguration)} + * のためのテスト・メソッド。 + * + * @throws ExportException */ @Test - public void testOutput() { + public void testOutput() throws ExportException { ExcelExporter exporter = new ExcelExporter(); String filePath = null; @@ -65,27 +68,18 @@ public void testOutput() { configuration = new ConvertConfiguration(ExcelExporter.EXTENTION_XLS); filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - try { - exporter.output( hssfWb, new BookData(), configuration); - File file = new File(exporter.getFilePath()); - assertTrue( file.exists()); - } catch ( ExportException e) { - e.printStackTrace(); - } + exporter.output( hssfWb, new BookData(), configuration); + File file = new File(exporter.getFilePath()); + assertTrue( file.exists()); //XLSX configuration = new ConvertConfiguration(ExcelExporter.EXTENTION_XLSX); filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - try { - exporter.output( xssfWb, new BookData(), configuration); - File file = new File(exporter.getFilePath()); - assertTrue( file.exists()); - - } catch ( ExportException e) { - e.printStackTrace(); - } + exporter.output( xssfWb, new BookData(), configuration); + file = new File(exporter.getFilePath()); + assertTrue( file.exists()); diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java index bd2635c..ccee756 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java @@ -25,7 +25,6 @@ import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.io.OutputStream; import java.net.URL; import java.net.URLDecoder; @@ -55,7 +54,7 @@ public class ExcelOutputStreamExporterTest { * @throws Exception */ @Test - public void testOutput() { + public void testOutput() throws Exception { FileOutputStream xlsFileOutputStream = null; // 出力先 @@ -86,17 +85,9 @@ public void testOutput() { long xlsFileByteLength = xlsExcelFile.length(); long xlsStreamFileSize = xlsStreamFile.length(); assertEquals( xlsFileByteLength, xlsStreamFileSize); - } catch ( Exception e) { - e.getStackTrace(); - fail( e.toString()); } finally { - try { - if ( xlsFileOutputStream != null) { - xlsFileOutputStream.close(); - } - } catch ( IOException e) { - e.printStackTrace(); - fail( e.toString()); + if ( xlsFileOutputStream != null) { + xlsFileOutputStream.close(); } } // XLSテスト� - フォーマット単数指定・ストリーム出力によるファイル以外が削除されていることを確認 @@ -128,17 +119,9 @@ public void testOutput() { if ( xlsExcelFile.exists()) { fail( "ExcelFile exists."); } - } catch ( Exception e) { - e.getStackTrace(); - fail( e.toString()); } finally { - try { - if ( xlsFileOutputStream != null) { - xlsFileOutputStream.close(); - } - } catch ( IOException e) { - e.printStackTrace(); - fail( e.toString()); + if ( xlsFileOutputStream != null) { + xlsFileOutputStream.close(); } } @@ -171,17 +154,9 @@ public void testOutput() { fail( "File is not opened"); } - } catch ( Exception e) { - e.getStackTrace(); - fail( e.toString()); } finally { - try { - if ( xlsFileOutputStream != null) { - xlsxFileOutputStream.close(); - } - } catch ( IOException e) { - e.printStackTrace(); - fail( e.toString()); + if ( xlsFileOutputStream != null) { + xlsxFileOutputStream.close(); } } } diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java index 6aef96e..f1efaea 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; import org.apache.poi.ss.usermodel.Workbook; import org.bbreak.excella.core.BookData; @@ -44,10 +43,13 @@ public ReportBookExporterTest( String version) { } /** - * {@link org.bbreak.excella.reports.exporter.ReportBookExporter#export(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.exporter.ReportBookExporter#export(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData)} + * のためのテスト・メソッド。 + * + * @throws ExportException */ @Test - public void testExport() { + public void testExport() throws ExportException { Workbook book = getWorkbook(); @@ -70,12 +72,7 @@ public void output( Workbook book, BookData bookdata, ConvertConfiguration confi }; exporter.setConfiguration( new ConvertConfiguration( "")); - try { - exporter.export( book, null); - } catch ( ExportException e) { - e.printStackTrace(); - fail( e.toString()); - } + exporter.export( book, null); assertEquals( 4, book.getNumberOfSheets()); diff --git a/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java index 08f0764..70860d2 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java @@ -47,9 +47,11 @@ public class XLSExporterTest { /** * {@link org.bbreak.excella.reports.exporter.XLSExporter#output(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData, org.bbreak.excella.reports.model.ConvertConfiguration)} * のためのテスト・メソッド。 + * + * @throws ExportException */ @Test - public void testOutput() { + public void testOutput() throws ExportException { XLSExporter exporter = new XLSExporter(); ConvertConfiguration configuration = new ConvertConfiguration( exporter.getFormatType()); @@ -60,17 +62,11 @@ public void testOutput() { Workbook wb = new HSSFWorkbook(); // XLS - try { - filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); - exporter.setFilePath( filePath); - exporter.output( wb, new BookData(), configuration); - File file = new File( exporter.getFilePath()); - assertTrue( file.exists()); - - } catch ( ExportException e) { - e.printStackTrace(); - fail( e.toString()); - } + filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); + exporter.setFilePath( filePath); + exporter.output( wb, new BookData(), configuration); + File file = new File( exporter.getFilePath()); + assertTrue( file.exists()); wb = new XSSFWorkbook(); // XLSX @@ -82,20 +78,15 @@ public void testOutput() { fail( "XLSXは解析不可"); } catch ( IllegalArgumentException e) { // OK - } catch ( ExportException e) { - fail( e.toString()); } // Exceptionを発生させる wb = new HSSFWorkbook(); filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - try { - exporter.output( wb, new BookData(), configuration); - } catch ( ExportException e) { - fail( e.toString()); - } - File file = new File( exporter.getFilePath()); + exporter.output( wb, new BookData(), configuration); + + file = new File( exporter.getFilePath()); file.setReadOnly(); try { exporter.output( wb, new BookData(), configuration); diff --git a/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java index 83d4abb..26234f0 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java @@ -45,9 +45,11 @@ public class XLSXExporterTest { /** * {@link org.bbreak.excella.reports.exporter.XLSXExporter#output(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData, org.bbreak.excella.reports.model.ConvertConfiguration)} * のためのテスト・メソッド。 + * + * @throws ExportException */ @Test - public void testOutput() { + public void testOutput() throws ExportException { XLSXExporter exporter = new XLSXExporter(); ConvertConfiguration configuration = new ConvertConfiguration( exporter.getFormatType()); @@ -66,9 +68,6 @@ public void testOutput() { } catch ( IllegalArgumentException e) { // OK - } catch ( ExportException e) { - e.printStackTrace(); - fail( e.toString()); } wb = new XSSFWorkbook(); @@ -82,20 +81,13 @@ public void testOutput() { } catch ( IllegalArgumentException e) { // OK - } catch ( ExportException e) { - e.printStackTrace(); - fail( e.toString()); } // Exceptionを発生させる wb = new XSSFWorkbook(); filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - try { - exporter.output( wb, new BookData(), configuration); - } catch ( ExportException e) { - fail( e.toString()); - } + exporter.output( wb, new BookData(), configuration); File file = new File( exporter.getFilePath()); file.setReadOnly(); try { diff --git a/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java b/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java index d70019e..18c51b3 100644 --- a/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java +++ b/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java @@ -20,8 +20,6 @@ package org.bbreak.excella.reports.listener; -import static org.junit.Assert.fail; - import java.io.IOException; import java.util.ArrayList; import java.util.Date; @@ -72,10 +70,14 @@ public void setUp() throws Exception { } /** - * {@link org.bbreak.excella.reports.listener.BreakAdapter#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.listener.BreakAdapter#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException */ @Test - public void testPostParse() { + public void testPostParse() throws ParseException, ReportsCheckException { Workbook workbook = getWorkbook(); @@ -89,16 +91,12 @@ public void testPostParse() { } Sheet sheet = workbook.getSheetAt( 0); - try { - adapter.postParse( sheet, sheetParser, null); - } catch ( ParseException e) { - e.printStackTrace(); - fail(); - } + adapter.postParse( sheet, sheetParser, null); checkSheet( workbook.getSheetName( 0), sheet, true); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -107,8 +105,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); try { diff --git a/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java b/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java index c8d6f2b..5a76cb5 100644 --- a/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java +++ b/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java @@ -20,8 +20,6 @@ package org.bbreak.excella.reports.listener; -import static org.junit.Assert.*; - import java.io.IOException; import java.util.ArrayList; import java.util.Date; @@ -67,10 +65,14 @@ public void setUp() throws Exception { } /** - * {@link org.bbreak.excella.reports.listener.RemoveAdapter#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.listener.RemoveAdapter#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException */ @Test - public void testPostParse() { + public void testPostParse() throws ParseException, ReportsCheckException { Workbook workbook = getWorkbook(); @@ -84,27 +86,18 @@ public void testPostParse() { } Sheet sheet = workbook.getSheetAt( 0); - try { - adapter.postParse( sheet, sheetParser, null); - } catch ( ParseException e) { - e.printStackTrace(); - fail(); - } + adapter.postParse( sheet, sheetParser, null); checkSheet( workbook.getSheetName( 0), sheet, true); workbook = getWorkbook(); sheet = workbook.getSheetAt( 1); - try { - adapter.postParse( sheet, sheetParser, null); - } catch ( ParseException e) { - e.printStackTrace(); - fail(); - } + adapter.postParse( sheet, sheetParser, null); checkSheet( workbook.getSheetName( 1), sheet, true); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -113,8 +106,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); try { diff --git a/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java b/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java index 05349e4..80e6572 100644 --- a/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java +++ b/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java @@ -20,8 +20,6 @@ package org.bbreak.excella.reports.others; -import static org.junit.Assert.fail; - import java.io.File; import java.io.FileInputStream; import java.io.UnsupportedEncodingException; @@ -205,7 +203,7 @@ private static String getTemplateFilePath( String templateFileName) throws Unsup return templateFilePath; } - private static void templateCopyTest( Workbook workbook, ReportBook reportBook) { + private static void templateCopyTest( Workbook workbook, ReportBook reportBook) throws ReportsCheckException { // 出力シート単位にコピーする for ( ReportSheet reportSheet : reportBook.getReportSheets()) { if ( reportSheet != null) { @@ -215,11 +213,7 @@ private static void templateCopyTest( Workbook workbook, ReportBook reportBook) Sheet expectedSheet = workbook.getSheetAt( tempIdx); Sheet actualSheet = workbook.cloneSheet( tempIdx); ReportsUtil.copyPrintSetup( workbook, tempIdx, actualSheet); - try { - ReportsTestUtil.checkSheet( expectedSheet, actualSheet, true); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } + ReportsTestUtil.checkSheet( expectedSheet, actualSheet, true); } } } diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java index cce9cb4..62be244 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java @@ -76,10 +76,17 @@ public ReportProcessorTest( String version) { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#ReportProcessor()} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#ReportProcessor()} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testReportProcessor() { + public void testReportProcessor() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); // デフォルトタグパーサー Map> actualParsers = ( Map>) getPrivateFiled( processor, "parsers"); @@ -108,10 +115,13 @@ public void testReportProcessor() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#process(org.bbreak.excella.reports.model.ReportData)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#process(org.bbreak.excella.reports.model.ReportData)} + * のためのテスト・メソッド。 + * + * @throws Exception */ @Test - public void testProcess() { + public void testProcess() throws Exception { getWorkbook(); @@ -148,12 +158,7 @@ public void testProcess() { book2.addReportSheet( null); - try { - reportProcessor.process( new ReportBook[] {book1, book2, null}); - } catch ( Exception e) { - e.printStackTrace(); - fail( e.toString()); - } + reportProcessor.process( new ReportBook[] {book1, book2, null}); List exceptedProccess = new ArrayList(); exceptedProccess.add( "ブック解析前処理 CustomListener#preBookParse( Workbook workbook, ReportBook reportBook)"); @@ -206,12 +211,7 @@ public void testProcess() { book2.addReportSheet( null); - try { - reportProcessor.process( book1, book2, null); - } catch ( Exception e) { - e.printStackTrace(); - fail( e.toString()); - } + reportProcessor.process( book1, book2, null); exceptedProccess = new ArrayList(); exceptedProccess.add( "ブック解析前処理 CustomListener#preBookParse( Workbook workbook, ReportBook reportBook)"); @@ -253,12 +253,9 @@ public void testProcess() { try { reportProcessor.process( book1); - fail(); + fail( "FileNotFoundException expected, but no exception was thrown."); } catch ( FileNotFoundException e) { assertTrue( true); - } catch ( Exception e) { - e.printStackTrace(); - fail( e.toString()); } assertTrue( processStrings.isEmpty()); @@ -301,12 +298,7 @@ public void testProcess() { book2.addReportSheet( sheetOriginal3); // →シート4(出力対象外) - try { - reportProcessor.process( book1, book2); - } catch ( Exception e) { - e.printStackTrace(); - fail( e.toString()); - } + reportProcessor.process( book1, book2); exceptedProccess = new ArrayList(); exceptedProccess.add( "ブック解析前処理 CustomListener#preBookParse( Workbook workbook, ReportBook reportBook)"); @@ -367,7 +359,7 @@ public void testProcess() { try { reportProcessor.process( book1); - fail(); + fail( "Exception expected, but no exception was thrown."); } catch ( Exception e) { assertTrue( true); } @@ -391,10 +383,17 @@ public void testProcess() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#addReportsTagParser(org.bbreak.excella.reports.tag.ReportsTagParser)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#addReportsTagParser(org.bbreak.excella.reports.tag.ReportsTagParser)} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testAddReportsTagParser() { + public void testAddReportsTagParser() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); ReportsTagParser addparser = new CustomTagParser( "$CUSTOM"); @@ -405,10 +404,17 @@ public void testAddReportsTagParser() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#removeReportsTagParser(java.lang.String)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#removeReportsTagParser(java.lang.String)} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testRemoveReportsTagParser() { + public void testRemoveReportsTagParser() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); @@ -419,10 +425,17 @@ public void testRemoveReportsTagParser() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#clearReportsTagParser()} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#clearReportsTagParser()} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testClearReportsTagParser() { + public void testClearReportsTagParser() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); processor.clearReportsTagParser(); Map> actualParsers = ( Map>) getPrivateFiled( processor, "parsers"); @@ -431,10 +444,17 @@ public void testClearReportsTagParser() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#addReportBookExporter(org.bbreak.excella.reports.exporter.ReportBookExporter)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#addReportBookExporter(org.bbreak.excella.reports.exporter.ReportBookExporter)} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testAddReportBookExporter() { + public void testAddReportBookExporter() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); ReportBookExporter bookExporter = new CustomExporter(); @@ -446,10 +466,17 @@ public void testAddReportBookExporter() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#removeReportBookExporter(java.lang.String)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#removeReportBookExporter(java.lang.String)} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testRemoveReportBookExporter() { + public void testRemoveReportBookExporter() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); processor.removeReportBookExporter( "EXCEL"); @@ -460,10 +487,17 @@ public void testRemoveReportBookExporter() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#clearReportBookExporter()} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#clearReportBookExporter()} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testClearReportBookExporter() { + public void testClearReportBookExporter() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); processor.clearReportBookExporter(); @@ -474,10 +508,17 @@ public void testClearReportBookExporter() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#addReportProcessListener(org.bbreak.excella.reports.listener.ReportProcessListener)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#addReportProcessListener(org.bbreak.excella.reports.listener.ReportProcessListener)} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testAddReportProcessListener() { + public void testAddReportProcessListener() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); CustomListener listener = new CustomListener(); @@ -493,10 +534,17 @@ public void testAddReportProcessListener() { } /** - * {@link org.bbreak.excella.reports.processor.ReportProcessor#removeReportProcessListener(org.bbreak.excella.reports.listener.ReportProcessListener)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportProcessor#removeReportProcessListener(org.bbreak.excella.reports.listener.ReportProcessListener)} + * のためのテスト・メソッド。 + * + * @throws IllegalAccessException + * @throws IllegalArgumentException + * @throws SecurityException + * @throws NoSuchFieldException */ @Test - public void testRemoveReportProcessListener() { + public void testRemoveReportProcessListener() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { ReportProcessor processor = new ReportProcessor(); CustomListener listener = new CustomListener(); @@ -512,18 +560,12 @@ public void testRemoveReportProcessListener() { } - private Object getPrivateFiled( Object object, String fieldName) { + private Object getPrivateFiled( Object object, String fieldName) throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { - Field field = null; - Object res = null; - try { - field = object.getClass().getDeclaredField( fieldName); - field.setAccessible( true); - res = field.get( object); - } catch ( Exception e) { - e.printStackTrace(); - fail(); - } + Field field = object.getClass().getDeclaredField( fieldName); + field.setAccessible( true); + Object res = field.get( object); return res; } diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportsCheckException.java b/src/test/java/org/bbreak/excella/reports/processor/ReportsCheckException.java index a386c85..6e8b14f 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportsCheckException.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportsCheckException.java @@ -78,4 +78,9 @@ public String getCheckMessagesToString() { } return buffer.toString(); } + + @Override + public String getMessage() { + return super.getMessage() + System.lineSeparator() + getCheckMessagesToString(); + } } diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java index 2eefd80..d5fc28f 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; import java.io.IOException; import java.util.ArrayList; @@ -144,10 +143,13 @@ public void testCreateChildParserInfo() { } /** - * {@link org.bbreak.excella.reports.processor.ReportsParserInfo#getMatchTagParser(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.processor.ReportsParserInfo#getMatchTagParser(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell)} + * のためのテスト・メソッド。 + * + * @throws ParseException */ @Test - public void testGetMatchTagParser() { + public void testGetMatchTagParser() throws ParseException { ReportsParserInfo info = new ReportsParserInfo(); ReportBook reportBook = new ReportBook("", "", new ConvertConfiguration[]{}); @@ -169,39 +171,18 @@ public void testGetMatchTagParser() { xssfCell1.setCellValue( "$TEST{XSSF}"); - TagParser parser = null; - try { - parser = info.getMatchTagParser( hssfSheet, hssfCell0); - } catch ( ParseException e) { - e.printStackTrace(); - fail(e.toString()); - } + TagParser parser = info.getMatchTagParser( hssfSheet, hssfCell0); assertEquals( SingleParamParser.class, parser.getClass()); - try { - parser = info.getMatchTagParser( hssfSheet, hssfCell1); - } catch ( ParseException e) { - e.printStackTrace(); - fail(e.toString()); - } + parser = info.getMatchTagParser( hssfSheet, hssfCell1); assertNull( parser); - try { - parser = info.getMatchTagParser( xssfSheet, xssfCell0); - } catch ( ParseException e) { - e.printStackTrace(); - fail(e.toString()); - } + parser = info.getMatchTagParser( xssfSheet, xssfCell0); assertEquals( SingleParamParser.class, parser.getClass()); - try { - parser = info.getMatchTagParser( xssfSheet, xssfCell1); - } catch ( ParseException e) { - e.printStackTrace(); - fail(e.toString()); - } + parser = info.getMatchTagParser( xssfSheet, xssfCell1); assertNull( parser); try { diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java index 9de2055..38cb193 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java @@ -21,7 +21,6 @@ package org.bbreak.excella.reports.processor; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URL; @@ -40,7 +39,6 @@ import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ParsedReportInfo; import org.bbreak.excella.reports.tag.ReportsTagParser; -import org.junit.Assert; public abstract class ReportsWorkbookTest extends WorkbookTest { @@ -52,7 +50,7 @@ public ReportsWorkbookTest( String version) { this.version = version; } - protected Workbook getExpectedWorkbook() { + protected Workbook getExpectedWorkbook() throws IOException { Workbook workbook = null; @@ -66,14 +64,9 @@ protected Workbook getExpectedWorkbook() { URL url = this.getClass().getResource( filename); - try { - String path = URLDecoder.decode( url.getFile(), "UTF-8"); + String path = URLDecoder.decode( url.getFile(), "UTF-8"); - workbook = getWorkbook(path); - - } catch ( UnsupportedEncodingException e) { - Assert.fail(); - } + workbook = getWorkbook(path); return workbook; } @@ -103,39 +96,17 @@ protected List parseSheet( ReportsTagParser parser, Sheet s } - protected Workbook getWorkbook(String filepath) { + protected Workbook getWorkbook(String filepath) throws IOException { Workbook workbook = null; if ( filepath.endsWith( ".xlsx")) { - try { - workbook = new XSSFWorkbook( filepath); - } catch ( IOException e) { - Assert.fail(); - } + workbook = new XSSFWorkbook( filepath); } else if ( filepath.endsWith( ".xls")) { - FileInputStream stream = null; - try { - stream = new FileInputStream( filepath); - } catch ( FileNotFoundException e) { - Assert.fail(); - } - POIFSFileSystem fs = null; - try { - fs = new POIFSFileSystem( stream); - } catch ( IOException e) { - Assert.fail(); - } - try { - workbook = new HSSFWorkbook( fs); - } catch ( IOException e) { - Assert.fail(); - } - try { - stream.close(); - } catch ( IOException e) { - Assert.fail(); - } + FileInputStream stream = new FileInputStream( filepath); + POIFSFileSystem fs = new POIFSFileSystem( stream); + workbook = new HSSFWorkbook( fs); + stream.close(); } return workbook; } diff --git a/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java index 9f322ec..6cb8d02 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java @@ -62,7 +62,7 @@ public BlockColRepeatParamParserTest( String version) { @Test - public void testParseSheetCellObject() throws ParseException { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException { Workbook workbook = null; ReportBook reportBook = new ReportBook( "", "test", new ConvertConfiguration[] {}); @@ -408,7 +408,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet11, reportsParserInfo); fail( "fromCellの値の個数チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet11", sheet11, true); @@ -418,7 +419,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet12, reportsParserInfo); fail( "toCellの値の個数チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet12", sheet12, true); @@ -433,7 +435,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet13, reportsParserInfo); fail( "fromCellのマイナス値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet13", sheet13, true); @@ -443,7 +446,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet14, reportsParserInfo); fail( "toCellのマイナス値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet14", sheet14, true); @@ -458,7 +462,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet15, reportsParserInfo); fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet15", sheet15, true); @@ -469,7 +474,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet17, reportsParserInfo); fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet17", sheet17, true); @@ -484,7 +490,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet16, reportsParserInfo); fail( "repeatNumの数値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet16", sheet16, true); @@ -495,7 +502,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet18, reportsParserInfo); fail( "repeatNumの数値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet18", sheet18, true); @@ -708,7 +716,8 @@ public void testBlockColRepeatParamParserString() { - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -719,8 +728,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java index eae4888..2bef434 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java @@ -59,7 +59,7 @@ public BlockRowRepeatParamParserTest( String version) { } @Test - public void testParseSheetCellObject() throws ParseException { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException { Workbook workbook = null; ReportBook reportBook = new ReportBook( "", "test", new ConvertConfiguration[] {}); @@ -381,7 +381,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet9, reportsParserInfo); fail( "fromCell必須チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet9", sheet9, true); @@ -391,7 +392,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet10, reportsParserInfo); fail( "toCell必須チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet10", sheet10, true); @@ -406,7 +408,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet11, reportsParserInfo); fail( "fromCellの値の個数チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet11", sheet11, true); @@ -416,7 +419,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet12, reportsParserInfo); fail( "toCellの値の個数チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet12", sheet12, true); @@ -432,7 +436,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet13, reportsParserInfo); fail( "fromCellのマイナス値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet13", sheet13, true); @@ -443,7 +448,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet14, reportsParserInfo); fail( "toCellのマイナス値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet14", sheet14, true); @@ -458,7 +464,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet15, reportsParserInfo); fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet15", sheet15, true); @@ -469,7 +476,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet17, reportsParserInfo); fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet17", sheet17, true); @@ -484,7 +492,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet16, reportsParserInfo); fail( "repeatNumの数値チェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet16", sheet16, true); @@ -495,7 +504,8 @@ public void testParseSheetCellObject() throws ParseException { try { results = parseSheet( parser, sheet18, reportsParserInfo); fail( "repeatNumのマイナスチェックにかかっていない"); - } catch (ParseException e) { + } catch (ParseException expected) { + // ok } checkSheet( "sheet18", sheet18, true); @@ -700,7 +710,8 @@ public void testBlockRowRepeatParamParserString() { } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -709,8 +720,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java index 2c73c73..38c9606 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.List; @@ -55,10 +54,13 @@ public BreakParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.BreakParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.BreakParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException { Workbook workbook = getWorkbook(); Sheet sheet1 = workbook.getSheetAt( 0); @@ -67,13 +69,8 @@ public void testParseSheetCellObject() { ReportsParserInfo reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setReportParsers( new ArrayList>( ReportCreateHelper.createDefaultParsers().values())); - List results = null; // 解析処理 - try { - results = parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + List results = parseSheet( parser, sheet1, reportsParserInfo); checkResult( new CellObject[] {new CellObject( 0, 0), new CellObject( 3, 2), new CellObject( 5, 3), new CellObject( 8, 1), new CellObject( 11, 4), new CellObject( 15, 2), new CellObject( 24, 3)}, diff --git a/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java index a076a4f..ff59292 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java @@ -60,10 +60,14 @@ public ColRepeatParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.ColRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.ColRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException { Workbook workbook = null; // ----------------------- // □[正常系]オプション指定なし @@ -96,12 +100,7 @@ public void testParseSheetCellObject() { reportsParserInfo.setParamInfo( reportSheets[0].getParamInfo()); // 解析処理 - List results = null; - try { - results = parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + List results = parseSheet( parser, sheet1, reportsParserInfo); CellObject[] expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 2, 1)}; CellObject[] expectAfCells = new CellObject[] {new CellObject( 0, 4), new CellObject( 2, 3)}; @@ -124,11 +123,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet2 = workbook.getSheetAt( 1); // 解析処理 - try { - results = parseSheet( parser, sheet2, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + results = parseSheet( parser, sheet2, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 2, 1), new CellObject( 4, 2)}; expectAfCells = new CellObject[] {new CellObject( 0, 4), new CellObject( 2, 3), new CellObject( 4, 3)}; @@ -150,12 +145,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet3 = workbook.getSheetAt( 2); // 解析処理 - try { - results = parseSheet( parser, sheet3, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet3, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 1, 0), new CellObject( 2, 0), new CellObject( 16, 0), new CellObject( 17, 0)}; expectAfCells = new CellObject[] {new CellObject( 0, 2), new CellObject( 1, 1), new CellObject( 2, 4), new CellObject( 16, 2), new CellObject( 17, 2)}; @@ -178,11 +168,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet4 = workbook.getSheetAt( 3); // 解析処理 - try { - results = parseSheet( parser, sheet4, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + results = parseSheet( parser, sheet4, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 1, 0), new CellObject( 2, 0)}; expectAfCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 1, 0), new CellObject( 2, 0)}; @@ -202,7 +188,8 @@ public void testParseSheetCellObject() { try { results = parseSheet( parser, sheet5, reportsParserInfo); fail( "シートハイパーリンク設定有無と重複非表示は重複不可チェックにかかっていない"); - } catch ( ParseException e) { + } catch ( ParseException expected) { + // ok } // ----------------------- @@ -214,7 +201,7 @@ public void testParseSheetCellObject() { // 解析処理 try { results = parseSheet( parser, sheet6, reportsParserInfo); - fail(); + fail( "ParseException expected, but no exception was thrown."); } catch ( ParseException e) { assertTrue( e instanceof ParseException); } @@ -245,12 +232,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet8 = workbook.getSheetAt( 7); // 解析処理 - try { - results = parseSheet( parser, sheet8, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet8, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject(1,2), new CellObject(1,12), new CellObject(1,16), new CellObject(4,2), new CellObject(5,3), new CellObject(5,14)}; expectAfCells = new CellObject[] {new CellObject(1,10), new CellObject(1,14), new CellObject(1,24), new CellObject(4,6), new CellObject(5,11), new CellObject(5,22)}; @@ -272,12 +254,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet9 = workbook.getSheetAt( 8); // 解析処理 - try { - results = parseSheet( parser, sheet9, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet9, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 1, 3), new CellObject( 1, 19), new CellObject( 1, 26), new CellObject( 4, 3), new CellObject( 4, 13)}; expectAfCells = new CellObject[] {new CellObject( 1, 15), new CellObject( 1, 22), new CellObject( 1, 38), new CellObject( 4, 9), new CellObject( 4, 19)}; @@ -319,13 +296,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet15 = workbook.getSheetAt( 14); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet15, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet15, reportsParserInfo); // 順にデータ数=最低繰返回数、データ数=最低繰返数-1,データ数=最低繰返数-1(結合セルを繰り返し),データ数=最低繰返数-1(結合セルが右にある) expectBeCells = new CellObject[] {new CellObject(1,1),new CellObject(2,2),new CellObject(3,4), new CellObject(4,4) }; @@ -366,7 +337,8 @@ public void testColRepeatParamParserString() { assertEquals( "てすと", parser.getTag()); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -375,8 +347,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java index 951ead1..d93170b 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java @@ -88,10 +88,15 @@ public ImageParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.ImageParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.ImageParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException + * @throws IOException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException, IOException { // ----------------------- // □[正常系]通常解析 // ----------------------- @@ -104,11 +109,7 @@ public void testParseSheetCellObject() { ReportsParserInfo reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet1, reportsParserInfo); // 不要シートの削除 Set delSheetIndexs = new TreeSet( Collections.reverseOrder()); @@ -128,9 +129,6 @@ public void testParseSheetCellObject() { try { // チェック ReportsTestUtil.checkSheet( expectedSheet, sheet1, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } finally { // オブジェクトはチェックできないので、出力して確認 String tmpDirPath = System.getProperty( "user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir"); @@ -139,19 +137,14 @@ public void testParseSheetCellObject() { file.mkdirs(); } - try { - String filepath = null; - if ( version.equals( "2007")) { - filepath = tmpDirPath + "ImageParamParserTest1.xlsx"; - } else { - filepath = tmpDirPath + "ImageParamParserTest1.xls"; - } - PoiUtil.writeBook( workbook, filepath); - log.info( "出力ファイルを確認してください:" + filepath); - - } catch ( IOException e) { - fail( e.toString()); + String filepath; + if ( version.equals( "2007")) { + filepath = tmpDirPath + "ImageParamParserTest1.xlsx"; + } else { + filepath = tmpDirPath + "ImageParamParserTest1.xls"; } + PoiUtil.writeBook( workbook, filepath); + log.info( "出力ファイルを確認してください:" + filepath); } // ----------------------- @@ -166,11 +159,7 @@ public void testParseSheetCellObject() { reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createTestData( "$Image")); - try { - parseSheet( parser, sheet2, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet2, reportsParserInfo); // 不要シートの削除 delSheetIndexs.clear(); @@ -190,8 +179,6 @@ public void testParseSheetCellObject() { try { // チェック ReportsTestUtil.checkSheet( expectedSheet, sheet2, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { // オブジェクトはチェックできないので、出力して確認 String tmpDirPath = System.getProperty( "user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir");; @@ -199,19 +186,14 @@ public void testParseSheetCellObject() { if ( !file.exists()) { file.mkdir(); } - try { - String filepath = null; - if ( version.equals( "2007")) { - filepath = tmpDirPath + "ImageParamParserTest2.xlsx"; - } else { - filepath = tmpDirPath + "ImageParamParserTest2.xls"; - } - PoiUtil.writeBook( workbook, filepath); - log.info( "出力ファイルを確認してください:" + filepath); - - } catch ( IOException e) { - fail( e.toString()); + String filepath; + if ( version.equals( "2007")) { + filepath = tmpDirPath + "ImageParamParserTest2.xlsx"; + } else { + filepath = tmpDirPath + "ImageParamParserTest2.xls"; } + PoiUtil.writeBook( workbook, filepath); + log.info( "出力ファイルを確認してください:" + filepath); } String filename = this.getClass().getSimpleName(); @@ -222,13 +204,7 @@ public void testParseSheetCellObject() { } URL url = this.getClass().getResource( filename); - String path = null; - try { - path = URLDecoder.decode( url.getFile(), "UTF-8"); - - } catch ( UnsupportedEncodingException e) { - Assert.fail(); - } + String path = URLDecoder.decode( url.getFile(), "UTF-8"); // ----------------------- // ■[異常系]チェック @@ -245,7 +221,8 @@ public void testParseSheetCellObject() { try { parseSheet( parser, sheet3, reportsParserInfo); fail( "チェックにかかっていない"); - } catch ( ParseException e) { + } catch ( ParseException expected) { + // ok } // ----------------------- @@ -260,22 +237,14 @@ public void testParseSheetCellObject() { reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet4, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet4, reportsParserInfo); // 期待値ブックの読み込み expectedWorkbook = getExpectedWorkbook(); expectedSheet = expectedWorkbook.getSheet( "Sheet4"); - try { - // チェック - ReportsTestUtil.checkSheet( expectedSheet, sheet4, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } + // チェック + ReportsTestUtil.checkSheet( expectedSheet, sheet4, false); // ---------------------------------------------------------------------- // □[正常系]1シート出力 / タグで複数画像 / 単一テンプレートを上書き @@ -289,11 +258,7 @@ public void testParseSheetCellObject() { reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createPluralTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet5, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet5, reportsParserInfo); // 不要シートの削除 delSheetIndexs.clear(); @@ -313,8 +278,6 @@ public void testParseSheetCellObject() { try { // チェック ReportsTestUtil.checkSheet( expectedSheet, sheet5, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { // オブジェクトはチェックできないので、出力して確認 String tmpDirPath = System.getProperty( "user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir"); @@ -323,19 +286,14 @@ public void testParseSheetCellObject() { file.mkdirs(); } - try { - String filepath = null; - if ( version.equals( "2007")) { - filepath = tmpDirPath + "ImageParamParserTest3.xlsx"; - } else { - filepath = tmpDirPath + "ImageParamParserTest3.xls"; - } - PoiUtil.writeBook( workbook, filepath); - log.info( "出力ファイルを確認してください:" + filepath); - - } catch ( IOException e) { - fail( e.toString()); + String filepath; + if ( version.equals( "2007")) { + filepath = tmpDirPath + "ImageParamParserTest3.xlsx"; + } else { + filepath = tmpDirPath + "ImageParamParserTest3.xls"; } + PoiUtil.writeBook( workbook, filepath); + log.info( "出力ファイルを確認してください:" + filepath); } // ---------------------------------------------------------------------- @@ -351,11 +309,7 @@ public void testParseSheetCellObject() { reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createPluralTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet6, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet6, reportsParserInfo); // 不要シートの削除 delSheetIndexs.clear(); @@ -375,8 +329,6 @@ public void testParseSheetCellObject() { try { // チェック ReportsTestUtil.checkSheet( expectedSheet, sheet6, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { // オブジェクトはチェックできないので、出力して確認 String tmpDirPath = System.getProperty( "user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir"); @@ -385,19 +337,14 @@ public void testParseSheetCellObject() { file.mkdirs(); } - try { - String filepath = null; - if ( version.equals( "2007")) { - filepath = tmpDirPath + "ImageParamParserTest4.xlsx"; - } else { - filepath = tmpDirPath + "ImageParamParserTest4.xls"; - } - PoiUtil.writeBook( workbook, filepath); - log.info( "出力ファイルを確認してください:" + filepath); - - } catch ( IOException e) { - fail( e.toString()); + String filepath; + if ( version.equals( "2007")) { + filepath = tmpDirPath + "ImageParamParserTest4.xlsx"; + } else { + filepath = tmpDirPath + "ImageParamParserTest4.xls"; } + PoiUtil.writeBook( workbook, filepath); + log.info( "出力ファイルを確認してください:" + filepath); } // ---------------------------------------------------------------------- @@ -415,11 +362,7 @@ public void testParseSheetCellObject() { reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createPluralTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet, reportsParserInfo); } // 不要シートの削除 @@ -446,8 +389,6 @@ public void testParseSheetCellObject() { // チェック ReportsTestUtil.checkSheet( expectedWorkbook.getSheetAt( startOfTargetSheet + i), workbook.getSheetAt( i), false); } - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { // オブジェクトはチェックできないので、出力して確認 String tmpDirPath = System.getProperty( "user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir"); @@ -456,19 +397,14 @@ public void testParseSheetCellObject() { file.mkdirs(); } - try { - String filepath = null; - if ( version.equals( "2007")) { - filepath = tmpDirPath + "ImageParamParserTest5.xlsx"; - } else { - filepath = tmpDirPath + "ImageParamParserTest5.xls"; - } - PoiUtil.writeBook( workbook, filepath); - log.info( "出力ファイルを確認してください:" + filepath); - - } catch ( IOException e) { - fail( e.toString()); + String filepath; + if ( version.equals( "2007")) { + filepath = tmpDirPath + "ImageParamParserTest5.xlsx"; + } else { + filepath = tmpDirPath + "ImageParamParserTest5.xls"; } + PoiUtil.writeBook( workbook, filepath); + log.info( "出力ファイルを確認してください:" + filepath); } @@ -493,11 +429,7 @@ public void testParseSheetCellObject() { reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setParamInfo( createPluralTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet, reportsParserInfo); } // 不要シートの削除 @@ -528,8 +460,6 @@ public void testParseSheetCellObject() { // チェック ReportsTestUtil.checkSheet( expectedWorkbook.getSheetAt( startOfTargetSheet + i), workbook.getSheetAt( i), false); } - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { // オブジェクトはチェックできないので、出力して確認 String tmpDirPath = System.getProperty( "user.dir") + "/work/test/"; // System.getProperty( "java.io.tmpdir"); @@ -538,24 +468,19 @@ public void testParseSheetCellObject() { file.mkdirs(); } - try { - String filepath = null; - if ( version.equals( "2007")) { - filepath = tmpDirPath + "ImageParamParserTest6.xlsx"; - } else { - filepath = tmpDirPath + "ImageParamParserTest6.xls"; - } - PoiUtil.writeBook( workbook, filepath); - log.info( "出力ファイルを確認してください:" + filepath); - - } catch ( IOException e) { - fail( e.toString()); + String filepath; + if ( version.equals( "2007")) { + filepath = tmpDirPath + "ImageParamParserTest6.xlsx"; + } else { + filepath = tmpDirPath + "ImageParamParserTest6.xls"; } + PoiUtil.writeBook( workbook, filepath); + log.info( "出力ファイルを確認してください:" + filepath); } } - private ParamInfo createTestData( String tag) { + private ParamInfo createTestData( String tag) throws UnsupportedEncodingException { ParamInfo info = new ParamInfo(); info.addParam( tag, "png", getImagePath( "bbreak.PNG")); @@ -565,7 +490,7 @@ private ParamInfo createTestData( String tag) { } - private ParamInfo createPluralTestData( String tag) { + private ParamInfo createPluralTestData( String tag) throws UnsupportedEncodingException { ParamInfo info = new ParamInfo(); info.addParam( tag, "png", getImagePath( "bbreak.PNG")); @@ -578,16 +503,11 @@ private ParamInfo createPluralTestData( String tag) { } - private String getImagePath( String fileName) { + private String getImagePath( String fileName) throws UnsupportedEncodingException { String path = null; - try { - URL url = this.getClass().getResource( fileName); - path = URLDecoder.decode( url.getFile(), "UTF-8"); - - } catch ( Exception e) { - fail( e.toString()); - } + URL url = this.getClass().getResource( fileName); + path = URLDecoder.decode( url.getFile(), "UTF-8"); return path; diff --git a/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java index b345b49..be276b5 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.List; @@ -55,10 +54,13 @@ public RemoveParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.RemoveParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.RemoveParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException { Workbook workbook = getWorkbook(); Sheet sheet1 = workbook.getSheetAt( 0); @@ -67,13 +69,8 @@ public void testParseSheetCellObject() { ReportsParserInfo reportsParserInfo = new ReportsParserInfo(); reportsParserInfo.setReportParsers( new ArrayList>( ReportCreateHelper.createDefaultParsers().values())); - List results = null; // 解析処理 - try { - results = parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + List results = parseSheet( parser, sheet1, reportsParserInfo); checkResult( new CellObject[] {new CellObject( 0, 0), new CellObject( 3, 2), new CellObject( 5, 3), new CellObject( 8, 1), new CellObject( 11, 4), new CellObject( 15, 2), new CellObject( 24, 3)}, results); diff --git a/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java index 4de6bcd..b30a2a3 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java @@ -60,10 +60,14 @@ public RowRepeatParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.RowRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.RowRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException { Workbook workbook = getWorkbook(); Sheet sheet1 = workbook.getSheetAt( 0); @@ -98,12 +102,7 @@ public void testParseSheetCellObject() { reportsParserInfo.setParamInfo( reportSheets[0].getParamInfo()); // 解析処理. - List results = null; - try { - results = parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + List results = parseSheet( parser, sheet1, reportsParserInfo); CellObject[] expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 2, 1)}; CellObject[] expectAfCells = new CellObject[] {new CellObject( 4, 0), new CellObject( 4, 1)}; @@ -130,12 +129,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet2 = workbook.getSheetAt( 1); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet2, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + results = parseSheet( parser, sheet2, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 2, 1), new CellObject( 4, 2)}; expectAfCells = new CellObject[] {new CellObject( 4, 0), new CellObject( 4, 1), new CellObject( 5, 2)}; @@ -157,12 +151,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet3 = workbook.getSheetAt( 2); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet3, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + results = parseSheet( parser, sheet3, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 0, 1), new CellObject( 0, 2), new CellObject( 17, 1), new CellObject( 18, 0)}; expectAfCells = new CellObject[] {new CellObject( 2, 0), new CellObject( 1, 1), new CellObject( 4, 2), new CellObject( 19, 1), new CellObject( 20, 0)}; @@ -185,11 +174,7 @@ public void testParseSheetCellObject() { Sheet sheet4 = workbook.getSheetAt( 3); // 解析処理 results = null; - try { - results = parseSheet( parser, sheet4, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + results = parseSheet( parser, sheet4, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 1, 0), new CellObject( 2, 0)}; expectAfCells = new CellObject[] {new CellObject( 0, 0), new CellObject( 1, 0), new CellObject( 2, 0)}; @@ -209,7 +194,8 @@ public void testParseSheetCellObject() { try { parseSheet( parser, sheet5, reportsParserInfo); fail( "シートハイパーリンク設定有無と重複非表示は重複不可チェックにかかっていない"); - } catch ( ParseException e) { + } catch ( ParseException expected) { + // ok } // ----------------------- @@ -221,7 +207,7 @@ public void testParseSheetCellObject() { // 解析処理 try { parseSheet( parser, sheet6, reportsParserInfo); - fail(); + fail( "ParseException expected, but no exception was thrown."); } catch ( ParseException e) { assertTrue( e instanceof ParseException); } @@ -252,13 +238,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet8 = workbook.getSheetAt( 7); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet8, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet8, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject(2,0), new CellObject(2,1), new CellObject(2,2), new CellObject(2,3), new CellObject(2,4), new CellObject(14,0)}; expectAfCells = new CellObject[] {new CellObject(10,0), new CellObject(10,1), new CellObject(10,2), new CellObject(4,3), new CellObject(6,4), new CellObject(22,0)}; @@ -280,13 +260,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet9 = workbook.getSheetAt( 8); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet9, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet9, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject(3,0),new CellObject(3,1),new CellObject(3,2),new CellObject(3,3),new CellObject(3,4)}; expectAfCells = new CellObject[] {new CellObject(15,0),new CellObject(15,1),new CellObject(15,2),new CellObject(6,3),new CellObject(9,4)}; @@ -329,13 +303,7 @@ public void testParseSheetCellObject() { // ------------------------------------------------------------ workbook = getWorkbook(); Sheet sheet17 = workbook.getSheetAt( 16); - results = null; - try { - results = parseSheet( parser, sheet17, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet17, reportsParserInfo); checkSheet( "Sheet17", sheet17, true); // ------------------------------------------------------------ @@ -345,13 +313,7 @@ public void testParseSheetCellObject() { workbook = getWorkbook(); Sheet sheet18 = workbook.getSheetAt( 17); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet18, reportsParserInfo); - } catch ( ParseException e) { - e.printStackTrace(); - fail( e.toString()); - } + results = parseSheet( parser, sheet18, reportsParserInfo); // 順にデータ数=最低繰返回数、データ数=最低繰返数-1,データ数=最低繰返数-1(結合セルが下にある),データ数=最低繰返数-1(結合セルを繰り返し) expectBeCells = new CellObject[] {new CellObject(1,1),new CellObject(2,2),new CellObject(2,4), new CellObject(4,3)}; @@ -392,7 +354,8 @@ public void testRowRepeatParamParserString() { assertEquals( "てすと", parser.getTag()); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -401,8 +364,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java index 6103798..dbe591f 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java @@ -21,7 +21,6 @@ package org.bbreak.excella.reports.tag; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; import java.math.BigDecimal; import java.math.BigInteger; @@ -54,10 +53,14 @@ public SingleParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.SingleParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.SingleParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException { // ----------------------- // □[正常系]通常解析 @@ -114,22 +117,14 @@ public void testParseSheetCellObject() { reportsParserInfo.setParamInfo( info); // 解析処理 - try { - parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet1, reportsParserInfo); // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); Sheet expectedSheet = expectedWorkbook.getSheet( "Sheet1"); - try { - // チェック - ReportsTestUtil.checkSheet( expectedSheet, sheet1, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } + // チェック + ReportsTestUtil.checkSheet( expectedSheet, sheet1, false); // ----------------------- // □[正常系]タグ名の変更 @@ -168,22 +163,14 @@ public void testParseSheetCellObject() { Sheet sheet2 = workbook.getSheetAt( 1); // 解析処理 - try { - parseSheet( parser, sheet2, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + parseSheet( parser, sheet2, reportsParserInfo); // 期待値ブックの読み込み expectedWorkbook = getExpectedWorkbook(); expectedSheet = expectedWorkbook.getSheet( "Sheet2"); - try { - // チェック - ReportsTestUtil.checkSheet( expectedSheet, sheet2, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } + // チェック + ReportsTestUtil.checkSheet( expectedSheet, sheet2, false); // セッターによるタグ名セット parser = new SingleParamParser(); @@ -192,23 +179,15 @@ public void testParseSheetCellObject() { sheet2 = workbook.getSheetAt( 1); // 解析処理 - try { - parseSheet( parser, sheet2/** sheet1 */ + parseSheet( parser, sheet2/** sheet1 */ , reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } // 期待値ブックの読み込み expectedWorkbook = getExpectedWorkbook(); expectedSheet = expectedWorkbook.getSheet( "Sheet2"); - try { - // チェック - ReportsTestUtil.checkSheet( expectedSheet, sheet2, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } + // チェック + ReportsTestUtil.checkSheet( expectedSheet, sheet2, false); // ----------------------- // □[正常系]必須パラメータがない場合 @@ -218,21 +197,14 @@ public void testParseSheetCellObject() { Sheet sheet3 = workbook.getSheetAt( 2); // 解析処理 - try { - parseSheet( parser, sheet3, reportsParserInfo); - } catch ( ParseException e) { + parseSheet( parser, sheet3, reportsParserInfo); - } // 期待値ブックの読み込み expectedWorkbook = getExpectedWorkbook(); expectedSheet = expectedWorkbook.getSheet( "Sheet3"); - try { - // チェック - ReportsTestUtil.checkSheet( expectedSheet, sheet3, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); - } + // チェック + ReportsTestUtil.checkSheet( expectedSheet, sheet3, false); } /** diff --git a/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java index 3b38668..d8eb7f0 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java @@ -23,7 +23,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigDecimal; @@ -61,10 +60,14 @@ public SumParamParserTest( String version) { } /** - * {@link org.bbreak.excella.reports.tag.SumParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.tag.SumParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} + * のためのテスト・メソッド。 + * + * @throws ParseException + * @throws ReportsCheckException */ @Test - public void testParseSheetCellObject() { + public void testParseSheetCellObject() throws ParseException, ReportsCheckException { // ----------------------- // □[正常系]通常解析 @@ -107,12 +110,7 @@ public void testParseSheetCellObject() { reportsParserInfo.setParamInfo( reportSheet.getParamInfo()); // 解析処理 - List results = null; - try { - results = parseSheet( parser, sheet1, reportsParserInfo); - } catch ( ParseException e) { - fail( e.toString()); - } + List results = parseSheet( parser, sheet1, reportsParserInfo); // 処理結果のチェック checkResult( new CellObject[] {new CellObject( 4, 1), new CellObject( 7, 1)}, results); @@ -148,7 +146,8 @@ public void testSumParamParserString() { assertEquals( "テスト", paser.getTag()); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) + throws ReportsCheckException { // 期待値ブックの読み込み Workbook expectedWorkbook = getExpectedWorkbook(); @@ -157,8 +156,6 @@ private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean ou try { // チェック ReportsTestUtil.checkSheet( expectedSheet, actualSheet, false); - } catch ( ReportsCheckException e) { - fail( e.getCheckMessagesToString()); } finally { if ( outputExcel) { String tmpDirPath = ReportsTestUtil.getTestOutputDir(); diff --git a/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java b/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java index d9a3bb1..b9b0c78 100644 --- a/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java +++ b/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java @@ -448,41 +448,38 @@ public void testgetMergedAddress() { } /** - * {@link org.bbreak.excella.reports.util.ReportsTagUtil#getCellIndex(java.lang.String, java.lang.String)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.util.ReportsTagUtil#getCellIndex(java.lang.String, java.lang.String)} + * のためのテスト・メソッド。 + * + * @throws ParseException */ @Test - public void testGetCellIndex() { - int[] pos = null; - try { - pos = ReportsUtil.getCellIndex( "3:5", ""); - assertEquals( 3, pos[0]); - assertEquals( 5, pos[1]); - - try { - pos = ReportsUtil.getCellIndex( "A:C", ""); - fail(); - } catch ( ParseException e) { - assertTrue( true); - } + public void testGetCellIndex() throws ParseException { + int[] pos = ReportsUtil.getCellIndex( "3:5", ""); + assertEquals( 3, pos[0]); + assertEquals( 5, pos[1]); - try { - pos = ReportsUtil.getCellIndex( "TEST", ""); - fail(); - } catch ( ParseException e) { - assertTrue( true); - } + try { + pos = ReportsUtil.getCellIndex( "A:C", ""); + fail( "ParseExcepion excepted, but no exception was thrown."); + } catch ( ParseException e) { + assertTrue( true); + } - try { - pos = ReportsUtil.getCellIndex( "100", ""); - fail(); - } catch ( ParseException e) { - assertTrue( true); - } + try { + pos = ReportsUtil.getCellIndex( "TEST", ""); + fail( "ParseExcepion excepted, but no exception was thrown."); + } catch ( ParseException e) { + assertTrue( true); + } + try { + pos = ReportsUtil.getCellIndex( "100", ""); + fail( "ParseExcepion excepted, but no exception was thrown."); } catch ( ParseException e) { - e.printStackTrace(); - fail(); + assertTrue( true); } + } /** @@ -499,12 +496,7 @@ public void testGetBlockCellValue() { for ( int r = 0; r <= 4; r++) { for ( int c = 0; c <= 3; c++) { if ( cellValues[r][c] != null) { - try { - assertEquals( PoiUtil.getCellValue( sheet.getRow( r).getCell( c)), cellValues[r][c]); - } catch ( NullPointerException e) { - e.printStackTrace(); - fail(); - } + assertEquals( PoiUtil.getCellValue( sheet.getRow( r).getCell( c)), cellValues[r][c]); } else { assertTrue( sheet.getRow( r) == null || sheet.getRow( r).getCell( c) == null || sheet.getRow( r).getCell( c).getCellType() == CellType.BLANK); } @@ -526,12 +518,7 @@ public void testGetBlockCellStyle() { for ( int r = 0; r <= 4; r++) { for ( int c = 0; c <= 3; c++) { if ( cellStyles[r][c] != null) { - try { - assertTrue( sheet.getRow( r).getCell( c).getCellStyle().equals( cellStyles[r][c])); - } catch ( NullPointerException e) { - e.printStackTrace(); - fail(); - } + assertTrue( sheet.getRow( r).getCell( c).getCellStyle().equals( cellStyles[r][c])); } else { assertTrue( sheet.getRow( r) == null || sheet.getRow( r).getCell( c) == null || sheet.getRow( r).getCell( c).getCellStyle() == null); } From 16c8f29b8385b9a20baf3cc7d1f6ff644b742bbf Mon Sep 17 00:00:00 2001 From: Takayuki Maruyama Date: Wed, 21 Oct 2020 09:01:28 +0900 Subject: [PATCH 4/5] Remove primitive wrapper class's constructor usage in test class --- .../reports/tag/SingleParamParserTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java index dbe591f..6bfda5d 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java @@ -79,27 +79,27 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // byte info.addParam( SingleParamParser.DEFAULT_TAG, "test01", ( byte) 1); // Byte - info.addParam( SingleParamParser.DEFAULT_TAG, "test02", new Byte( "1")); + info.addParam( SingleParamParser.DEFAULT_TAG, "test02", Byte.valueOf( "1")); // short info.addParam( SingleParamParser.DEFAULT_TAG, "test03", ( short) 2); // Short - info.addParam( SingleParamParser.DEFAULT_TAG, "test04", new Short( "2")); + info.addParam( SingleParamParser.DEFAULT_TAG, "test04", Short.valueOf( "2")); // int info.addParam( SingleParamParser.DEFAULT_TAG, "test05", 3); // Integer - info.addParam( SingleParamParser.DEFAULT_TAG, "test06", new Integer( "3")); + info.addParam( SingleParamParser.DEFAULT_TAG, "test06", Integer.valueOf( "3")); // long info.addParam( SingleParamParser.DEFAULT_TAG, "test07", 4L); // Long - info.addParam( SingleParamParser.DEFAULT_TAG, "test08", new Long( "4")); + info.addParam( SingleParamParser.DEFAULT_TAG, "test08", Long.valueOf( "4")); // float info.addParam( SingleParamParser.DEFAULT_TAG, "test09", 5.1f); // Float - info.addParam( SingleParamParser.DEFAULT_TAG, "test10", new Float( "5.1")); + info.addParam( SingleParamParser.DEFAULT_TAG, "test10", Float.valueOf( "5.1")); // double info.addParam( SingleParamParser.DEFAULT_TAG, "test11", 6.1); // Double - info.addParam( SingleParamParser.DEFAULT_TAG, "test12", new Double( 6.1)); + info.addParam( SingleParamParser.DEFAULT_TAG, "test12", Double.valueOf( 6.1)); // BigInteger info.addParam( SingleParamParser.DEFAULT_TAG, "test13", new BigInteger( "7")); // BigDecimal @@ -137,17 +137,17 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept infoP.addParam( "$P", "test", "test!"); infoP.addParam( "$P", "テスト", "テストです!"); infoP.addParam( "$P", "test01", ( byte) 1); - infoP.addParam( "$P", "test02", new Byte( "1")); + infoP.addParam( "$P", "test02", Byte.valueOf( "1")); infoP.addParam( "$P", "test03", ( short) 2); - infoP.addParam( "$P", "test04", new Short( "2")); + infoP.addParam( "$P", "test04", Short.valueOf( "2")); infoP.addParam( "$P", "test05", 3); - infoP.addParam( "$P", "test06", new Integer( "3")); + infoP.addParam( "$P", "test06", Integer.valueOf( "3")); infoP.addParam( "$P", "test07", 4L); - infoP.addParam( "$P", "test08", new Long( "4")); + infoP.addParam( "$P", "test08", Long.valueOf( "4")); infoP.addParam( "$P", "test09", 5.1f); - infoP.addParam( "$P", "test10", new Float( "5.1")); + infoP.addParam( "$P", "test10", Float.valueOf( "5.1")); infoP.addParam( "$P", "test11", 6.1); - infoP.addParam( "$P", "test12", new Double( 6.1)); + infoP.addParam( "$P", "test12", Double.valueOf( 6.1)); infoP.addParam( "$P", "test13", new BigInteger( "7")); infoP.addParam( "$P", "test14", new BigDecimal( "8.5")); cal.clear(); From 696b38607e56ae80e94f3867355232b91a6c4573 Mon Sep 17 00:00:00 2001 From: Takayuki Maruyama Date: Thu, 22 Oct 2020 09:00:54 +0900 Subject: [PATCH 5/5] Migrate from JUnit 4 to JUnit 5 --- pom.xml | 15 +- .../bbreak/excella/reports/AllTestSuite.java | 51 ---- .../bbreak/excella/reports/WorkbookTest.java | 36 +-- .../reports/exporter/ExcelExporterTest.java | 6 +- .../ExcelOutputStreamExporterTest.java | 6 +- .../reports/exporter/ExporterTestSuite.java | 42 --- .../exporter/ReportBookExporterTest.java | 22 +- .../reports/exporter/XLSExporterTest.java | 43 ++- .../reports/exporter/XLSXExporterTest.java | 58 ++-- .../reports/listener/BreakAdapterTest.java | 45 +--- .../reports/listener/ListenerTestSuite.java | 39 --- .../reports/listener/RemoveAdapterTest.java | 44 +--- .../model/ConvertConfigurationTest.java | 19 +- .../excella/reports/model/ModelTestSuite.java | 42 --- .../excella/reports/model/ParamInfoTest.java | 10 +- .../reports/model/ParsedReportInfoTest.java | 20 +- .../excella/reports/model/ReportBookTest.java | 22 +- .../reports/model/ReportSheetTest.java | 21 +- .../reports/others/ImageDisplayTest.java | 18 +- .../reports/others/OthersTestSuite.java | 39 --- .../reports/others/PrintSettingCopyTest.java | 18 +- .../reports/processor/ProcessorTestSuite.java | 40 --- .../processor/ReportCreateHelperTest.java | 8 +- .../processor/ReportProcessorTest.java | 51 ++-- .../processor/ReportsParserInfoTest.java | 24 +- .../processor/ReportsWorkbookTest.java | 15 +- .../tag/BlockColRepeatParamParserTest.java | 248 +++++++----------- .../tag/BlockRowRepeatParamParserTest.java | 242 +++++++---------- .../reports/tag/BreakParamParserTest.java | 29 +- .../reports/tag/ColRepeatParamParserTest.java | 109 ++++---- .../reports/tag/ImageParamParserTest.java | 67 ++--- .../reports/tag/RemoveParamParserTest.java | 29 +- .../reports/tag/RowRepeatParamParserTest.java | 112 ++++---- .../reports/tag/SingleParamParserTest.java | 35 ++- .../reports/tag/SumParamParserTest.java | 31 +-- .../excella/reports/tag/TagTestSuite.java | 46 ---- .../excella/reports/util/ReportsUtilTest.java | 101 +++---- .../excella/reports/util/UtilTestSuite.java | 38 --- 38 files changed, 556 insertions(+), 1285 deletions(-) delete mode 100644 src/test/java/org/bbreak/excella/reports/AllTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/exporter/ExporterTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/listener/ListenerTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/model/ModelTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/others/OthersTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/processor/ProcessorTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/tag/TagTestSuite.java delete mode 100644 src/test/java/org/bbreak/excella/reports/util/UtilTestSuite.java diff --git a/pom.xml b/pom.xml index 4c76bd4..c9c966b 100644 --- a/pom.xml +++ b/pom.xml @@ -40,12 +40,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.17 - - - **/AllTestSuite.java - - + 3.0.0-M5 org.apache.maven.plugins @@ -109,7 +104,7 @@ org.apache.maven.plugins maven-surefire-report-plugin - 2.17 + 3.0.0-M5 @@ -120,9 +115,9 @@ 2.0 - junit - junit - 4.13.1 + org.junit.jupiter + junit-jupiter + 5.7.0 test diff --git a/src/test/java/org/bbreak/excella/reports/AllTestSuite.java b/src/test/java/org/bbreak/excella/reports/AllTestSuite.java deleted file mode 100644 index 13b1783..0000000 --- a/src/test/java/org/bbreak/excella/reports/AllTestSuite.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports; - -import org.bbreak.excella.reports.exporter.ExporterTestSuite; -import org.bbreak.excella.reports.listener.ListenerTestSuite; -import org.bbreak.excella.reports.model.ModelTestSuite; -import org.bbreak.excella.reports.others.OthersTestSuite; -import org.bbreak.excella.reports.processor.ProcessorTestSuite; -import org.bbreak.excella.reports.tag.TagTestSuite; -import org.bbreak.excella.reports.util.UtilTestSuite; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * 全テスト実行用テストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - TagTestSuite.class, - UtilTestSuite.class, - ExporterTestSuite.class, - ProcessorTestSuite.class, - ModelTestSuite.class, - ListenerTestSuite.class, - OthersTestSuite.class -}) -public class AllTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/WorkbookTest.java b/src/test/java/org/bbreak/excella/reports/WorkbookTest.java index 63b9d0f..f54866c 100644 --- a/src/test/java/org/bbreak/excella/reports/WorkbookTest.java +++ b/src/test/java/org/bbreak/excella/reports/WorkbookTest.java @@ -24,57 +24,25 @@ import java.io.IOException; import java.net.URL; import java.net.URLDecoder; -import java.util.Arrays; -import java.util.Collection; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; /** * Workbookテストクラス * * @since 1.0 */ -@RunWith( Parameterized.class) public abstract class WorkbookTest { - /** - * ログ - */ - private static Log log = LogFactory.getLog( WorkbookTest.class); - - /** Excelファイルのバージョン */ - private String version = null; - /** ファイルパス */ private String filepath = null; - /** - * コンストラクタ - * - * @param version Excelファイルのバージョン - */ - public WorkbookTest( String version) { - - this.version = version; - if ( log.isDebugEnabled()) { - log.debug( "Start " + version + "."); - } - } - - @Parameters - public static Collection parameters() { - return Arrays.asList( new Object[][] {{"2003"}, {"2007"}}); - } + protected static final String VERSIONS = "2003, 2007"; - protected Workbook getWorkbook() throws IOException { + protected Workbook getWorkbook( String version) throws IOException { Workbook workbook = null; diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java index 671149f..e2be7f7 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/ExcelExporterTest.java @@ -20,8 +20,8 @@ package org.bbreak.excella.reports.exporter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.util.Date; @@ -33,7 +33,7 @@ import org.bbreak.excella.core.exception.ExportException; import org.bbreak.excella.reports.ReportsTestUtil; import org.bbreak.excella.reports.model.ConvertConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.exporter.ExcelExporter} のためのテスト・クラス。 diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java index ccee756..f9fd636 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/ExcelOutputStreamExporterTest.java @@ -20,8 +20,8 @@ package org.bbreak.excella.reports.exporter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.FileOutputStream; @@ -34,7 +34,7 @@ import org.bbreak.excella.reports.model.ReportBook; import org.bbreak.excella.reports.model.ReportSheet; import org.bbreak.excella.reports.processor.ReportProcessor; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.exporter.ExcelOutputStreamExporter}のためのテスト・クラス。 diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ExporterTestSuite.java b/src/test/java/org/bbreak/excella/reports/exporter/ExporterTestSuite.java deleted file mode 100644 index 82c1322..0000000 --- a/src/test/java/org/bbreak/excella/reports/exporter/ExporterTestSuite.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.exporter; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * Exporterのテストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - ExcelExporterTest.class, - ReportBookExporterTest.class, - XLSExporterTest.class, - XLSXExporterTest.class, - ExcelOutputStreamExporterTest.class, -}) -public class ExporterTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java index f1efaea..d9fb563 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/ReportBookExporterTest.java @@ -20,8 +20,10 @@ package org.bbreak.excella.reports.exporter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.io.IOException; import org.apache.poi.ss.usermodel.Workbook; import org.bbreak.excella.core.BookData; @@ -29,7 +31,9 @@ import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ConvertConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.exporter.ReportBookExporter} のためのテスト・クラス。 @@ -38,20 +42,18 @@ */ public class ReportBookExporterTest extends WorkbookTest { - public ReportBookExporterTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.exporter.ReportBookExporter#export(org.apache.poi.ss.usermodel.Workbook, org.bbreak.excella.core.BookData)} * のためのテスト・メソッド。 * * @throws ExportException + * @throws IOException */ - @Test - public void testExport() throws ExportException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testExport( String version) throws ExportException, IOException { - Workbook book = getWorkbook(); + Workbook book = getWorkbook( version); ReportBookExporter exporter = new ReportBookExporter() { diff --git a/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java index 70860d2..a79d754 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/XLSExporterTest.java @@ -20,9 +20,10 @@ package org.bbreak.excella.reports.exporter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.IOException; @@ -35,7 +36,7 @@ import org.bbreak.excella.core.exception.ExportException; import org.bbreak.excella.reports.ReportsTestUtil; import org.bbreak.excella.reports.model.ConvertConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.exporter.XLSExporter} のためのテスト・クラス。 @@ -60,43 +61,31 @@ public void testOutput() throws ExportException { String filePath = null; - Workbook wb = new HSSFWorkbook(); + Workbook xlsWorkbook= new HSSFWorkbook(); // XLS filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - exporter.output( wb, new BookData(), configuration); + exporter.output( xlsWorkbook, new BookData(), configuration); File file = new File( exporter.getFilePath()); assertTrue( file.exists()); - wb = new XSSFWorkbook(); + Workbook xlsxWorkbook = new XSSFWorkbook(); // XLSX - try { - filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); - exporter.setFilePath( filePath); - exporter.output( wb, null, null); - - fail( "XLSXは解析不可"); - } catch ( IllegalArgumentException e) { - // OK - } + filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); + exporter.setFilePath( filePath); + assertThrows( IllegalArgumentException.class, () -> exporter.output( xlsxWorkbook, null, null)); // Exceptionを発生させる - wb = new HSSFWorkbook(); + Workbook xlsWorkbook2 = new HSSFWorkbook(); filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - exporter.output( wb, new BookData(), configuration); + exporter.output( xlsWorkbook2, new BookData(), configuration); file = new File( exporter.getFilePath()); file.setReadOnly(); - try { - exporter.output( wb, new BookData(), configuration); - fail( "例外未発生"); - } catch ( Exception e) { - if ( e.getCause() instanceof IOException) { - // OK - } else { - fail( e.toString()); - } + ExportException ee = assertThrows( ExportException.class, () -> exporter.output( xlsWorkbook2, new BookData(), configuration)); + if ( !(ee.getCause() instanceof IOException)) { + fail(ee); } } diff --git a/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java b/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java index 26234f0..a4bc18a 100644 --- a/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java +++ b/src/test/java/org/bbreak/excella/reports/exporter/XLSXExporterTest.java @@ -20,7 +20,11 @@ package org.bbreak.excella.reports.exporter; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.IOException; @@ -33,7 +37,7 @@ import org.bbreak.excella.core.exception.ExportException; import org.bbreak.excella.reports.ReportsTestUtil; import org.bbreak.excella.reports.model.ConvertConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.exporter.XLSXExporter} のためのテスト・クラス。 @@ -58,49 +62,31 @@ public void testOutput() throws ExportException { String filePath = null; - Workbook wb = new HSSFWorkbook(); + Workbook xlsWorkbook = new HSSFWorkbook(); // XLS - try { - filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); - exporter.setFilePath( filePath); - exporter.output( wb, new BookData(), configuration); - fail( "XLSは解析不可"); - - } catch ( IllegalArgumentException e) { - // OK - } + filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); + exporter.setFilePath( filePath); + assertThrows( IllegalArgumentException.class, () -> exporter.output( xlsWorkbook, new BookData(), configuration)); - wb = new XSSFWorkbook(); + Workbook xlsxWorkbook = new XSSFWorkbook(); // XLSX - try { - filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); - exporter.setFilePath( filePath); - exporter.output( wb, new BookData(), configuration); - File file = new File( exporter.getFilePath()); - assertTrue( file.exists()); - - } catch ( IllegalArgumentException e) { - // OK - } + filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); + exporter.setFilePath( filePath); + assertDoesNotThrow( () -> exporter.output( xlsxWorkbook, new BookData(), configuration)); + File file = new File( exporter.getFilePath()); + assertTrue( file.exists()); // Exceptionを発生させる - wb = new XSSFWorkbook(); + Workbook xlsxWorkbook2 = new XSSFWorkbook(); filePath = tmpDirPath + (new Date()).getTime() + exporter.getExtention(); exporter.setFilePath( filePath); - exporter.output( wb, new BookData(), configuration); - File file = new File( exporter.getFilePath()); + exporter.output( xlsxWorkbook2, new BookData(), configuration); + file = new File( exporter.getFilePath()); file.setReadOnly(); - try { - exporter.output( wb, new BookData(), configuration); - fail( "例外未発生"); - } catch ( Exception e) { - if ( e.getCause() instanceof IOException) { - // OK - } else { - fail( e.toString()); - } + ExportException ee = assertThrows( ExportException.class, () -> exporter.output( xlsxWorkbook2, new BookData(), configuration)); + if ( !(ee.getCause() instanceof IOException)) { + fail(ee); } - } /** diff --git a/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java b/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java index 18c51b3..67e6763 100644 --- a/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java +++ b/src/test/java/org/bbreak/excella/reports/listener/BreakAdapterTest.java @@ -31,13 +31,13 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.processor.ReportCreateHelper; import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; import org.bbreak.excella.reports.tag.ReportsTagParser; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.listener.BreakAdapter} のためのテスト・クラス。 @@ -46,40 +46,19 @@ */ public class BreakAdapterTest extends ReportsWorkbookTest { - /** - * コンストラクタ - * - * @param version - */ - public BreakAdapterTest( String version) { - super( version); - } - - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * {@link org.bbreak.excella.reports.listener.BreakAdapter#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)} * のためのテスト・メソッド。 * * @throws ParseException * @throws ReportsCheckException + * @throws IOException */ - @Test - public void testPostParse() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testPostParse( String version) throws ParseException, ReportsCheckException, IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); BreakAdapter adapter = new BreakAdapter(); @@ -92,14 +71,14 @@ public void testPostParse() throws ParseException, ReportsCheckException { Sheet sheet = workbook.getSheetAt( 0); adapter.postParse( sheet, sheetParser, null); - checkSheet( workbook.getSheetName( 0), sheet, true); + checkSheet( workbook.getSheetName( 0), sheet, true, version); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); try { diff --git a/src/test/java/org/bbreak/excella/reports/listener/ListenerTestSuite.java b/src/test/java/org/bbreak/excella/reports/listener/ListenerTestSuite.java deleted file mode 100644 index 82066f5..0000000 --- a/src/test/java/org/bbreak/excella/reports/listener/ListenerTestSuite.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.listener; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * Listenerのテストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - RemoveAdapterTest.class, - BreakAdapterTest.class -}) -public class ListenerTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java b/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java index 5a76cb5..954051c 100644 --- a/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java +++ b/src/test/java/org/bbreak/excella/reports/listener/RemoveAdapterTest.java @@ -31,13 +31,13 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.processor.ReportCreateHelper; import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; import org.bbreak.excella.reports.tag.ReportsTagParser; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.listener.RemoveAdapter} のためのテスト・クラス。 @@ -46,35 +46,19 @@ */ public class RemoveAdapterTest extends ReportsWorkbookTest { - public RemoveAdapterTest( String version) { - super( version); - } - - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * {@link org.bbreak.excella.reports.listener.RemoveAdapter#postParse(org.apache.poi.ss.usermodel.Sheet, org.bbreak.excella.core.SheetParser, org.bbreak.excella.core.SheetData)} * のためのテスト・メソッド。 * * @throws ParseException * @throws ReportsCheckException + * @throws IOException */ - @Test - public void testPostParse() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testPostParse( String version) throws ParseException, ReportsCheckException, IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); RemoveAdapter adapter = new RemoveAdapter(); @@ -87,20 +71,20 @@ public void testPostParse() throws ParseException, ReportsCheckException { Sheet sheet = workbook.getSheetAt( 0); adapter.postParse( sheet, sheetParser, null); - checkSheet( workbook.getSheetName( 0), sheet, true); + checkSheet( workbook.getSheetName( 0), sheet, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); sheet = workbook.getSheetAt( 1); adapter.postParse( sheet, sheetParser, null); - checkSheet( workbook.getSheetName( 1), sheet, true); + checkSheet( workbook.getSheetName( 1), sheet, true, version); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); try { diff --git a/src/test/java/org/bbreak/excella/reports/model/ConvertConfigurationTest.java b/src/test/java/org/bbreak/excella/reports/model/ConvertConfigurationTest.java index 9aea9ed..a515888 100644 --- a/src/test/java/org/bbreak/excella/reports/model/ConvertConfigurationTest.java +++ b/src/test/java/org/bbreak/excella/reports/model/ConvertConfigurationTest.java @@ -20,14 +20,16 @@ package org.bbreak.excella.reports.model; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.model.ConvertConfiguration} のためのテスト・クラス。 @@ -41,14 +43,7 @@ public class ConvertConfigurationTest { /** * @throws java.lang.Exception */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before + @BeforeEach public void setUp() throws Exception { configuration = new ConvertConfiguration( "Test"); } diff --git a/src/test/java/org/bbreak/excella/reports/model/ModelTestSuite.java b/src/test/java/org/bbreak/excella/reports/model/ModelTestSuite.java deleted file mode 100644 index 65dc78c..0000000 --- a/src/test/java/org/bbreak/excella/reports/model/ModelTestSuite.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.model; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * Modelのテストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - ParamInfoTest.class, - ConvertConfigurationTest.class, - ReportBookTest.class, - ReportSheetTest.class, - ParsedReportInfoTest.class -}) -public class ModelTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/model/ParamInfoTest.java b/src/test/java/org/bbreak/excella/reports/model/ParamInfoTest.java index 3565159..104a883 100644 --- a/src/test/java/org/bbreak/excella/reports/model/ParamInfoTest.java +++ b/src/test/java/org/bbreak/excella/reports/model/ParamInfoTest.java @@ -20,14 +20,14 @@ package org.bbreak.excella.reports.model; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.model.ParamInfo} のためのテスト・クラス。 @@ -41,7 +41,7 @@ public class ParamInfoTest { /** * @throws java.lang.Exception */ - @Before + @BeforeEach public void setUp() throws Exception { info = new ParamInfo(); info.addParam( "$", "Test0", "Data0"); diff --git a/src/test/java/org/bbreak/excella/reports/model/ParsedReportInfoTest.java b/src/test/java/org/bbreak/excella/reports/model/ParsedReportInfoTest.java index 05fd614..ecba7f1 100644 --- a/src/test/java/org/bbreak/excella/reports/model/ParsedReportInfoTest.java +++ b/src/test/java/org/bbreak/excella/reports/model/ParsedReportInfoTest.java @@ -20,11 +20,9 @@ package org.bbreak.excella.reports.model; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.model.ParsedReportInfo} のためのテスト・クラス。 @@ -33,20 +31,6 @@ */ public class ParsedReportInfoTest { - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * {@link org.bbreak.excella.reports.model.ParsedReportInfo#getRowIndex()} のためのテスト・メソッド。 */ diff --git a/src/test/java/org/bbreak/excella/reports/model/ReportBookTest.java b/src/test/java/org/bbreak/excella/reports/model/ReportBookTest.java index 04d8ce0..99042a1 100644 --- a/src/test/java/org/bbreak/excella/reports/model/ReportBookTest.java +++ b/src/test/java/org/bbreak/excella/reports/model/ReportBookTest.java @@ -20,14 +20,14 @@ package org.bbreak.excella.reports.model; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.model.ReportBook} のためのテスト・クラス。 @@ -38,20 +38,6 @@ public class ReportBookTest { private ReportBook reportBook = null; - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * {@link org.bbreak.excella.reports.model.ReportBook#ReportBook(String, String, ConvertConfiguration...)} のためのテスト・メソッド。 */ diff --git a/src/test/java/org/bbreak/excella/reports/model/ReportSheetTest.java b/src/test/java/org/bbreak/excella/reports/model/ReportSheetTest.java index 6c77d0b..14913f4 100644 --- a/src/test/java/org/bbreak/excella/reports/model/ReportSheetTest.java +++ b/src/test/java/org/bbreak/excella/reports/model/ReportSheetTest.java @@ -20,14 +20,13 @@ package org.bbreak.excella.reports.model; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.model.ReportSheet} のためのテスト・クラス。 @@ -36,20 +35,6 @@ */ public class ReportSheetTest { - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * {@link org.bbreak.excella.reports.model.ReportSheet#ReportSheet(java.lang.String, java.lang.String)} のためのテスト・メソッド。 */ diff --git a/src/test/java/org/bbreak/excella/reports/others/ImageDisplayTest.java b/src/test/java/org/bbreak/excella/reports/others/ImageDisplayTest.java index 334a3a7..a465e95 100644 --- a/src/test/java/org/bbreak/excella/reports/others/ImageDisplayTest.java +++ b/src/test/java/org/bbreak/excella/reports/others/ImageDisplayTest.java @@ -30,9 +30,7 @@ import org.bbreak.excella.reports.model.ReportSheet; import org.bbreak.excella.reports.processor.ReportProcessor; import org.bbreak.excella.reports.tag.ImageParamParser; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * 画像描画確認のためのテストクラス @@ -56,20 +54,6 @@ public class ImageDisplayTest { */ private static final Integer PLURAL_COPY_SECOND_NUM_OF_SHEETS = 4; - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * 目視確認用の画像付ファイルを出力します */ diff --git a/src/test/java/org/bbreak/excella/reports/others/OthersTestSuite.java b/src/test/java/org/bbreak/excella/reports/others/OthersTestSuite.java deleted file mode 100644 index 8b782e8..0000000 --- a/src/test/java/org/bbreak/excella/reports/others/OthersTestSuite.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.others; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * その他(画像・印刷設定)テストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - PrintSettingCopyTest.class, - ImageDisplayTest.class -}) -public class OthersTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java b/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java index 80e6572..e5a5d08 100644 --- a/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java +++ b/src/test/java/org/bbreak/excella/reports/others/PrintSettingCopyTest.java @@ -36,9 +36,7 @@ import org.bbreak.excella.reports.processor.ReportProcessor; import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.util.ReportsUtil; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * テンプレートをシートコピーした時の印刷設定確認のためのテストクラス @@ -62,20 +60,6 @@ public class PrintSettingCopyTest { */ private static final Integer PLURAL_COPY_SECOND_NUM_OF_SHEETS = 4; - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * 印刷設定付のコピーをテストし、ファイルを出力します */ diff --git a/src/test/java/org/bbreak/excella/reports/processor/ProcessorTestSuite.java b/src/test/java/org/bbreak/excella/reports/processor/ProcessorTestSuite.java deleted file mode 100644 index 240dbe1..0000000 --- a/src/test/java/org/bbreak/excella/reports/processor/ProcessorTestSuite.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.processor; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * Exporterのテストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - ReportProcessorTest.class, - ReportCreateHelperTest.class, - ReportsParserInfoTest.class -}) -public class ProcessorTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportCreateHelperTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportCreateHelperTest.java index eca581d..24bad2f 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportCreateHelperTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportCreateHelperTest.java @@ -20,9 +20,9 @@ package org.bbreak.excella.reports.processor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Map; @@ -38,7 +38,7 @@ import org.bbreak.excella.reports.tag.RowRepeatParamParser; import org.bbreak.excella.reports.tag.SingleParamParser; import org.bbreak.excella.reports.tag.SumParamParser; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.processor.ReportCreateHelper} のためのテスト・クラス。 diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java index 62be244..3ae77e5 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportProcessorTest.java @@ -20,7 +20,12 @@ package org.bbreak.excella.reports.processor; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.FileNotFoundException; import java.lang.reflect.Field; @@ -38,6 +43,7 @@ import org.bbreak.excella.core.exception.ExportException; import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.exporter.ReportBookExporter; import org.bbreak.excella.reports.listener.ReportProcessAdaptor; import org.bbreak.excella.reports.listener.ReportProcessListener; @@ -46,7 +52,9 @@ import org.bbreak.excella.reports.model.ReportBook; import org.bbreak.excella.reports.model.ReportSheet; import org.bbreak.excella.reports.tag.ReportsTagParser; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.processor.ReportProcessor} のためのテスト・クラス。 @@ -66,14 +74,6 @@ public class ReportProcessorTest extends ReportsWorkbookTest { */ private List processStrings = new ArrayList(); - /** - * コンストラクタ - * - * @param version バージョン - */ - public ReportProcessorTest( String version) { - super( version); - } /** * {@link org.bbreak.excella.reports.processor.ReportProcessor#ReportProcessor()} @@ -120,10 +120,11 @@ public void testReportProcessor() * * @throws Exception */ - @Test - public void testProcess() throws Exception { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testProcess( String version) throws Exception { - getWorkbook(); + getWorkbook( version); ReportProcessor reportProcessor = new ReportProcessor(); reportProcessor.addReportProcessListener( new CustomListener()); @@ -243,20 +244,15 @@ public void testProcess() throws Exception { // -------------------------------------------------------------------------- processStrings.clear(); - // ブック1 - book1 = new ReportBook( "test", tmpDirPath + "workbookout1", configurations); + // ブック + ReportBook unknownTemplateBook = new ReportBook( "test", tmpDirPath + "workbookout1", configurations); // book1.setCopyTemplate( true); // →シート1 sheetC1 = new ReportSheet( "Sheet1", "CSheet1"); - book1.addReportSheet( sheetC1); + unknownTemplateBook.addReportSheet( sheetC1); - try { - reportProcessor.process( book1); - fail( "FileNotFoundException expected, but no exception was thrown."); - } catch ( FileNotFoundException e) { - assertTrue( true); - } + assertThrows( FileNotFoundException.class, () -> reportProcessor.process( unknownTemplateBook)); assertTrue( processStrings.isEmpty()); // --------------------------------------------------------------------------- @@ -350,19 +346,14 @@ public void testProcess() throws Exception { configurations = new ConvertConfiguration[] {configuration, configuration2}; // ブック1 - book1 = new ReportBook( getFilepath(), tmpDirPath + "workbookout1", configurations); + ReportBook errorBook= new ReportBook( getFilepath(), tmpDirPath + "workbookout1", configurations); // book1.setCopyTemplate( true); // →シート1 sheetC1 = new ReportSheet( "Sheet1", "CSheet1"); - book1.addReportSheet( sheetC1); + errorBook.addReportSheet( sheetC1); - try { - reportProcessor.process( book1); - fail( "Exception expected, but no exception was thrown."); - } catch ( Exception e) { - assertTrue( true); - } + assertThrows( Exception.class, () -> reportProcessor.process( errorBook)); exceptedProccess = new ArrayList(); exceptedProccess.add( "ブック解析前処理 CustomListener#preBookParse( Workbook workbook, ReportBook reportBook)"); diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java index d5fc28f..2eb0720 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportsParserInfoTest.java @@ -20,9 +20,9 @@ package org.bbreak.excella.reports.processor; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; import java.util.ArrayList; @@ -40,9 +40,7 @@ import org.bbreak.excella.reports.model.ReportBook; import org.bbreak.excella.reports.tag.ReportsTagParser; import org.bbreak.excella.reports.tag.SingleParamParser; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link org.bbreak.excella.reports.processor.ReportsParserInfo} のためのテスト・クラス。 @@ -51,20 +49,6 @@ */ public class ReportsParserInfoTest { - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - /** * {@link org.bbreak.excella.reports.processor.ReportsParserInfo#getParamInfo()} のためのテスト・メソッド。 */ diff --git a/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java b/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java index 38cb193..ecdb933 100644 --- a/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java +++ b/src/test/java/org/bbreak/excella/reports/processor/ReportsWorkbookTest.java @@ -22,7 +22,6 @@ import java.io.FileInputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; @@ -42,15 +41,7 @@ public abstract class ReportsWorkbookTest extends WorkbookTest { - /** Excelファイルのバージョン */ - protected String version = null; - - public ReportsWorkbookTest( String version) { - super( version); - this.version = version; - } - - protected Workbook getExpectedWorkbook() throws IOException { + protected Workbook getExpectedWorkbook( String version) throws IOException { Workbook workbook = null; @@ -66,7 +57,7 @@ protected Workbook getExpectedWorkbook() throws IOException { URL url = this.getClass().getResource( filename); String path = URLDecoder.decode( url.getFile(), "UTF-8"); - workbook = getWorkbook(path); + workbook = getWorkbookByPath(path); return workbook; } @@ -96,7 +87,7 @@ protected List parseSheet( ReportsTagParser parser, Sheet s } - protected Workbook getWorkbook(String filepath) throws IOException { + protected Workbook getWorkbookByPath(String filepath) throws IOException { Workbook workbook = null; diff --git a/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java index 6cb8d02..79b0662 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/BlockColRepeatParamParserTest.java @@ -20,7 +20,10 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -32,6 +35,7 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ConvertConfiguration; import org.bbreak.excella.reports.model.ParamInfo; import org.bbreak.excella.reports.model.ParsedReportInfo; @@ -42,7 +46,9 @@ import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.BlockColRepeatParamParser} のためのテスト・クラス。 @@ -50,19 +56,9 @@ */ public class BlockColRepeatParamParserTest extends ReportsWorkbookTest { - - - /** - * コンストラクタ - * @param version エクセルバージョン - */ - public BlockColRepeatParamParserTest( String version) { - super(version); - } - - - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { Workbook workbook = null; ReportBook reportBook = new ReportBook( "", "test", new ConvertConfiguration[] {}); @@ -189,7 +185,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[正常系]オプション指定なし // BC-C // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); results = parseSheet( parser, sheet1, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 3, 3)}; @@ -204,14 +200,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet1", sheet1, true); + checkSheet( "Sheet1", sheet1, true, version); // ----------------------- // □[正常系]オプション指定なし // BC-C2 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); results = parseSheet( parser, sheet2, reportsParserInfo); @@ -228,14 +224,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet2", sheet2, true); + checkSheet( "Sheet2", sheet2, true, version); // ----------------------- // □[正常系]オプション指定なし // BC-R // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet3 = workbook.getSheetAt( 2); results = parseSheet( parser, sheet3, reportsParserInfo); @@ -252,14 +248,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet3", sheet3, true); + checkSheet( "Sheet3", sheet3, true, version); // ----------------------- // □[正常系]オプション指定なし // BC-R2 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet4 = workbook.getSheetAt( 3); results = parseSheet( parser, sheet4, reportsParserInfo); @@ -268,14 +264,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept expectAfCells = new CellObject[] {new CellObject( 12, 6)}; checkResult( expectBeCells, expectAfCells, results); - checkSheet( "Sheet4", sheet4, true); + checkSheet( "Sheet4", sheet4, true, version); // ----------------------- // □[正常系]オプション指定なし // BC-CR // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet5 = workbook.getSheetAt( 4); results = parseSheet( parser, sheet5, reportsParserInfo); @@ -292,14 +288,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet5", sheet5, true); + checkSheet( "Sheet5", sheet5, true, version); // ----------------------- // □[正常系]オプション指定なし // BC-BC // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet6 = workbook.getSheetAt( 5); results = parseSheet( parser, sheet6, reportsParserInfo); @@ -317,14 +313,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept checkResult( expectBeCells, expectAfCells, results); - checkSheet( "Sheet6", sheet6, true); + checkSheet( "Sheet6", sheet6, true, version); // ----------------------- // □[正常系]オプション指定なし // BC-BR // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet7 = workbook.getSheetAt( 6); results = parseSheet( parser, sheet7, reportsParserInfo); @@ -341,7 +337,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet7", sheet7, true); + checkSheet( "sheet7", sheet7, true, version); // ----------------------- @@ -354,7 +350,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept reportsParserInfo8.setReportBook( reportBook); reportsParserInfo8.setParamInfo( reportSheets[1].getParamInfo()); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet8 = workbook.getSheetAt( 7); results = parseSheet( parser, sheet8, reportsParserInfo8); @@ -371,141 +367,93 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet8", sheet8, true); + checkSheet( "sheet8", sheet8, true, version); // ----------------------- // □[異常系]チェック // ・必須パラメータなし:fromCellなし、toCellなし // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet9 = workbook.getSheetAt( 8); - try { - results = parseSheet( parser, sheet9, reportsParserInfo); - fail( "fromCell必須チェックにかかっていない"); - } catch (ParseException e) { - } - checkSheet( "sheet9", sheet9, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet9, reportsParserInfo), "fromCell必須チェックにかかっていない"); + checkSheet( "sheet9", sheet9, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet10 = workbook.getSheetAt( 9); - try { - results = parseSheet( parser, sheet10, reportsParserInfo); - fail( "toCell必須チェックにかかっていない"); - } catch (ParseException e) { - } - checkSheet( "sheet10", sheet10, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet10, reportsParserInfo), "toCell必須チェックにかかっていない"); + checkSheet( "sheet10", sheet10, true, version); // ----------------------- // □[異常系]チェック // ・値不正:fromCell、toCell // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet11 = workbook.getSheetAt( 10); - try { - results = parseSheet( parser, sheet11, reportsParserInfo); - fail( "fromCellの値の個数チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet11", sheet11, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet11, reportsParserInfo), "fromCellの値の個数チェックにかかっていない"); + checkSheet( "sheet11", sheet11, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet12 = workbook.getSheetAt( 11); - try { - results = parseSheet( parser, sheet12, reportsParserInfo); - fail( "toCellの値の個数チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet12", sheet12, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet12, reportsParserInfo), "toCellの値の個数チェックにかかっていない"); + checkSheet( "sheet12", sheet12, true, version); // ----------------------- // □[異常系]チェック // ・値不正:fromCell、toCell // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet13 = workbook.getSheetAt( 12); - try { - results = parseSheet( parser, sheet13, reportsParserInfo); - fail( "fromCellのマイナス値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet13", sheet13, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet13, reportsParserInfo), "fromCellのマイナス値チェックにかかっていない"); + checkSheet( "sheet13", sheet13, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet14 = workbook.getSheetAt( 13); - try { - results = parseSheet( parser, sheet14, reportsParserInfo); - fail( "toCellのマイナス値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet14", sheet14, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet14, reportsParserInfo), "toCellのマイナス値チェックにかかっていない"); + checkSheet( "sheet14", sheet14, true, version); // ----------------------- // □[異常系]チェック // ・値不正:fromCell > toCell // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet15 = workbook.getSheetAt( 14); - try { - results = parseSheet( parser, sheet15, reportsParserInfo); - fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet15", sheet15, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet15, reportsParserInfo), "fromCell > toCellチェックにかかっていない"); + checkSheet( "sheet15", sheet15, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet17 = workbook.getSheetAt( 16); - try { - results = parseSheet( parser, sheet17, reportsParserInfo); - fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet17", sheet17, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet17, reportsParserInfo), "fromCell > toCellチェックにかかっていない"); + checkSheet( "sheet17", sheet17, true, version); // ----------------------- // □[異常系]チェック // ・値不正:repeatNum // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet16 = workbook.getSheetAt( 15); - try { - results = parseSheet( parser, sheet16, reportsParserInfo); - fail( "repeatNumの数値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet16", sheet16, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet16, reportsParserInfo), "repeatNumの数値チェックにかかっていない"); + checkSheet( "sheet16", sheet16, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet18 = workbook.getSheetAt( 17); - try { - results = parseSheet( parser, sheet18, reportsParserInfo); - fail( "repeatNumの数値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet18", sheet18, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet18, reportsParserInfo), "repeatNumの数値チェックにかかっていない"); + checkSheet( "sheet18", sheet18, true, version); // ---------------------------------- // □[正常系]チェック @@ -518,7 +466,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // // 3.指定範囲外に列方向の結合セルが存在 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet19 = workbook.getSheetAt( 18); results = parseSheet( parser, sheet19, reportsParserInfo); @@ -535,13 +483,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet19", sheet19, true); + checkSheet( "sheet19", sheet19, true, version); // ---------------------------------- // □[正常系]チェック // 行結合セルと列結合セル混在 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet20 = workbook.getSheetAt( 19); results = parseSheet( parser, sheet20, reportsParserInfo); @@ -558,7 +506,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet20", sheet20, true); + checkSheet( "sheet20", sheet20, true, version); // ---------------------------------- // ■[異常系]チェック @@ -566,22 +514,18 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // 列方向の結合セルが存在する場合に // 発生する例外処理の確認 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet21 = workbook.getSheetAt( 20); - try { - results = parseSheet( parser, sheet21, reportsParserInfo); - fail( "例外処理が発生していない"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - // ※補足 - // BR、BCの場合には子タグから親タグに例外がスローされた時に - // ParseExceptionをさらに入れ子にして例外をスローするため、 - // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 - assertTrue( e.getMessage().contains("IllegalArgumentException")); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + ParseException pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet21, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + // ※補足 + // BR、BCの場合には子タグから親タグに例外がスローされた時に + // ParseExceptionをさらに入れ子にして例外をスローするため、 + // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 + assertTrue( pe.getMessage().contains("IllegalArgumentException")); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // 不要シートを削除 if ( version.equals( "2007")) { @@ -591,7 +535,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet21", sheet21, true); + checkSheet( "sheet21", sheet21, true, version); // ---------------------------------- // ■[異常系]チェック @@ -599,22 +543,18 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // 行方向の結合セルが存在する場合に // 発生する例外処理の確認 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet22 = workbook.getSheetAt( 21); - try { - results = parseSheet( parser, sheet22, reportsParserInfo); - fail( "例外処理が発生していない"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - // ※補足 - // BR、BCの場合には子タグから親タグに例外がスローされた時に - // ParseExceptionをさらに入れ子にして例外をスローするため、 - // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 - assertTrue( e.getMessage().contains("IllegalArgumentException")); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet22, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + // ※補足 + // BR、BCの場合には子タグから親タグに例外がスローされた時に + // ParseExceptionをさらに入れ子にして例外をスローするため、 + // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 + assertTrue( pe.getMessage().contains("IllegalArgumentException")); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // 不要シートを削除 if ( version.equals( "2007")) { @@ -624,7 +564,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet22", sheet22, true); + checkSheet( "sheet22", sheet22, true, version); // ----------------------- // □[正常系]オプション指定 @@ -635,7 +575,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept reportsParserInfo23.setReportBook( reportBook); reportsParserInfo23.setParamInfo( reportSheets[0].getParamInfo()); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet23 = workbook.getSheetAt( 22); results = parseSheet( parser, sheet23, reportsParserInfo23); @@ -652,7 +592,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet23", sheet23, true); + checkSheet( "sheet23", sheet23, true, version); // ----------------------- // □[正常系]オプション指定 @@ -663,7 +603,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept reportsParserInfo24.setReportBook( reportBook); reportsParserInfo24.setParamInfo( reportSheets[0].getParamInfo()); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet24 = workbook.getSheetAt( 23); results = parseSheet( parser, sheet24, reportsParserInfo24); @@ -680,7 +620,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet24", sheet24, true); + checkSheet( "sheet24", sheet24, true, version); } @@ -708,19 +648,11 @@ public void testBlockColRepeatParamParserString() { assertEquals( "てすと", parser.getTag()); } - - - - - - - - - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); expectedSheet.getPrintSetup().getCopies(); diff --git a/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java index 2bef434..ee6839a 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/BlockRowRepeatParamParserTest.java @@ -20,10 +20,10 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -35,6 +35,7 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ConvertConfiguration; import org.bbreak.excella.reports.model.ParamInfo; import org.bbreak.excella.reports.model.ParsedReportInfo; @@ -45,21 +46,16 @@ import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; public class BlockRowRepeatParamParserTest extends ReportsWorkbookTest { - /** - * コンストラクタ - * @param version エクセルバージョン - */ - public BlockRowRepeatParamParserTest( String version) { - super(version); - } - - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { Workbook workbook = null; ReportBook reportBook = new ReportBook( "", "test", new ConvertConfiguration[] {}); @@ -188,7 +184,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[正常系]オプション指定なし // BR-C // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); results = parseSheet( parser, sheet1, reportsParserInfo); expectBeCells = new CellObject[] {new CellObject( 3, 3)}; @@ -203,14 +199,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet1", sheet1, true); + checkSheet( "Sheet1", sheet1, true, version); // ----------------------- // □[正常系]オプション指定なし // BR-C2 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); results = parseSheet( parser, sheet2, reportsParserInfo); @@ -227,13 +223,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet2", sheet2, true); + checkSheet( "Sheet2", sheet2, true, version); // ----------------------- // □[正常系]オプション指定なし // BR-R // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet3 = workbook.getSheetAt( 2); results = parseSheet( parser, sheet3, reportsParserInfo); @@ -250,14 +246,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet3", sheet3, true); + checkSheet( "Sheet3", sheet3, true, version); // ----------------------- // □[正常系]オプション指定なし // BR-R2 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet4 = workbook.getSheetAt( 3); results = parseSheet( parser, sheet4, reportsParserInfo); @@ -266,14 +262,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept expectAfCells = new CellObject[] {new CellObject( 24, 3)}; checkResult( expectBeCells, expectAfCells, results); - checkSheet( "Sheet4", sheet4, true); + checkSheet( "Sheet4", sheet4, true, version); // ----------------------- // □[正常系]オプション指定なし // BR-CR // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet5 = workbook.getSheetAt( 4); results = parseSheet( parser, sheet5, reportsParserInfo); @@ -290,14 +286,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet5", sheet5, true); + checkSheet( "Sheet5", sheet5, true, version); // ----------------------- // □[正常系]オプション指定なし // BR-BR // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet6 = workbook.getSheetAt( 5); results = parseSheet( parser, sheet6, reportsParserInfo); @@ -315,14 +311,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept checkResult( expectBeCells, expectAfCells, results); - checkSheet( "Sheet6", sheet6, true); + checkSheet( "Sheet6", sheet6, true, version); // ----------------------- // □[正常系]オプション指定なし // BR-BC // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet7 = workbook.getSheetAt( 6); results = parseSheet( parser, sheet7, reportsParserInfo); @@ -339,7 +335,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet7", sheet7, true); + checkSheet( "sheet7", sheet7, true, version); // ----------------------- @@ -352,7 +348,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept reportsParserInfo8.setReportBook( reportBook); reportsParserInfo8.setParamInfo( reportSheets[1].getParamInfo()); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet8 = workbook.getSheetAt( 7); results = parseSheet( parser, sheet8, reportsParserInfo8); @@ -369,60 +365,40 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet8", sheet8, true); + checkSheet( "sheet8", sheet8, true, version); // ----------------------- // □[異常系]チェック // ・必須パラメータなし:fromCellなし、toCellなし // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet9 = workbook.getSheetAt( 8); - try { - results = parseSheet( parser, sheet9, reportsParserInfo); - fail( "fromCell必須チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet9", sheet9, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet9, reportsParserInfo), "fromCell必須チェックにかかっていない"); + checkSheet( "sheet9", sheet9, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet10 = workbook.getSheetAt( 9); - try { - results = parseSheet( parser, sheet10, reportsParserInfo); - fail( "toCell必須チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet10", sheet10, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet10, reportsParserInfo), "toCell必須チェックにかかっていない"); + checkSheet( "sheet10", sheet10, true, version); // ----------------------- // □[異常系]チェック // ・値不正:fromCell、toCell // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet11 = workbook.getSheetAt( 10); - try { - results = parseSheet( parser, sheet11, reportsParserInfo); - fail( "fromCellの値の個数チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet11", sheet11, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet11, reportsParserInfo), "fromCellの値の個数チェックにかかっていない"); + checkSheet( "sheet11", sheet11, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet12 = workbook.getSheetAt( 11); - try { - results = parseSheet( parser, sheet12, reportsParserInfo); - fail( "toCellの値の個数チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet12", sheet12, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet12, reportsParserInfo), "toCellの値の個数チェックにかかっていない"); + checkSheet( "sheet12", sheet12, true, version); @@ -430,84 +406,54 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[異常系]チェック // ・値不正:fromCell、toCell // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet13 = workbook.getSheetAt( 12); - try { - results = parseSheet( parser, sheet13, reportsParserInfo); - fail( "fromCellのマイナス値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet13", sheet13, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet13, reportsParserInfo), "fromCellのマイナス値チェックにかかっていない"); + checkSheet( "sheet13", sheet13, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet14 = workbook.getSheetAt( 13); - try { - results = parseSheet( parser, sheet14, reportsParserInfo); - fail( "toCellのマイナス値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet14", sheet14, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet14, reportsParserInfo), "toCellのマイナス値チェックにかかっていない"); + checkSheet( "sheet14", sheet14, true, version); // ----------------------- // □[異常系]チェック // ・値不正:fromCell > toCell // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet15 = workbook.getSheetAt( 14); - try { - results = parseSheet( parser, sheet15, reportsParserInfo); - fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet15", sheet15, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet15, reportsParserInfo), "fromCell > toCellチェックにかかっていない"); + checkSheet( "sheet15", sheet15, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet17 = workbook.getSheetAt( 16); - try { - results = parseSheet( parser, sheet17, reportsParserInfo); - fail( "fromCell > toCellチェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet17", sheet17, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet17, reportsParserInfo), "fromCell > toCellチェックにかかっていない"); + checkSheet( "sheet17", sheet17, true, version); // ----------------------- // □[異常系]チェック // ・値不正:repeatNum // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet16 = workbook.getSheetAt( 15); - try { - results = parseSheet( parser, sheet16, reportsParserInfo); - fail( "repeatNumの数値チェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet16", sheet16, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet16, reportsParserInfo), "repeatNumの数値チェックにかかっていない"); + checkSheet( "sheet16", sheet16, true, version); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet18 = workbook.getSheetAt( 17); - try { - results = parseSheet( parser, sheet18, reportsParserInfo); - fail( "repeatNumのマイナスチェックにかかっていない"); - } catch (ParseException expected) { - // ok - } - checkSheet( "sheet18", sheet18, true); + assertThrows( ParseException.class, () -> parseSheet( parser, sheet18, reportsParserInfo), "repeatNumのマイナスチェックにかかっていない"); + checkSheet( "sheet18", sheet18, true, version); // ---------------------------------- // □[正常系]チェック @@ -520,7 +466,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // // 3.指定範囲外に列方向の結合セルが存在 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet19 = workbook.getSheetAt( 18); results = parseSheet( parser, sheet19, reportsParserInfo); @@ -537,13 +483,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet19", sheet19, true); + checkSheet( "sheet19", sheet19, true, version); // ---------------------------------- // □[正常系]チェック // 行結合セルと列結合セル混在 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet20 = workbook.getSheetAt( 19); results = parseSheet( parser, sheet20, reportsParserInfo); @@ -560,7 +506,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet20", sheet20, true); + checkSheet( "sheet20", sheet20, true, version); // ---------------------------------- // ■[異常系]チェック @@ -568,22 +514,18 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // 列方向の結合セルが存在する場合に // 発生する例外処理の確認 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet21 = workbook.getSheetAt( 20); - try { - results = parseSheet( parser, sheet21, reportsParserInfo); - fail( "例外処理が発生していない"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - // ※補足 - // BR、BCの場合には子タグから親タグに例外がスローされた時に - // ParseExceptionをさらに入れ子にして例外をスローするため、 - // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 - assertTrue( e.getMessage().contains("IllegalArgumentException")); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + ParseException pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet21, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + // ※補足 + // BR、BCの場合には子タグから親タグに例外がスローされた時に + // ParseExceptionをさらに入れ子にして例外をスローするため、 + // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 + assertTrue( pe.getMessage().contains("IllegalArgumentException")); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // 不要シートを削除 if ( version.equals( "2007")) { @@ -593,7 +535,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet21", sheet21, true); + checkSheet( "sheet21", sheet21, true, version); // ---------------------------------- // ■[異常系]チェック @@ -601,22 +543,18 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // 行方向の結合セルが存在する場合に // 発生する例外処理の確認 // ---------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet22 = workbook.getSheetAt( 21); - try { - results = parseSheet( parser, sheet22, reportsParserInfo); - fail( "例外処理が発生していない"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - // ※補足 - // BR、BCの場合には子タグから親タグに例外がスローされた時に - // ParseExceptionをさらに入れ子にして例外をスローするため、 - // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 - assertTrue( e.getMessage().contains("IllegalArgumentException")); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet22, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + // ※補足 + // BR、BCの場合には子タグから親タグに例外がスローされた時に + // ParseExceptionをさらに入れ子にして例外をスローするため、 + // getCauseによるinstanceofは使用せずにgetMessageで評価を行いました。 + assertTrue( pe.getMessage().contains("IllegalArgumentException")); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // 不要シートを削除 if ( version.equals( "2007")) { @@ -626,7 +564,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet22", sheet22, true); + checkSheet( "sheet22", sheet22, true, version); // ----------------------- // □[正常系]オプション指定 @@ -637,7 +575,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept reportsParserInfo23.setReportBook( reportBook); reportsParserInfo23.setParamInfo( reportSheets[0].getParamInfo()); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet23 = workbook.getSheetAt( 22); results = parseSheet( parser, sheet23, reportsParserInfo23); @@ -654,7 +592,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet23", sheet23, true); + checkSheet( "sheet23", sheet23, true, version); // ----------------------- // □[正常系]オプション指定 // ・最低繰返回数(最低繰返数=paramInfo数+1) @@ -664,7 +602,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept reportsParserInfo24.setReportBook( reportBook); reportsParserInfo24.setParamInfo( reportSheets[0].getParamInfo()); - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet24 = workbook.getSheetAt( 23); results = parseSheet( parser, sheet24, reportsParserInfo24); @@ -681,7 +619,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "sheet24", sheet24, true); + checkSheet( "sheet24", sheet24, true, version); } @@ -710,11 +648,11 @@ public void testBlockRowRepeatParamParserString() { } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java index 38c9606..4a95ac7 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/BreakParamParserTest.java @@ -20,22 +20,26 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.bbreak.excella.core.exception.ParseException; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ParsedReportInfo; import org.bbreak.excella.reports.processor.CellObject; import org.bbreak.excella.reports.processor.ReportCreateHelper; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.BreakParamParser} のためのテスト・クラス。 @@ -44,25 +48,18 @@ */ public class BreakParamParserTest extends ReportsWorkbookTest { - /** - * コンストラクタ - * - * @param version Excelバージョン - */ - public BreakParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.BreakParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 * * @throws ParseException + * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); BreakParamParser parser = new BreakParamParser(); diff --git a/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java index ff59292..56c246f 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/ColRepeatParamParserTest.java @@ -20,11 +20,11 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -36,6 +36,7 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ConvertConfiguration; import org.bbreak.excella.reports.model.ParamInfo; import org.bbreak.excella.reports.model.ParsedReportInfo; @@ -46,7 +47,9 @@ import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.ColRepeatParamParser} のためのテスト・クラス。 @@ -55,24 +58,22 @@ */ public class ColRepeatParamParserTest extends ReportsWorkbookTest { - public ColRepeatParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.ColRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 * * @throws ParseException * @throws ReportsCheckException + * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { Workbook workbook = null; // ----------------------- // □[正常系]オプション指定なし // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); ReportBook reportBook = new ReportBook("", "test", new ConvertConfiguration[] {}); @@ -114,13 +115,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet1", sheet1, true); + checkSheet( "Sheet1", sheet1, true, version); // ----------------------- // □[正常系]オプション指定 // ・重複非表示 // ・上限回数 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); // 解析処理 results = parseSheet( parser, sheet2, reportsParserInfo); @@ -136,13 +137,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet2", sheet2, true); + checkSheet( "Sheet2", sheet2, true, version); // ----------------------- // □[正常系]オプション指定 // ・シートリンク // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet3 = workbook.getSheetAt( 2); // 解析処理 results = parseSheet( parser, sheet3, reportsParserInfo); @@ -158,14 +159,14 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet3", sheet3, true); + checkSheet( "Sheet3", sheet3, true, version); // ----------------------- // □[異常系]チェック // ・必須パラメータなし:置換変数 // ・シートハイパーリンク設定有無と重複非表示は重複不可 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet4 = workbook.getSheetAt( 3); // 解析処理 results = parseSheet( parser, sheet4, reportsParserInfo); @@ -181,30 +182,21 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet4", sheet4, true); + checkSheet( "Sheet4", sheet4, true, version); Sheet sheet5 = workbook.getSheetAt( 4); // 解析処理 - try { - results = parseSheet( parser, sheet5, reportsParserInfo); - fail( "シートハイパーリンク設定有無と重複非表示は重複不可チェックにかかっていない"); - } catch ( ParseException expected) { - // ok - } + assertThrows( ParseException.class, () -> parseSheet( parser, sheet5, reportsParserInfo), + "シートハイパーリンク設定有無と重複非表示は重複不可チェックにかかっていない"); // ----------------------- // ■[異常系]チェック // ・エラーがあった場合 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet6 = workbook.getSheetAt( 5); // 解析処理 - try { - results = parseSheet( parser, sheet6, reportsParserInfo); - fail( "ParseException expected, but no exception was thrown."); - } catch ( ParseException e) { - assertTrue( e instanceof ParseException); - } + assertThrows( ParseException.class, () -> parseSheet( parser, sheet6, reportsParserInfo)); // ------------------------------------------------------------ // ■[異常系] @@ -212,24 +204,20 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // PoiUtil.getMergedAddressメソッドにて // 定義した想定例外が発生することの確認を行う // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet7 = workbook.getSheetAt( 6); // 解析処理 - try { - results = parseSheet( parser, sheet7, reportsParserInfo); - fail( "想定例外が発生せず"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - assertTrue( e.getCause() instanceof IllegalArgumentException); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + ParseException pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet7, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + assertTrue( pe.getCause() instanceof IllegalArgumentException); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // ------------------------------------------------------------ // □[正常系] // ・列方向の結合セル(サイズ2)が存在する場合の正常終了確認 // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet8 = workbook.getSheetAt( 7); // 解析処理 results = parseSheet( parser, sheet8, reportsParserInfo); @@ -245,13 +233,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet8", sheet8, true); + checkSheet( "Sheet8", sheet8, true, version); // ------------------------------------------------------------ // □[正常系] // ・列方向の結合セル(サイズ3)が存在する場合の正常終了確認 // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet9 = workbook.getSheetAt( 8); // 解析処理 results = parseSheet( parser, sheet9, reportsParserInfo); @@ -267,7 +255,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet9", sheet9, true); + checkSheet( "Sheet9", sheet9, true, version); // ------------------------------------------------------------ // ■[異常系] @@ -275,25 +263,20 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // PoiUtil.getMergedAddressメソッドにて // 定義した想定例外が発生することの確認を行う // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet10 = workbook.getSheetAt( 9); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet10, reportsParserInfo); - fail( "想定例外が発生せず"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - assertTrue( e.getCause() instanceof IllegalArgumentException); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet10, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + assertTrue( pe.getCause() instanceof IllegalArgumentException); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // ------------------------------------------------------------ // □[正常系] // ・最低繰返回数 // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet15 = workbook.getSheetAt( 14); // 解析処理 results = parseSheet( parser, sheet15, reportsParserInfo); @@ -311,7 +294,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet15", sheet15, true); + checkSheet( "Sheet15", sheet15, true, version); } /** @@ -337,11 +320,11 @@ public void testColRepeatParamParserString() { assertEquals( "てすと", parser.getTag()); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java index d93170b..2e3a723 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/ImageParamParserTest.java @@ -20,8 +20,8 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.IOException; @@ -39,12 +39,14 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ParamInfo; import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.ImageParamParser} のためのテスト・クラス。 @@ -78,15 +80,6 @@ public class ImageParamParserTest extends ReportsWorkbookTest { */ private static final int PLURAL_COPY_SECOND_NUM_OF_SHEETS = 2; - /** - * コンストラクタ - * - * @param version バージョン - */ - public ImageParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.ImageParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 @@ -95,12 +88,13 @@ public ImageParamParserTest( String version) { * @throws ReportsCheckException * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException, IOException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { // ----------------------- // □[正常系]通常解析 // ----------------------- - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); @@ -123,7 +117,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( "Sheet1"); try { @@ -150,7 +144,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // ----------------------- // □[正常系]タグ変更 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); @@ -173,7 +167,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.getSheet( "Sheet2"); try { @@ -209,26 +203,21 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // ----------------------- // ■[異常系]チェック // ----------------------- - workbook = getWorkbook( path); + workbook = getWorkbookByPath( path); Sheet sheet3 = workbook.getSheetAt( 2); - parser = new ImageParamParser(); + ImageParamParser parserForCheck = new ImageParamParser(); - reportsParserInfo = new ReportsParserInfo(); - reportsParserInfo.setParamInfo( createTestData( ImageParamParser.DEFAULT_TAG)); + ReportsParserInfo parserInfoForCheck = new ReportsParserInfo(); + parserInfoForCheck.setParamInfo( createTestData( ImageParamParser.DEFAULT_TAG)); - try { - parseSheet( parser, sheet3, reportsParserInfo); - fail( "チェックにかかっていない"); - } catch ( ParseException expected) { - // ok - } + assertThrows( ParseException.class, () -> parseSheet( parserForCheck, sheet3, parserInfoForCheck), "チェックにかかっていない"); // ----------------------- // □[正常系]必須パラメータがない場合 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet4 = workbook.getSheetAt( 2); @@ -240,7 +229,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept parseSheet( parser, sheet4, reportsParserInfo); // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.getSheet( "Sheet4"); // チェック @@ -249,7 +238,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // ---------------------------------------------------------------------- // □[正常系]1シート出力 / タグで複数画像 / 単一テンプレートを上書き // ---------------------------------------------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet5 = workbook.getSheetAt( INDEX_OF_SHEET5); @@ -272,7 +261,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.getSheet( "Sheet5"); try { @@ -300,7 +289,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[正常系]1シート出力 / タグで複数画像 / 単一テンプレートを1回コピー // ---------------------------------------------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet6 = workbook.cloneSheet( INDEX_OF_SHEET5); @@ -323,7 +312,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.cloneSheet( INDEX_OF_SHEET5); try { @@ -351,7 +340,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[正常系] 複数シート出力 / タグで複数画像 / 単一テンプレートを複数回コピー // ---------------------------------------------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); for ( int i = 1; i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS; i++) { @@ -377,7 +366,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); for ( int i = 1; i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS; i++) { expectedSheet = expectedWorkbook.cloneSheet( INDEX_OF_SHEET5); } @@ -412,7 +401,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[正常系] 複数シート出力 / タグで複数画像 / 複数(2個)のテンプレートを複数回コピー // ---------------------------------------------------------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet = null; int totalNumOfCopies = PLURAL_COPY_FIRST_NUM_OF_SHEETS + PLURAL_COPY_SECOND_NUM_OF_SHEETS; @@ -444,7 +433,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); for ( int i = 1; i <= totalNumOfCopies; i++) { if ( i <= PLURAL_COPY_FIRST_NUM_OF_SHEETS) { expectedSheet = expectedWorkbook.cloneSheet( INDEX_OF_SHEET5); diff --git a/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java index be276b5..b0ad53f 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/RemoveParamParserTest.java @@ -20,22 +20,26 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.bbreak.excella.core.exception.ParseException; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ParsedReportInfo; import org.bbreak.excella.reports.processor.CellObject; import org.bbreak.excella.reports.processor.ReportCreateHelper; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.RemoveParamParser} のためのテスト・クラス。 @@ -44,25 +48,18 @@ */ public class RemoveParamParserTest extends ReportsWorkbookTest { - /** - * コンストラクタ - * - * @param version Excelバージョン - */ - public RemoveParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.RemoveParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 * * @throws ParseException + * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); RemoveParamParser parser = new RemoveParamParser(); diff --git a/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java index b30a2a3..2e10c28 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/RowRepeatParamParserTest.java @@ -20,11 +20,11 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -36,6 +36,7 @@ import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ConvertConfiguration; import org.bbreak.excella.reports.model.ParamInfo; import org.bbreak.excella.reports.model.ParsedReportInfo; @@ -46,7 +47,9 @@ import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.RowRepeatParamParser} のためのテスト・クラス。 @@ -55,21 +58,19 @@ */ public class RowRepeatParamParserTest extends ReportsWorkbookTest { - public RowRepeatParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.RowRepeatParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 * * @throws ParseException * @throws ReportsCheckException + * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); // ----------------------- @@ -116,7 +117,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet1", sheet1, true); + checkSheet( "Sheet1", sheet1, true, version); // ----------------------- // □[正常系]オプション指定 @@ -126,7 +127,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // ・上限回数 // ・セルシフト // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); // 解析処理 results = parseSheet( parser, sheet2, reportsParserInfo); @@ -142,13 +143,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet2", sheet2, true); + checkSheet( "Sheet2", sheet2, true, version); // ----------------------- // □[正常系]オプション指定 // ・シートリンク // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet3 = workbook.getSheetAt( 2); // 解析処理 results = parseSheet( parser, sheet3, reportsParserInfo); @@ -164,13 +165,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet3", sheet3, true); + checkSheet( "Sheet3", sheet3, true, version); // ----------------------- // ■[異常系]チェック // ・シートハイパーリンク設定有無と重複非表示は重複不可 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet4 = workbook.getSheetAt( 3); // 解析処理 results = null; @@ -187,30 +188,20 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet4", sheet4, true); + checkSheet( "Sheet4", sheet4, true, version); Sheet sheet5 = workbook.getSheetAt( 4); // 解析処理 - try { - parseSheet( parser, sheet5, reportsParserInfo); - fail( "シートハイパーリンク設定有無と重複非表示は重複不可チェックにかかっていない"); - } catch ( ParseException expected) { - // ok - } + assertThrows( ParseException.class, () -> parseSheet( parser, sheet5, reportsParserInfo), "シートハイパーリンク設定有無と重複非表示は重複不可チェックにかかっていない"); // ----------------------- // ■[異常系]チェック // ・エラーがあった場合 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet6 = workbook.getSheetAt( 5); // 解析処理 - try { - parseSheet( parser, sheet6, reportsParserInfo); - fail( "ParseException expected, but no exception was thrown."); - } catch ( ParseException e) { - assertTrue( e instanceof ParseException); - } + assertThrows( ParseException.class, () -> parseSheet( parser, sheet6, reportsParserInfo)); // ------------------------------------------------------------ // ■[異常系] @@ -218,24 +209,20 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // PoiUtil.getMergedAddressメソッドにて // 定義した想定例外が発生することの確認を行う // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet7 = workbook.getSheetAt( 6); // 解析処理 - try { - results = parseSheet( parser, sheet7, reportsParserInfo); - fail( "想定例外が発生せず"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - assertTrue( e.getCause() instanceof IllegalArgumentException); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + ParseException pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet7, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + assertTrue( pe.getCause() instanceof IllegalArgumentException); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // ------------------------------------------------------------ // □[正常系] // ・行方向の結合セル(サイズ2)が存在する場合の正常終了確認 // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet8 = workbook.getSheetAt( 7); // 解析処理 results = parseSheet( parser, sheet8, reportsParserInfo); @@ -251,13 +238,13 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept workbook.removeSheetAt( index); } } - checkSheet( "Sheet8", sheet8, true); + checkSheet( "Sheet8", sheet8, true, version); // ------------------------------------------------------------ // □[正常系] // ・行方向の結合セル(サイズ3)が存在する場合の正常終了確認 // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet9 = workbook.getSheetAt( 8); // 解析処理 results = parseSheet( parser, sheet9, reportsParserInfo); @@ -274,7 +261,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet9", sheet9, true); + checkSheet( "Sheet9", sheet9, true, version); // ------------------------------------------------------------ @@ -283,34 +270,29 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // PoiUtil.getMergedAddressメソッドにて // 定義した想定例外が発生することの確認を行う // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet10 = workbook.getSheetAt( 9); // 解析処理 - results = null; - try { - results = parseSheet( parser, sheet10, reportsParserInfo); - fail( "想定例外が発生せず"); - } catch ( ParseException e) { - // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) - // でthrowした想定例外であることを確認する - assertTrue( e.getCause() instanceof IllegalArgumentException); - assertTrue( e.getMessage().contains("There are crossing merged regions in the range.")); - } + pe = assertThrows( ParseException.class, () -> parseSheet( parser, sheet10, reportsParserInfo)); + // org.bbreak.excella.core.util.PoiUtil#getMergedAddress( Sheet sheet, CellRangeAddress rangeAddress) + // でthrowした想定例外であることを確認する + assertTrue( pe.getCause() instanceof IllegalArgumentException); + assertTrue( pe.getMessage().contains("There are crossing merged regions in the range.")); // ------------------------------------------------------------ // □[正常系] // ・行シフト先に結合セルがある // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet17 = workbook.getSheetAt( 16); results = parseSheet( parser, sheet17, reportsParserInfo); - checkSheet( "Sheet17", sheet17, true); + checkSheet( "Sheet17", sheet17, true, version); // ------------------------------------------------------------ // □[正常系] // ・最低繰返回数 // ------------------------------------------------------------ - workbook = getWorkbook(); + workbook = getWorkbook( version); Sheet sheet18 = workbook.getSheetAt( 17); // 解析処理 results = parseSheet( parser, sheet18, reportsParserInfo); @@ -328,7 +310,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet18", sheet18, true); + checkSheet( "Sheet18", sheet18, true, version); } /** @@ -354,11 +336,11 @@ public void testRowRepeatParamParserString() { assertEquals( "てすと", parser.getTag()); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java index 6bfda5d..498d284 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/SingleParamParserTest.java @@ -20,8 +20,9 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Calendar; @@ -30,11 +31,14 @@ import org.apache.poi.ss.usermodel.Workbook; import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.reports.ReportsTestUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.model.ParamInfo; import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.SingleParamParser} のためのテスト・クラス。 @@ -43,30 +47,23 @@ */ public class SingleParamParserTest extends ReportsWorkbookTest { - /** - * コンストラクタ - * - * @param version バージョン - */ - public SingleParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.SingleParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 * * @throws ParseException * @throws ReportsCheckException + * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { // ----------------------- // □[正常系]通常解析 // ----------------------- - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); @@ -120,7 +117,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept parseSheet( parser, sheet1, reportsParserInfo); // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( "Sheet1"); // チェック @@ -130,7 +127,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept // □[正常系]タグ名の変更 // ----------------------- - workbook = getWorkbook(); + workbook = getWorkbook( version); // テストデータ ParamInfo infoP = new ParamInfo(); @@ -166,7 +163,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept parseSheet( parser, sheet2, reportsParserInfo); // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.getSheet( "Sheet2"); // チェック @@ -183,7 +180,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept , reportsParserInfo); // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.getSheet( "Sheet2"); // チェック @@ -200,7 +197,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept parseSheet( parser, sheet3, reportsParserInfo); // 期待値ブックの読み込み - expectedWorkbook = getExpectedWorkbook(); + expectedWorkbook = getExpectedWorkbook( version); expectedSheet = expectedWorkbook.getSheet( "Sheet3"); // チェック diff --git a/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java b/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java index d8eb7f0..2376d03 100644 --- a/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java +++ b/src/test/java/org/bbreak/excella/reports/tag/SumParamParserTest.java @@ -20,9 +20,9 @@ package org.bbreak.excella.reports.tag; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.math.BigDecimal; @@ -35,6 +35,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.ReportsTestUtil; import org.bbreak.excella.reports.model.ConvertConfiguration; import org.bbreak.excella.reports.model.ParamInfo; @@ -46,7 +47,9 @@ import org.bbreak.excella.reports.processor.ReportsCheckException; import org.bbreak.excella.reports.processor.ReportsParserInfo; import org.bbreak.excella.reports.processor.ReportsWorkbookTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.tag.SumParamParser} のためのテスト・クラス。 @@ -55,25 +58,23 @@ */ public class SumParamParserTest extends ReportsWorkbookTest { - public SumParamParserTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.tag.SumParamParser#parse(org.apache.poi.ss.usermodel.Sheet, org.apache.poi.ss.usermodel.Cell, java.lang.Object)} * のためのテスト・メソッド。 * * @throws ParseException * @throws ReportsCheckException + * @throws IOException */ - @Test - public void testParseSheetCellObject() throws ParseException, ReportsCheckException { + @ParameterizedTest + @CsvSource( WorkbookTest.VERSIONS) + public void testParseSheetCellObject( String version) throws ParseException, ReportsCheckException, IOException { // ----------------------- // □[正常系]通常解析 // ----------------------- - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet1 = workbook.getSheetAt( 0); @@ -124,7 +125,7 @@ public void testParseSheetCellObject() throws ParseException, ReportsCheckExcept } } - checkSheet( "Sheet1", sheet1, true); + checkSheet( "Sheet1", sheet1, true, version); } @@ -146,11 +147,11 @@ public void testSumParamParserString() { assertEquals( "テスト", paser.getTag()); } - private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel) - throws ReportsCheckException { + private void checkSheet( String expectedSheetName, Sheet actualSheet, boolean outputExcel, String version) + throws ReportsCheckException, IOException { // 期待値ブックの読み込み - Workbook expectedWorkbook = getExpectedWorkbook(); + Workbook expectedWorkbook = getExpectedWorkbook( version); Sheet expectedSheet = expectedWorkbook.getSheet( expectedSheetName); try { diff --git a/src/test/java/org/bbreak/excella/reports/tag/TagTestSuite.java b/src/test/java/org/bbreak/excella/reports/tag/TagTestSuite.java deleted file mode 100644 index d4cfbfd..0000000 --- a/src/test/java/org/bbreak/excella/reports/tag/TagTestSuite.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.tag; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * タグのテストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - SingleParamParserTest.class, - ImageParamParserTest.class, - RowRepeatParamParserTest.class, - ColRepeatParamParserTest.class, - RemoveParamParserTest.class, - SumParamParserTest.class, - BlockColRepeatParamParserTest.class, - BlockRowRepeatParamParserTest.class, - BreakParamParserTest.class -}) -public class TagTestSuite { - -} diff --git a/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java b/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java index b9b0c78..6e6c3aa 100644 --- a/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java +++ b/src/test/java/org/bbreak/excella/reports/util/ReportsUtilTest.java @@ -20,11 +20,11 @@ package org.bbreak.excella.reports.util; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.math.BigDecimal; @@ -48,6 +48,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.bbreak.excella.core.exception.ParseException; import org.bbreak.excella.core.util.PoiUtil; +import org.bbreak.excella.reports.WorkbookTest; import org.bbreak.excella.reports.exporter.ExcelExporter; import org.bbreak.excella.reports.model.ConvertConfiguration; import org.bbreak.excella.reports.model.ParamInfo; @@ -62,7 +63,9 @@ import org.bbreak.excella.reports.tag.ReportsTagParser; import org.bbreak.excella.reports.tag.RowRepeatParamParser; import org.bbreak.excella.reports.tag.SingleParamParser; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; /** * {@link org.bbreak.excella.reports.util.ReportsUtil} のためのテスト・クラス。 @@ -71,10 +74,6 @@ */ public class ReportsUtilTest extends ReportsWorkbookTest { - public ReportsUtilTest( String version) { - super( version); - } - /** * {@link org.bbreak.excella.reports.util.ReportsUtil#getReportSheet(String, org.bbreak.excella.reports.model.ReportBook)} のためのテスト・メソッド。 */ @@ -459,36 +458,25 @@ public void testGetCellIndex() throws ParseException { assertEquals( 3, pos[0]); assertEquals( 5, pos[1]); - try { - pos = ReportsUtil.getCellIndex( "A:C", ""); - fail( "ParseExcepion excepted, but no exception was thrown."); - } catch ( ParseException e) { - assertTrue( true); - } + assertThrows( ParseException.class, () -> ReportsUtil.getCellIndex( "A:C", "")); - try { - pos = ReportsUtil.getCellIndex( "TEST", ""); - fail( "ParseExcepion excepted, but no exception was thrown."); - } catch ( ParseException e) { - assertTrue( true); - } + assertThrows( ParseException.class, () -> ReportsUtil.getCellIndex( "TEST", "")); - try { - pos = ReportsUtil.getCellIndex( "100", ""); - fail( "ParseExcepion excepted, but no exception was thrown."); - } catch ( ParseException e) { - assertTrue( true); - } + assertThrows( ParseException.class, () -> ReportsUtil.getCellIndex( "100", "")); } /** - * {@link org.bbreak.excella.reports.util.ReportsTagUtil#getBlockCellValue(org.apache.poi.ss.usermodel.Sheet, int, int, int, int)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.util.ReportsTagUtil#getBlockCellValue(org.apache.poi.ss.usermodel.Sheet, int, int, int, int)} + * のためのテスト・メソッド。 + * + * @throws IOException */ - @Test - public void testGetBlockCellValue() { + @ParameterizedTest + @CsvSource(WorkbookTest.VERSIONS) + public void testGetBlockCellValue(String version) throws IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet = workbook.getSheetAt( 0); Object[][] cellValues = ReportsUtil.getBlockCellValue( sheet, 0, 4, 0, 3); @@ -506,11 +494,15 @@ public void testGetBlockCellValue() { } /** - * {@link org.bbreak.excella.reports.util.ReportsTagUtil#getBlockCellStyle(org.apache.poi.ss.usermodel.Sheet, int, int, int, int)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.util.ReportsTagUtil#getBlockCellStyle(org.apache.poi.ss.usermodel.Sheet, int, int, int, int)} + * のためのテスト・メソッド。 + * + * @throws IOException */ - @Test - public void testGetBlockCellStyle() { - Workbook workbook = getWorkbook(); + @ParameterizedTest + @CsvSource(WorkbookTest.VERSIONS) + public void testGetBlockCellStyle(String version) throws IOException { + Workbook workbook = getWorkbook( version); Sheet sheet = workbook.getSheetAt( 0); Object[][] cellStyles = ReportsUtil.getBlockCellStyle( sheet, 0, 4, 0, 3); @@ -528,12 +520,16 @@ public void testGetBlockCellStyle() { } /** - * {@link org.bbreak.excella.reports.util.ReportsUtil#getRowHeight(org.apache.poi.ss.usermodel.Sheet, int, int)} のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.util.ReportsUtil#getRowHeight(org.apache.poi.ss.usermodel.Sheet, int, int)} + * のためのテスト・メソッド。 + * + * @throws IOException */ - @Test - public void testGetRowHeight() { + @ParameterizedTest + @CsvSource(WorkbookTest.VERSIONS) + public void testGetRowHeight(String version) throws IOException { - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet = workbook.getSheetAt( 0); Row row0 = sheet.getRow(0); @@ -554,13 +550,18 @@ public void testGetRowHeight() { } /** - * {@link org.bbreak.excella.reports.util.ReportsUtil#isEmptyRow( int[] rowCellTypes, Object[] rowCellValues, CellStyle[] rowCellStyles){}}のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.util.ReportsUtil#isEmptyRow( int[] + * rowCellTypes, Object[] rowCellValues, CellStyle[] + * rowCellStyles){}}のためのテスト・メソッド。 + * + * @throws IOException */ - @Test - public void testIsEmptyRow() { + @ParameterizedTest + @CsvSource(WorkbookTest.VERSIONS) + public void testIsEmptyRow(String version) throws IOException { // テストシートの取得 - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); // 開始列設定 ※初期値=0(A列) @@ -606,13 +607,17 @@ public void testIsEmptyRow() { } /** - * {@link org.bbreak.excella.reports.util.ReportsUtil#isEmptyCell( int cellType, Object cellValue, CellStyle cellStyle}のためのテスト・メソッド。 + * {@link org.bbreak.excella.reports.util.ReportsUtil#isEmptyCell( int cellType, + * Object cellValue, CellStyle cellStyle}のためのテスト・メソッド。 + * + * @throws IOException */ - @Test - public void testIsEmptyCell() { + @ParameterizedTest + @CsvSource(WorkbookTest.VERSIONS) + public void testIsEmptyCell(String version) throws IOException { // テストシートの取得 - Workbook workbook = getWorkbook(); + Workbook workbook = getWorkbook( version); Sheet sheet2 = workbook.getSheetAt( 1); // 開始列設定 ※初期値=0(A列) diff --git a/src/test/java/org/bbreak/excella/reports/util/UtilTestSuite.java b/src/test/java/org/bbreak/excella/reports/util/UtilTestSuite.java deleted file mode 100644 index 888024c..0000000 --- a/src/test/java/org/bbreak/excella/reports/util/UtilTestSuite.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * #%L - * excella-reports - * %% - * Copyright (C) 2009 - 2019 bBreak Systems and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -package org.bbreak.excella.reports.util; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -/** - * ユーティリティのテストスイート - * - * @since 1.0 - */ -@RunWith(Suite.class) -@SuiteClasses({ - ReportsUtilTest.class -}) -public class UtilTestSuite { - -}