View Javadoc
1   /*
2    * Copyright (C) 2020-2023 Dipl.-Inform. Kai Hofmann. All rights reserved!
3    */
4   package de.powerstat.validation.values.impl.test;
5   
6   
7   import static org.junit.jupiter.api.Assertions.assertFalse;
8   import static org.junit.jupiter.api.Assertions.assertThrows;
9   
10  import org.junit.jupiter.api.Test;
11  
12  import de.powerstat.validation.values.impl.IBANVerifier;
13  
14  
15  /**
16   * IBAN verifier tests.
17   */
18  final class IBANVerifierTests
19   {
20    /**
21     * Illegal argument exception expected constant.
22     */
23    private static final String ILLEGAL_ARGUMENT_EXCEPTION = "Illegal argument exception expected"; //$NON-NLS-1$
24  
25    /**
26     * German IBAN regexp.
27     */
28    private static final String IBAN_DE_REGEXP = "^DE[0-9]{2}[0-9]{18}$"; //$NON-NLS-1$
29  
30  
31    /**
32     * Default Constructor.
33     */
34    /* default */ IBANVerifierTests()
35     {
36      super();
37     }
38  
39  
40    /**
41     * Test constructor with illegal length.
42     */
43    @Test
44    /* default */ void testConstructor1()
45     {
46      assertThrows(IllegalArgumentException.class, () ->
47       {
48        IBANVerifier.of(14, IBANVerifierTests.IBAN_DE_REGEXP);
49       }, IBANVerifierTests.ILLEGAL_ARGUMENT_EXCEPTION
50      );
51     }
52  
53  
54    /**
55     * Test constructor with illegal regexp.
56     */
57    @Test
58    /* default */ void testConstructor2()
59     {
60      assertThrows(IllegalArgumentException.class, () ->
61       {
62        IBANVerifier.of(15, "DE[0-9]{2}[0-9]{18}"); //$NON-NLS-1$
63       }, IBANVerifierTests.ILLEGAL_ARGUMENT_EXCEPTION
64      );
65     }
66  
67  
68    /**
69     * Test constructor with illegal length.
70     */
71    @Test
72    /* default */ void testConstructor3()
73     {
74      assertThrows(IllegalArgumentException.class, () ->
75       {
76        IBANVerifier.of(35, IBANVerifierTests.IBAN_DE_REGEXP);
77       }, IBANVerifierTests.ILLEGAL_ARGUMENT_EXCEPTION
78      );
79     }
80  
81  
82    /**
83     * Test constructor with illegal regexp.
84     */
85    @Test
86    /* default */ void testConstructor4()
87     {
88      assertThrows(IllegalArgumentException.class, () ->
89       {
90        IBANVerifier.of(15, "^DE[0-9]{2}[0-9]{18}"); //$NON-NLS-1$
91       }, IBANVerifierTests.ILLEGAL_ARGUMENT_EXCEPTION
92      );
93     }
94  
95  
96    /**
97     * Testverify.
98     */
99    @Test
100   /* default */ void testVerify1()
101    {
102     final IBANVerifier iv = IBANVerifier.of(21, IBANVerifierTests.IBAN_DE_REGEXP);
103     final boolean result = iv.verify("DE68210501700012345678"); //$NON-NLS-1$
104     assertFalse(result, "result not as expected"); //$NON-NLS-1$
105    }
106 
107  }