1 package junitparams; 2 3 import org.junit.Ignore; 4 import org.junit.Test; 5 import org.junit.runner.RunWith; 6 7 import junitparams.mappers.CsvWithHeaderMapper; 8 import junitparams.usage.person_example.PersonMapper; 9 import junitparams.usage.person_example.PersonTest.Person; 10 11 import static org.assertj.core.api.Assertions.*; 12 13 @RunWith(JUnitParamsRunner.class) 14 public class FileParamsTest { 15 16 @Ignore("Does not work when run on device as it does not have access to the file") 17 @Test 18 @FileParameters("src/test/resources/test.csv") loadParamsFromFileWithIdentityMapper(int age, String name)19 public void loadParamsFromFileWithIdentityMapper(int age, String name) { 20 assertThat(age).isGreaterThan(0); 21 } 22 23 @Ignore("Does not work when run on device as it does not have access to the file") 24 @Test 25 @FileParameters(value = "src/test/resources/test.csv", mapper = PersonMapper.class) loadParamsFromFileWithCustomMapper(Person person)26 public void loadParamsFromFileWithCustomMapper(Person person) { 27 assertThat(person.getAge()).isGreaterThan(0); 28 } 29 30 @Test 31 @FileParameters("classpath:test.csv") loadParamsFromFileAtClasspath(int age, String name)32 public void loadParamsFromFileAtClasspath(int age, String name) { 33 assertThat(age).isGreaterThan(0); 34 } 35 36 @Ignore("Does not work when run on device as it does not have access to the file") 37 @Test 38 @FileParameters("file:src/test/resources/test.csv") loadParamsFromFileAtFilesystem(int age, String name)39 public void loadParamsFromFileAtFilesystem(int age, String name) { 40 assertThat(age).isGreaterThan(0); 41 } 42 43 @Test 44 @FileParameters(value = "classpath:with_header.csv", mapper = CsvWithHeaderMapper.class) csvWithHeader(int id, String name)45 public void csvWithHeader(int id, String name) { 46 assertThat(id).isGreaterThan(0); 47 } 48 49 @Test 50 @FileParameters(value = "classpath:with_special_chars.csv", encoding = "UTF-8") loadParamWithCorrectEncoding(String value)51 public void loadParamWithCorrectEncoding(String value) { 52 assertThat(value).isEqualTo("åäöÅÄÖ"); 53 } 54 55 @Test 56 @FileParameters(value = "classpath:with_special_chars.csv", encoding = "ISO-8859-1") loadParamWithWrongEncoding(String value)57 public void loadParamWithWrongEncoding(String value) { 58 assertThat(value).isNotEqualTo("åäöÅÄÖ"); 59 } 60 } 61