diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt index a17262b2..38397a59 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/banks/BankFinder.kt @@ -29,14 +29,29 @@ open class BankFinder { } val queryLowerCase = query.toLowerCase() + val queryPartsLowerCase = queryLowerCase.split(" ") - return getBankList().filter { - it.name.toLowerCase().contains(queryLowerCase) - || it.bankCode.startsWith(query) - || it.city.toLowerCase().contains(queryLowerCase) + return getBankList().filter { bankInfo -> + checkIfAllQueryPartsMatchBank(queryPartsLowerCase, bankInfo) } } + protected open fun checkIfAllQueryPartsMatchBank(queryPartsLowerCase: List, bankInfo: BankInfo): Boolean { + for (queryPartLowerCase in queryPartsLowerCase) { + if (checkIfQueryMatchesBank(bankInfo, queryPartLowerCase) == false) { + return false + } + } + + return true + } + + protected open fun checkIfQueryMatchesBank(bankInfo: BankInfo, queryLowerCase: String): Boolean { + return bankInfo.name.toLowerCase().contains(queryLowerCase) + || bankInfo.bankCode.startsWith(queryLowerCase) + || bankInfo.city.toLowerCase().contains(queryLowerCase) + } + open fun getBankList(): List { bankListField?.let { diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/banks/BankFinderTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/banks/BankFinderTest.kt index 56b49879..d87bb669 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/banks/BankFinderTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/banks/BankFinderTest.kt @@ -19,8 +19,9 @@ class BankFinderTest { assertThat(result[0].name).isEqualTo("Bundesbank") } + @Test - fun findBankByNameBankCodeOrCity_starnberg() { + fun findBankByNameBankCodeOrCity_Starnberg_MultipleResults() { // when val result = underTest.findBankByNameBankCodeOrCity("starnberg") @@ -30,14 +31,39 @@ class BankFinderTest { } @Test - fun findBankByNameBankCodeOrCity_mizUh() { + fun findBankByNameBankCodeOrCity_mizUh_SingleResult() { // when val result = underTest.findBankByNameBankCodeOrCity("mizUh") // then assertThat(result).hasSize(1) - assertThat(result[0].name).isEqualTo("Mizuho Bank Filiale Düsseldorf") + + assertThat(result.first().name).isEqualTo("Mizuho Bank Filiale Düsseldorf") + } + + @Test + fun findBankByNameBankCodeOrCity_MultiPartsQuery_BerlinSparkas() { + + // when + val result = underTest.findBankByNameBankCodeOrCity("Berlin Sparkas") + + // then + assertThat(result).hasSize(3) + + assertThat(result.first().name).isEqualTo("Landesbank Berlin - Berliner Sparkasse") + } + + @Test + fun findBankByNameBankCodeOrCity_MultiPartsQuery_SparkasBerlin() { + + // when + val result = underTest.findBankByNameBankCodeOrCity("Sparkas Berlin") + + // then + assertThat(result).hasSize(3) + + assertThat(result.first().name).isEqualTo("Landesbank Berlin - Berliner Sparkasse") } } \ No newline at end of file