SwiftCodeService { public SwiftCountry loadCountry(String countryCode) throws IOException { URL resource = this.getClass().getClassLoader().getResource("swift" + File.separator + countryCode + ".csv"); if (resource != null) { SwiftCountry swiftCountry = new SwiftCountry(countryCode); try (BufferedReader in = new BufferedReader(new InputStreamReader(resource.openStream()))) { int lines = 0; String line = null; while ((line = in.readLine()) != null) { if (lines >= LINES_TO_IGNORE) { line = line.trim(); if (!line.isEmpty()) { String[] split = line.split(","); String code = split[0]; SwiftCode swiftCode = new SwiftCode(code); swiftCountry.add(swiftCode); } } lines++; } } return swiftCountry; } else { return null; } }  SwiftCountry loadCountry(String countryCode); SwiftCode getSwiftCode(String code); SwiftCountry getCountry(String countryCode);  }
@Test public void testLoadCountryCode() throws IOException { SwiftCountry swiftCountry = service.loadCountry("AD"); assertNotNull(swiftCountry); assertEquals("AD", swiftCountry.getCountryCode()); swiftCountry = service.loadCountry("AE"); assertNotNull(swiftCountry); assertEquals("AE", swiftCountry.getCountryCode()); swiftCountry = service.loadCountry("XX"); assertNull(swiftCountry); }
@Test public void testLoadCountryList() throws IOException { SwiftCountry swiftCountry = service.loadCountry("AD"); assertEquals("BACAADAD", swiftCountry.get("BACAADAD").getCode()); assertEquals("VALBADAD", swiftCountry.get("VALBADAD").getCode()); }