diff --git a/build.gradle b/build.gradle index 9c6b5266..aa2478e1 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,7 @@ dependencies { testCompile 'org.jmockit:jmockit:1.30' testCompile 'org.springframework:spring-test:4.3.6.RELEASE' testCompile 'com.natpryce:make-it-easy:4.0.1' + testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3' testCompileOnly 'org.projectlombok:lombok:1.16.16' testAnnotationProcessor 'org.projectlombok:lombok:1.16.16' } diff --git a/src/main/java/bisq/core/arbitration/ArbitratorManager.java b/src/main/java/bisq/core/arbitration/ArbitratorManager.java index a4ffd4f6..aed4ffbd 100644 --- a/src/main/java/bisq/core/arbitration/ArbitratorManager.java +++ b/src/main/java/bisq/core/arbitration/ArbitratorManager.java @@ -322,6 +322,18 @@ public boolean isPublicKeyInList(String pubKeyAsHex) { return publicKeys.contains(pubKeyAsHex); } + public boolean isArbitratorAvailableForLanguage(String languageCode) { + return arbitratorsObservableMap.values().stream().anyMatch(arbitrator -> + arbitrator.getLanguageCodes().stream().anyMatch(lc -> lc.equals(languageCode))); + } + + public List getArbitratorLanguages(List nodeAddresses) { + return arbitratorsObservableMap.values().stream() + .filter(arbitrator -> nodeAddresses.stream().anyMatch(nodeAddress -> nodeAddress.equals(arbitrator.getNodeAddress()))) + .flatMap(arbitrator -> arbitrator.getLanguageCodes().stream()) + .distinct() + .collect(Collectors.toList()); + } /////////////////////////////////////////////////////////////////////////////////////////// // Private diff --git a/src/main/resources/i18n/displayStrings.properties b/src/main/resources/i18n/displayStrings.properties index 71e23b1a..c9cc982a 100644 --- a/src/main/resources/i18n/displayStrings.properties +++ b/src/main/resources/i18n/displayStrings.properties @@ -352,6 +352,7 @@ offerbook.info.sellAboveMarketPrice=You will get {0} more than the current marke offerbook.info.buyBelowMarketPrice=You will pay {0} less than the current market price (updated every minute). offerbook.info.buyAtFixedPrice=You will buy at this fixed price. offerbook.info.sellAtFixedPrice=You will sell at this fixed price. +offerbook.info.noArbitrationInUserLanguage=In case of a dispute, please note that arbitration for this offer will be handled in {0}. Language is currently set to {1}. #################################################################### # Offerbook / Create offer @@ -852,6 +853,7 @@ setting.preferences.sortWithNumOffers=Sort market lists with no. of offers/trade setting.preferences.resetAllFlags=Reset all \"Don't show again\" flags: setting.preferences.reset=Reset settings.preferences.languageChange=To apply the language change to all screens requires a restart. +settings.preferences.arbitrationLanguageWarning=In case of a dispute, please note that arbitration is handled in {0}. settings.preferences.selectCurrencyNetwork=Select base currency settings.net.btcHeader=Bitcoin network diff --git a/src/test/java/bisq/core/arbitration/ArbitratorManagerTest.java b/src/test/java/bisq/core/arbitration/ArbitratorManagerTest.java new file mode 100644 index 00000000..7f91c723 --- /dev/null +++ b/src/test/java/bisq/core/arbitration/ArbitratorManagerTest.java @@ -0,0 +1,122 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.arbitration; + +import bisq.core.user.User; + +import bisq.network.p2p.NodeAddress; + +import org.bouncycastle.jce.provider.BouncyCastleProvider; + +import java.security.Security; + +import java.util.ArrayList; + +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.contains; +import static org.mockito.Mockito.mock; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({User.class, ArbitratorService.class}) +public class ArbitratorManagerTest { + + @Before + public void setUp() { + Security.addProvider(new BouncyCastleProvider()); + } + + @Test + public void testIsArbitratorAvailableForLanguage() { + User user = mock(User.class); + ArbitratorService arbitratorService = mock(ArbitratorService.class); + + ArbitratorManager manager = new ArbitratorManager(null, arbitratorService, user, null, null, false); + + ArrayList languagesOne = new ArrayList() {{ + add("en"); + add("de"); + }}; + + ArrayList languagesTwo = new ArrayList() {{ + add("en"); + add("es"); + }}; + + Arbitrator one = new Arbitrator(new NodeAddress("arbitrator:1"), null, null, null, + languagesOne, 0L, null, "", null, + null, null); + + Arbitrator two = new Arbitrator(new NodeAddress("arbitrator:2"), null, null, null, + languagesTwo, 0L, null, "", null, + null, null); + + manager.addArbitrator(one, () -> {}, errorMessage -> {}); + manager.addArbitrator(two, () -> {}, errorMessage -> {}); + + assertTrue(manager.isArbitratorAvailableForLanguage("en")); + assertFalse(manager.isArbitratorAvailableForLanguage("th")); + } + + @Test + public void testGetArbitratorLanguages() { + User user = mock(User.class); + ArbitratorService arbitratorService = mock(ArbitratorService.class); + + ArbitratorManager manager = new ArbitratorManager(null, arbitratorService, user, null, null, false); + + ArrayList languagesOne = new ArrayList() {{ + add("en"); + add("de"); + }}; + + ArrayList languagesTwo = new ArrayList() {{ + add("en"); + add("es"); + }}; + + Arbitrator one = new Arbitrator(new NodeAddress("arbitrator:1"), null, null, null, + languagesOne, 0L, null, "", null, + null, null); + + Arbitrator two = new Arbitrator(new NodeAddress("arbitrator:2"), null, null, null, + languagesTwo, 0L, null, "", null, + null, null); + + ArrayList nodeAddresses = new ArrayList() {{ + add(two.getNodeAddress()); + }}; + + manager.addArbitrator(one, () -> {}, errorMessage -> {}); + manager.addArbitrator(two, () -> {}, errorMessage -> {}); + + assertThat(manager.getArbitratorLanguages(nodeAddresses), containsInAnyOrder("en", "es")); + assertThat(manager.getArbitratorLanguages(nodeAddresses), not(containsInAnyOrder("de"))); + } + +}