Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>**/AllTestSuite.java</include>
</includes>
</configuration>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -109,7 +104,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.17</version>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</reporting>
Expand All @@ -120,9 +115,9 @@
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
51 changes: 0 additions & 51 deletions src/test/java/org/bbreak/excella/reports/AllTestSuite.java

This file was deleted.

85 changes: 12 additions & 73 deletions src/test/java/org/bbreak/excella/reports/WorkbookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,63 +21,28 @@
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;
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.Assert;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
* Workbookテストクラス
*
* @since 1.0
*/
@RunWith( Parameterized.class)
public class WorkbookTest {

/**
* ログ
*/
private static Log log = LogFactory.getLog( WorkbookTest.class);

/** Excelファイルのバージョン */
private String version = null;
public abstract class WorkbookTest {

/** ファイルパス */
private String filepath = null;

/**
* コンストラクタ
*
* @param version Excelファイルのバージョン
*/
public WorkbookTest( String version) {
protected static final String VERSIONS = "2003, 2007";

this.version = version;
if ( log.isDebugEnabled()) {
log.debug( "Start " + version + ".");
}
}

@Parameters
public static Collection<?> parameters() {
return Arrays.asList( new Object[][] {{"2003"}, {"2007"}});
}

protected Workbook getWorkbook() {
protected Workbook getWorkbook( String version) throws IOException {

Workbook workbook = null;

Expand All @@ -90,41 +55,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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} のためのテスト・クラス。
Expand All @@ -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;
Expand All @@ -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());



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

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;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLDecoder;
Expand All @@ -35,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}のためのテスト・クラス。
Expand All @@ -55,7 +54,7 @@ public class ExcelOutputStreamExporterTest {
* @throws Exception
*/
@Test
public void testOutput() {
public void testOutput() throws Exception {

FileOutputStream xlsFileOutputStream = null;
// 出力先
Expand Down Expand Up @@ -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テスト� - フォーマット単数指定・ストリーム出力によるファイル以外が削除されていることを確認
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}
}
Expand Down
Loading