1package junitparams;
2
3import org.junit.Ignore;
4import org.junit.Test;
5import org.junit.runner.RunWith;
6
7import junitparams.mappers.CsvWithHeaderMapper;
8import junitparams.usage.person_example.PersonMapper;
9import junitparams.usage.person_example.PersonTest.Person;
10
11import static org.assertj.core.api.Assertions.*;
12
13@RunWith(JUnitParamsRunner.class)
14public 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")
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)
26    public void loadParamsFromFileWithCustomMapper(Person person) {
27        assertThat(person.getAge()).isGreaterThan(0);
28    }
29
30    @Test
31    @FileParameters("classpath:test.csv")
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")
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)
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")
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")
57    public void loadParamWithWrongEncoding(String value) {
58        assertThat(value).isNotEqualTo("åäöÅÄÖ");
59    }
60}
61