1 package club.wpia.gigi.dbObjects;
3 import static org.junit.Assert.*;
5 import java.util.Arrays;
8 import org.hamcrest.BaseMatcher;
9 import org.hamcrest.CoreMatchers;
10 import org.hamcrest.Description;
11 import org.hamcrest.Matcher;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.junit.runners.Parameterized;
15 import org.junit.runners.Parameterized.Parameter;
16 import org.junit.runners.Parameterized.Parameters;
18 import club.wpia.gigi.GigiApiException;
19 import club.wpia.gigi.dbObjects.Country;
20 import club.wpia.gigi.dbObjects.Country.CountryCodeType;
21 import club.wpia.gigi.testUtils.BusinessTest;
23 @RunWith(Parameterized.class)
24 public class TestCountryCode extends BusinessTest {
27 public CountryCodeType type;
29 @Parameters(name = "Type: {0}")
30 public static Iterable<Object[]> getParameters() {
31 return Arrays.<Object[]>asList(new Object[] {
32 CountryCodeType.CODE_2_CHARS
34 CountryCodeType.CODE_3_CHARS
39 public void testList() throws GigiApiException {
40 List<Country> ccs = Country.getCountries();
41 for (Country cc : ccs) {
42 assertThat(cc.getCode(type), stringLength(type.getLen()));
47 public void testFetch() throws GigiApiException {
48 String ref = type == CountryCodeType.CODE_2_CHARS ? "DE" : "DEU";
49 Country cc = Country.getCountryByCode(ref, type);
50 assertEquals(ref, cc.getCode(type));
51 assertEquals("Germany", cc.getName());
55 public void testCheck() throws GigiApiException {
56 String ref = type == CountryCodeType.CODE_2_CHARS ? "DE" : "DEU";
57 String reff = type == CountryCodeType.CODE_2_CHARS ? "DF" : "DFU";
59 Country.checkCountryCode(ref, type);
61 Country.checkCountryCode(reff, type);
62 } catch (GigiApiException e) {
63 assertThat(e.getMessage(), CoreMatchers.containsString("was wrong"));
66 Country.getCountryByCode(ref, type);
68 Country.getCountryByCode(reff, type);
69 } catch (GigiApiException e) {
70 assertThat(e.getMessage(), CoreMatchers.containsString("was wrong"));
75 public void testSingleInstance() throws GigiApiException {
76 String ref = type == CountryCodeType.CODE_2_CHARS ? "DE" : "DEU";
77 assertSame(Country.getCountryByCode(ref, type), Country.getCountryByCode(ref, type));
80 private Matcher<String> stringLength(final int len) {
81 return new BaseMatcher<String>() {
84 public boolean matches(Object s) {
85 if (s instanceof String) {
86 return ((String) s).length() == len;
92 public void describeTo(Description arg0) {
93 arg0.appendText("String of length " + len);