|
22 | 22 | import static org.mockito.Mockito.mock; |
23 | 23 | import static org.mockito.Mockito.when; |
24 | 24 |
|
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.Map; |
25 | 27 | import org.apache.fineract.infrastructure.accountnumberformat.domain.AccountNumberFormat; |
26 | 28 | import org.apache.fineract.infrastructure.codes.domain.CodeValue; |
27 | 29 | import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; |
@@ -142,4 +144,80 @@ public void testGenerateShareAccountNumber() { |
142 | 144 | String accountNumber = generator.generate(share, format); |
143 | 145 | assertThat(accountNumber).isEqualTo("000000321"); |
144 | 146 | } |
| 147 | + |
| 148 | + @Test |
| 149 | + public void testCheckAccountNumberConflict_nullEntityType_returnsFalse() { |
| 150 | + Map<String, String> props = new HashMap<>(); |
| 151 | + boolean result = generator.checkAccountNumberConflict(props, null, "12345"); |
| 152 | + assertThat(result).isFalse(); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testCheckAccountNumberConflict_clientNoConflict() { |
| 157 | + Map<String, String> props = new HashMap<>(); |
| 158 | + props.put("entityType", "client"); |
| 159 | + when(clientRepo.getClientByAccountNumber("12345")).thenReturn(null); |
| 160 | + |
| 161 | + boolean result = generator.checkAccountNumberConflict(props, null, "12345"); |
| 162 | + assertThat(result).isFalse(); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void testCheckAccountNumberConflict_clientWithConflict() { |
| 167 | + Map<String, String> props = new HashMap<>(); |
| 168 | + props.put("entityType", "client"); |
| 169 | + when(clientRepo.getClientByAccountNumber("12345")).thenReturn(mock(Client.class)); |
| 170 | + |
| 171 | + boolean result = generator.checkAccountNumberConflict(props, null, "12345"); |
| 172 | + assertThat(result).isTrue(); |
| 173 | + } |
| 174 | + |
| 175 | + @Test |
| 176 | + public void testCheckAccountNumberConflict_loanNoConflict() { |
| 177 | + Map<String, String> props = new HashMap<>(); |
| 178 | + props.put("entityType", "loan"); |
| 179 | + when(loanRepo.findLoanAccountByAccountNumber("77777")).thenReturn(null); |
| 180 | + |
| 181 | + boolean result = generator.checkAccountNumberConflict(props, null, "77777"); |
| 182 | + assertThat(result).isFalse(); |
| 183 | + } |
| 184 | + |
| 185 | + @Test |
| 186 | + public void testCheckAccountNumberConflict_loanWithConflict() { |
| 187 | + Map<String, String> props = new HashMap<>(); |
| 188 | + props.put("entityType", "loan"); |
| 189 | + when(loanRepo.findLoanAccountByAccountNumber("77777")).thenReturn(mock(Loan.class)); |
| 190 | + |
| 191 | + boolean result = generator.checkAccountNumberConflict(props, null, "77777"); |
| 192 | + assertThat(result).isTrue(); |
| 193 | + } |
| 194 | + |
| 195 | + @Test |
| 196 | + public void testCheckAccountNumberConflict_savingsNoConflict() { |
| 197 | + Map<String, String> props = new HashMap<>(); |
| 198 | + props.put("entityType", "savingsAccount"); |
| 199 | + when(savingsRepo.findSavingsAccountByAccountNumber("55555")).thenReturn(null); |
| 200 | + |
| 201 | + boolean result = generator.checkAccountNumberConflict(props, null, "55555"); |
| 202 | + assertThat(result).isFalse(); |
| 203 | + } |
| 204 | + |
| 205 | + @Test |
| 206 | + public void testCheckAccountNumberConflict_savingsWithConflict() { |
| 207 | + Map<String, String> props = new HashMap<>(); |
| 208 | + props.put("entityType", "savingsAccount"); |
| 209 | + when(savingsRepo.findSavingsAccountByAccountNumber("55555")).thenReturn(mock(SavingsAccount.class)); |
| 210 | + |
| 211 | + boolean result = generator.checkAccountNumberConflict(props, null, "55555"); |
| 212 | + assertThat(result).isTrue(); |
| 213 | + } |
| 214 | + |
| 215 | + @Test |
| 216 | + public void testCheckAccountNumberConflict_unknownEntityType_returnsFalse() { |
| 217 | + Map<String, String> props = new HashMap<>(); |
| 218 | + props.put("entityType", "foobar"); |
| 219 | + |
| 220 | + boolean result = generator.checkAccountNumberConflict(props, null, "12345"); |
| 221 | + assertThat(result).isFalse(); |
| 222 | + } |
145 | 223 | } |
0 commit comments