Permalink
Browse files

Lad AutorisationParser kaste ParserException i stedet for tilfældig S…

…tringTokenizer-fejl, når parse fejler: Så kan test gøres mere robust end expected=Exception.class
  • Loading branch information...
1 parent dde83b1 commit 3e25bfc0a5ad50d250655f40a0c6f7925ea76a4e @jrftrifork jrftrifork committed Sep 12, 2012
@@ -119,17 +119,21 @@ public Autorisationsregisterudtraek parse(File file, DateTime validFrom) throws
while (lineIterator.hasNext()) {
String line = lineIterator.nextLine();
- StringTokenizer st = new StringTokenizer(line, ";");
+ Autorisation autorisation = new Autorisation();
- Autorisation autorisation = new Autorisation();
+ try {
+ StringTokenizer st = new StringTokenizer(line, ";");
- autorisation.setAutorisationnummer(st.nextToken());
- autorisation.setCpr(st.nextToken());
- autorisation.setEfternavn(st.nextToken());
- autorisation.setFornavn(st.nextToken());
- autorisation.setUddannelsesKode(st.nextToken());
+ autorisation.setAutorisationnummer(st.nextToken());
+ autorisation.setCpr(st.nextToken());
+ autorisation.setEfternavn(st.nextToken());
+ autorisation.setFornavn(st.nextToken());
+ autorisation.setUddannelsesKode(st.nextToken());
+ } catch (RuntimeException e) {
+ throw new ParserException("Unable to parse line " + line, e);
+ }
- autorisation.setValidFrom(validFrom.toDate());
+ autorisation.setValidFrom(validFrom.toDate());
autorisation.setValidTo(Dates.THE_END_OF_TIME);
dataset.add(autorisation);
@@ -27,6 +27,7 @@
import dk.nsi.sdm4.autorisation.config.AutorisationApplicationConfig;
import dk.nsi.sdm4.autorisation.model.Autorisation;
+import dk.nsi.sdm4.core.parser.ParserException;
import dk.nsi.sdm4.testutils.TestDbConfiguration;
import org.apache.commons.io.FileUtils;
import org.joda.time.DateTime;
@@ -70,7 +71,7 @@ public void testParse() throws IOException {
assertEquals("Tage Søgaard", a.getFornavn());
}
- @Test(expected = Exception.class)
+ @Test(expected = ParserException.class)
public void testInvalid() throws IOException {
new AutorisationParser().parse(invalid, new DateTime());
}

0 comments on commit 3e25bfc

Please sign in to comment.