Skip to content

Commit

Permalink
refs #90 テストファイルの出力先の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
mygreen committed Dec 23, 2016
1 parent b1d878b commit fed3e6c
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 292 deletions.
35 changes: 23 additions & 12 deletions src/test/java/com/gh/mygreen/xlsmapper/POIUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.gh.mygreen.xlsmapper;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import static com.gh.mygreen.xlsmapper.TestUtils.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
Expand All @@ -15,20 +17,29 @@
import org.apache.poi.ss.util.CellRangeAddressList;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.gh.mygreen.xlsmapper.POIUtils;
import com.gh.mygreen.xlsmapper.cellconvert.LinkType;


/**
* {@link POIUtils}のテスタ
*
* @version 1.0
* @author T.TSUCHIE
*
*/
public class POIUtilsTest {

@Before
public void setUp() throws Exception {
}
/**
* テスト結果ファイルの出力ディレクトリ
*/
private static File OUT_DIR;

@After
public void tearDown() throws Exception {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
OUT_DIR = createOutDir();
}

@Test
Expand Down Expand Up @@ -91,7 +102,7 @@ public void testUpdateDataValidationRegion_xssf_v() throws Exception {

assertThat(found, is(true));

workbook.write(new FileOutputStream("src/test/out/utils_out.xlsx"));
workbook.write(new FileOutputStream(new File(OUT_DIR, "utils_out.xlsx")));

}

Expand Down Expand Up @@ -138,7 +149,7 @@ public void testUpdateDataValidationRegion_xssf_h() throws Exception {

assertThat(found, is(true));

workbook.write(new FileOutputStream("src/test/out/utils_out.xlsx"));
workbook.write(new FileOutputStream(new File(OUT_DIR, "utils_out.xlsx")));

}

Expand Down Expand Up @@ -185,7 +196,7 @@ public void testUpdateDataValidationRegion_hssf() throws Exception {

assertThat(found, is(true));

workbook.write(new FileOutputStream("src/test/out/utils_out.xls"));
workbook.write(new FileOutputStream(new File(OUT_DIR, "utils_out.xls")));

}

Expand Down Expand Up @@ -216,9 +227,9 @@ public void testUpdateDataValidationRegion_hssf() throws Exception {
//
// assertThat(removed, is(true));
//
// workbook.write(new FileOutputStream("src/test/out/utils_out.xls"));
// workbook.write(new FileOutputStream(OUT_DIR, "utils_out.xls"));
//
// workbook = WorkbookFactory.create(new FileInputStream("src/test/out/utils_out.xls"));
// workbook = WorkbookFactory.create(new FileInputStream(new File(OUT_DIR, "utils_out.xls")));
// sheet = workbook.getSheet("入力規則");
//
// // 書き換わったかどうか確認する
Expand Down
26 changes: 15 additions & 11 deletions src/test/java/com/gh/mygreen/xlsmapper/SampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
Expand All @@ -26,6 +21,7 @@
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.BeforeClass;
import org.junit.Test;

import com.gh.mygreen.xlsmapper.annotation.LabelledCellType;
Expand All @@ -38,7 +34,6 @@
import com.gh.mygreen.xlsmapper.annotation.XlsPreSave;
import com.gh.mygreen.xlsmapper.annotation.XlsSheet;
import com.gh.mygreen.xlsmapper.annotation.XlsSheetName;
import com.gh.mygreen.xlsmapper.fieldprocessor.CellNotFoundException;

/**
* マニュアルなどに明記するためのサンプル
Expand All @@ -48,6 +43,15 @@
*/
public class SampleTest {

/**
* テスト結果ファイルの出力ディレクトリ
*/
private static File OUT_DIR;

@BeforeClass
public static void setUpBeforeClass() throws Exception {
OUT_DIR = createOutDir();
}

/**
* マッピングの基本 - 読み込み
Expand Down Expand Up @@ -131,13 +135,13 @@ public void test_HowTo_Save() throws Exception {
XlsMapper xlsMapper = new XlsMapper();
xlsMapper.save(
new FileInputStream("src/test/data/sample_template.xlsx"), // テンプレートのExcelファイル
new FileOutputStream("src/test/out/sample_out.xlsx"), // 書き込むExcelファイル
new FileOutputStream(new File(OUT_DIR, "sample_out.xlsx")), // 書き込むExcelファイル
sheet // 作成したデータ
);


// assertion
UserSheet inSheet = xlsMapper.load(new FileInputStream("src/test/out/sample_out.xlsx"), UserSheet.class);
UserSheet inSheet = xlsMapper.load(new FileInputStream(new File(OUT_DIR, "sample_out.xlsx")), UserSheet.class);
assertThat(inSheet.createDate, is(sheet.createDate));
assertThat(inSheet.users, hasSize(sheet.users.size()));
for(int i=0; i < inSheet.users.size(); i++) {
Expand Down Expand Up @@ -207,7 +211,7 @@ public void test_MapColumn_dynamic_save() throws Exception {
XlsMapper xlsMapper = new XlsMapper();
xlsMapper.save(
new FileInputStream("src/test/data/sample_template.xlsx"),
new FileOutputStream("src/test/out/sample_out.xlsx"),
new FileOutputStream(new File(OUT_DIR, "sample_out.xlsx")),
sheet
);

Expand Down Expand Up @@ -254,7 +258,7 @@ public void test_mofidy_sheet() throws Exception {

}

workbook.write(new FileOutputStream("src/test/out/sample_out.xlsx"));
workbook.write(new FileOutputStream(new File(OUT_DIR, "sample_out.xlsx")));
}

// シート用クラス
Expand Down Expand Up @@ -375,7 +379,7 @@ public void test_Sheet_regex_clone() throws Exception {
XlsMapper xlsMapper = new XlsMapper();
xlsMapper.saveMultiple(
new FileInputStream(cloneTemplateFile), // クローンしたシートを持つファイルを指定する
new FileOutputStream("src/test/out/sample_out.xlsx"),
new FileOutputStream(new File(OUT_DIR, "sample_out.xlsx")),
sheets);

}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/com/gh/mygreen/xlsmapper/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gh.mygreen.xlsmapper;

import java.awt.Point;
import java.io.File;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Arrays;
Expand Down Expand Up @@ -227,4 +228,22 @@ public static Date getDateByDay(Date base, int days) {
return cal.getTime();

}

/**
* テスト用の結果出力ディレクトリを作成します。
* <p>target/test_out</p> を作成します。
*
* @return
*/
public static File createOutDir() {

final File dir = new File("target/test_out");

if(!dir.exists()) {
dir.mkdirs();
}

return dir;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.gh.mygreen.xlsmapper.IsEmptyBuilder;
import com.gh.mygreen.xlsmapper.TestUtils;
import com.gh.mygreen.xlsmapper.XlsMapper;
import com.gh.mygreen.xlsmapper.annotation.OverRecordOperate;
import com.gh.mygreen.xlsmapper.annotation.RecordTerminal;
Expand All @@ -42,16 +41,14 @@
*/
public class BooleanCellConverterTest {

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}
/**
* テスト結果ファイルの出力ディレクトリ
*/
private static File OUT_DIR;

@After
public void tearDown() throws Exception {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
OUT_DIR = createOutDir();
}

/**
Expand Down Expand Up @@ -273,7 +270,7 @@ public void test_save_boolean() throws Exception {
XlsMapper mapper = new XlsMapper();
mapper.getConig().setContinueTypeBindFailure(true);

File outFile = new File("src/test/out/convert_boolean.xlsx");
File outFile = new File(OUT_DIR, "convert_boolean.xlsx");
try(InputStream template = new FileInputStream("src/test/data/convert_template.xlsx");
OutputStream out = new FileOutputStream(outFile)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.gh.mygreen.xlsmapper.IsEmptyBuilder;
Expand All @@ -47,16 +48,14 @@
*/
public class CollectionCellConveterTest {

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}
/**
* テスト結果ファイルの出力ディレクトリ
*/
private static File OUT_DIR;

@After
public void tearDown() throws Exception {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
OUT_DIR = createOutDir();
}

/**
Expand Down Expand Up @@ -478,7 +477,7 @@ public void test_save_collection() throws Exception {
XlsMapper mapper = new XlsMapper();
mapper.getConig().setContinueTypeBindFailure(true);

File outFile = new File("src/test/out/convert_collection.xlsx");
File outFile = new File(OUT_DIR, "convert_collection.xlsx");
try(InputStream template = new FileInputStream("src/test/data/convert_template.xlsx");
OutputStream out = new FileOutputStream(outFile)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.gh.mygreen.xlsmapper.IsEmptyBuilder;
Expand All @@ -47,16 +45,14 @@
*/
public class DateTimeCellConverterTest {

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}
/**
* テスト結果ファイルの出力ディレクトリ
*/
private static File OUT_DIR;

@After
public void tearDown() throws Exception {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
OUT_DIR = createOutDir();
}

@Test
Expand Down Expand Up @@ -252,7 +248,7 @@ public void test_save_date_time() throws Exception {
XlsMapper mapper = new XlsMapper();
mapper.getConig().setContinueTypeBindFailure(true);

File outFile = new File("src/test/out/convert_datetime.xlsx");
File outFile = new File(OUT_DIR, "convert_datetime.xlsx");
try(InputStream template = new FileInputStream("src/test/data/convert_template.xlsx");
OutputStream out = new FileOutputStream(outFile)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.gh.mygreen.xlsmapper.IsEmptyBuilder;
Expand Down Expand Up @@ -45,16 +43,14 @@
*/
public class EnumCellConverterTest {

@AfterClass
public static void tearDownAfterClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}
/**
* テスト結果ファイルの出力ディレクトリ
*/
private static File OUT_DIR;

@After
public void tearDown() throws Exception {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
OUT_DIR = createOutDir();
}

/**
Expand Down Expand Up @@ -209,7 +205,7 @@ public void test_save_enum() throws Exception {
XlsMapper mapper = new XlsMapper();
mapper.getConig().setContinueTypeBindFailure(true);

File outFile = new File("src/test/out/convert_enum.xlsx");
File outFile = new File(OUT_DIR, "convert_enum.xlsx");
try(InputStream template = new FileInputStream("src/test/data/convert_template.xlsx");
OutputStream out = new FileOutputStream(outFile)) {

Expand Down

0 comments on commit fed3e6c

Please sign in to comment.