Skip to content

Commit

Permalink
Lad AutorisationParser kaste ParserException i stedet for tilfældig S…
Browse files Browse the repository at this point in the history
…tringTokenizer-fejl, når parse fejler: Så kan test gøres mere robust end expected=Exception.class
  • Loading branch information
jrftrifork committed Sep 12, 2012
1 parent dde83b1 commit 3e25bfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 3e25bfc

Please sign in to comment.