Skip to content

Commit

Permalink
IK.isValid() implementiert
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli B committed Jan 14, 2024
1 parent ce499e1 commit db806df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/main/kotlin/de/jfachwert/med/IK.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 by Oliver Boehm
* Copyright (c) 2018-2024 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,6 +58,16 @@ open class IK
*/
constructor(code: String) : this(code.toInt()) {}

/**
* Diese Methode liefert immer 'true' zurueck. Es sei denn, nan hat den
* Default-Validator beim Anlegen der IK deaktiviert.
*
* @return true oder false
*/
override fun isValid(): Boolean {
return VALIDATOR.isVald(code)
}

/**
* Die ersten beiden Ziffern bilden die Klassifikation, die hierueber
* zurueckgegeben werden kann.
Expand Down Expand Up @@ -115,8 +125,8 @@ open class IK
* Wenn der uebergebene Wert gueltig ist, soll er unveraendert
* zurueckgegeben werden, damit er anschliessend von der aufrufenden
* Methode weiterverarbeitet werden kann. Ist der Wert nicht gueltig,
* soll eine [ValidationException] geworfen
* werden.
* soll eine [de.jfachwert.pruefung.exception.ValidationException]
* geworfen werden.
*
* @param value Wert, der validiert werden soll
* @return Wert selber, wenn er gueltig ist
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/de/jfachwert/med/IKTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 by Oliver Boehm
* Copyright (c) 2018-2024 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@
package de.jfachwert.med;

import de.jfachwert.AbstractFachwertTest;
import de.jfachwert.pruefung.NullValidator;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -109,6 +110,12 @@ public void testGetPruefziffer() {
assertEquals(2, ik.getPruefziffer());
}

@Test
public void testInvalid() {
IK invalid = new IK(1234567897, new NullValidator<>());
assertFalse(invalid.isValid());
}

@Test
public void testIKs() throws IOException {
try (InputStream istream = IKTest.class.getResourceAsStream("/de/jfachwert/med/test-iks.txt")) {
Expand Down

0 comments on commit db806df

Please sign in to comment.