moving away from JUnit 4 completely to JUnit 5 Jupiter

This commit is contained in:
napoly 2023-03-25 18:11:58 +01:00 committed by woodser
parent a052fd7767
commit 65bc78d3d7
114 changed files with 1352 additions and 1338 deletions

View file

@ -1,57 +0,0 @@
package haveno.apitest;
import lombok.extern.slf4j.Slf4j;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import static java.lang.String.format;
@Slf4j
public class JUnitHelper {
private static boolean allPass;
public static void runTests(Class<?>... testClasses) {
JUnitCore jUnitCore = new JUnitCore();
jUnitCore.addListener(new RunListener() {
public void testStarted(Description description) {
log.info("{}", description);
}
public void testIgnored(Description description) {
log.info("Ignored {}", description);
}
public void testFailure(Failure failure) {
log.error("Failed {}", failure.getTrace());
}
});
Result result = jUnitCore.run(testClasses);
printTestResults(result);
}
public static boolean allTestsPassed() {
return allPass;
}
private static void printTestResults(Result result) {
log.info("Total tests: {}, Failed: {}, Ignored: {}",
result.getRunCount(),
result.getFailureCount(),
result.getIgnoreCount());
if (result.wasSuccessful()) {
log.info("All {} tests passed", result.getRunCount());
allPass = true;
} else if (result.getFailureCount() > 0) {
log.error("{} test(s) failed", result.getFailureCount());
result.getFailures().iterator().forEachRemaining(f -> log.error(format("%s.%s()%n\t%s",
f.getDescription().getTestClass().getName(),
f.getDescription().getMethodName(),
f.getTrace())));
}
}
}

View file

@ -17,10 +17,10 @@
package haveno.asset; package haveno.asset;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
/** /**
* Abstract base class for all {@link Asset} unit tests. Subclasses must implement the * Abstract base class for all {@link Asset} unit tests. Subclasses must implement the

View file

@ -18,7 +18,7 @@
package haveno.asset.coins; package haveno.asset.coins;
import haveno.asset.AbstractAssetTest; import haveno.asset.AbstractAssetTest;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class BitcoinCashTest extends AbstractAssetTest { public class BitcoinCashTest extends AbstractAssetTest {

View file

@ -18,7 +18,7 @@
package haveno.asset.coins; package haveno.asset.coins;
import haveno.asset.AbstractAssetTest; import haveno.asset.AbstractAssetTest;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class BitcoinTest extends AbstractAssetTest { public class BitcoinTest extends AbstractAssetTest {

View file

@ -18,7 +18,7 @@
package haveno.asset.coins; package haveno.asset.coins;
import haveno.asset.AbstractAssetTest; import haveno.asset.AbstractAssetTest;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class LitecoinTest extends AbstractAssetTest { public class LitecoinTest extends AbstractAssetTest {

View file

@ -18,7 +18,7 @@
package haveno.asset.coins; package haveno.asset.coins;
import haveno.asset.AbstractAssetTest; import haveno.asset.AbstractAssetTest;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class MoneroTest extends AbstractAssetTest { public class MoneroTest extends AbstractAssetTest {

View file

@ -50,7 +50,7 @@ configure(subprojects) {
guiceVersion = '4.2.2' guiceVersion = '4.2.2'
moneroJavaVersion = '0.7.15' moneroJavaVersion = '0.7.15'
httpclient5Version = '5.0' httpclient5Version = '5.0'
hamcrestVersion = '1.3' hamcrestVersion = '2.2'
httpclientVersion = '4.5.12' httpclientVersion = '4.5.12'
httpcoreVersion = '4.4.13' httpcoreVersion = '4.4.13'
ioVersion = '2.6' ioVersion = '2.6'
@ -63,8 +63,7 @@ configure(subprojects) {
joptVersion = '5.0.4' joptVersion = '5.0.4'
jsonsimpleVersion = '1.1.1' jsonsimpleVersion = '1.1.1'
jsonrpc4jVersion = '1.6.0.bisq.1' jsonrpc4jVersion = '1.6.0.bisq.1'
junitVersion = '4.12' jupiterVersion = '5.9.2'
jupiterVersion = '5.7.0'
kotlinVersion = '1.3.41' kotlinVersion = '1.3.41'
langVersion = '3.11' langVersion = '3.11'
logbackVersion = '1.1.11' logbackVersion = '1.1.11'
@ -89,10 +88,6 @@ configure(subprojects) {
maven { url 'https://mvnrepository.com' } maven { url 'https://mvnrepository.com' }
} }
dependencies {
testImplementation "junit:junit:$junitVersion"
}
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
} }
@ -250,6 +245,9 @@ configure(project(':assets')) {
implementation "com.google.guava:guava:$guavaVersion" implementation "com.google.guava:guava:$guavaVersion"
implementation "org.apache.commons:commons-lang3:$langVersion" implementation "org.apache.commons:commons-lang3:$langVersion"
implementation "org.slf4j:slf4j-api:$slf4jVersion" implementation "org.slf4j:slf4j-api:$slf4jVersion"
testImplementation "org.hamcrest:hamcrest:$hamcrestVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
} }
} }
@ -285,7 +283,9 @@ configure(project(':common')) {
implementation "org.bouncycastle:bcpg-jdk15on:$bcVersion" implementation "org.bouncycastle:bcpg-jdk15on:$bcVersion"
implementation "org.jetbrains:annotations:$jetbrainsAnnotationsVersion" implementation "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
implementation "org.slf4j:slf4j-api:$slf4jVersion" implementation "org.slf4j:slf4j-api:$slf4jVersion"
testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion" testImplementation "org.hamcrest:hamcrest:$hamcrestVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion") { runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion") {
exclude(module: 'guava') exclude(module: 'guava')
exclude(module: 'animal-sniffer-annotations') exclude(module: 'animal-sniffer-annotations')
@ -332,6 +332,9 @@ configure(project(':p2p')) {
} }
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion" testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompileOnly "org.projectlombok:lombok:$lombokVersion" testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
testImplementation "ch.qos.logback:logback-classic:$logbackVersion" testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
testImplementation "ch.qos.logback:logback-core:$logbackVersion" testImplementation "ch.qos.logback:logback-core:$logbackVersion"
testImplementation "org.apache.commons:commons-lang3:$langVersion" testImplementation "org.apache.commons:commons-lang3:$langVersion"
@ -398,7 +401,9 @@ configure(project(':core')) {
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion" testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompileOnly "org.projectlombok:lombok:$lombokVersion" testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testImplementation "com.natpryce:make-it-easy:$easyVersion" testImplementation "com.natpryce:make-it-easy:$easyVersion"
testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion" testImplementation "org.hamcrest:hamcrest:$hamcrestVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
testImplementation "org.mockito:mockito-core:$mockitoVersion" testImplementation "org.mockito:mockito-core:$mockitoVersion"
implementation "org.openjfx:javafx-base:$javafxVersion:$os" implementation "org.openjfx:javafx-base:$javafxVersion:$os"
@ -556,7 +561,7 @@ configure(project(':cli')) {
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion"
testRuntimeOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion" testRuntimeOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
} }
test { test {
@ -624,6 +629,9 @@ configure(project(':desktop')) {
testCompileOnly "org.projectlombok:lombok:$lombokVersion" testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testImplementation "com.natpryce:make-it-easy:$easyVersion" testImplementation "com.natpryce:make-it-easy:$easyVersion"
testImplementation "org.mockito:mockito-core:$mockitoVersion" testImplementation "org.mockito:mockito-core:$mockitoVersion"
testImplementation "org.hamcrest:hamcrest:$hamcrestVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
implementation("io.github.monero-ecosystem:monero-java:$moneroJavaVersion") { implementation("io.github.monero-ecosystem:monero-java:$moneroJavaVersion") {
exclude(module: 'jackson-core') exclude(module: 'jackson-core')
@ -679,7 +687,7 @@ configure(project(':monitor')) {
testCompileOnly "org.projectlombok:lombok:$lombokVersion" testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion"
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
implementation "org.openjfx:javafx-base:$javafxVersion:$os" implementation "org.openjfx:javafx-base:$javafxVersion:$os"
implementation "org.openjfx:javafx-graphics:$javafxVersion:$os" implementation "org.openjfx:javafx-graphics:$javafxVersion:$os"
@ -725,6 +733,8 @@ configure(project(':seednode')) {
exclude(module: 'guava') exclude(module: 'guava')
} }
testImplementation "org.mockito:mockito-core:$mockitoVersion" testImplementation "org.mockito:mockito-core:$mockitoVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
} }
} }
@ -908,7 +918,7 @@ configure(project(':apitest')) {
testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion" testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion"
testRuntimeOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion" testRuntimeOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jupiterVersion"
} }
} }

View file

@ -17,7 +17,7 @@
package haveno.common.app; package haveno.common.app;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -26,9 +26,9 @@ import java.util.HashSet;
import static haveno.common.app.Capability.SEED_NODE; import static haveno.common.app.Capability.SEED_NODE;
import static haveno.common.app.Capability.TRADE_STATISTICS; import static haveno.common.app.Capability.TRADE_STATISTICS;
import static haveno.common.app.Capability.TRADE_STATISTICS_2; import static haveno.common.app.Capability.TRADE_STATISTICS_2;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class CapabilitiesTest { public class CapabilitiesTest {

View file

@ -17,11 +17,11 @@
package haveno.common.app; package haveno.common.app;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class VersionTest { public class VersionTest {

View file

@ -1,16 +1,16 @@
package haveno.common.config; package haveno.common.config;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
public class ConfigFileEditorTests { public class ConfigFileEditorTests {
@ -19,7 +19,7 @@ public class ConfigFileEditorTests {
private ConfigFileReader reader; private ConfigFileReader reader;
private ConfigFileEditor editor; private ConfigFileEditor editor;
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
file = File.createTempFile("haveno", "properties"); file = File.createTempFile("haveno", "properties");
reader = new ConfigFileReader(file); reader = new ConfigFileReader(file);

View file

@ -1,6 +1,6 @@
package haveno.common.config; package haveno.common.config;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;

View file

@ -1,18 +1,16 @@
package haveno.common.config; package haveno.common.config;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
public class ConfigFileReaderTests { public class ConfigFileReaderTests {
@ -20,10 +18,7 @@ public class ConfigFileReaderTests {
private PrintWriter writer; private PrintWriter writer;
private ConfigFileReader reader; private ConfigFileReader reader;
@Rule @BeforeEach
public ExpectedException exception = ExpectedException.none();
@Before
public void setUp() throws IOException { public void setUp() throws IOException {
file = File.createTempFile("haveno", "properties"); file = File.createTempFile("haveno", "properties");
reader = new ConfigFileReader(file); reader = new ConfigFileReader(file);
@ -35,11 +30,12 @@ public class ConfigFileReaderTests {
writer.close(); writer.close();
assertTrue(file.delete()); assertTrue(file.delete());
exception.expect(ConfigException.class); Exception exception = assertThrows(ConfigException.class, () -> reader.getLines());
exception.expectMessage(containsString("Config file"));
exception.expectMessage(containsString("does not exist"));
reader.getLines(); String expectedMessage = "does not exist";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
} }
@Test @Test

View file

@ -1,8 +1,6 @@
package haveno.common.config; package haveno.common.config;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -21,21 +19,22 @@ import static haveno.common.config.Config.DEFAULT_CONFIG_FILE_NAME;
import static haveno.common.config.Config.HELP; import static haveno.common.config.Config.HELP;
import static haveno.common.config.Config.TORRC_FILE; import static haveno.common.config.Config.TORRC_FILE;
import static haveno.common.config.Config.USER_DATA_DIR; import static haveno.common.config.Config.USER_DATA_DIR;
import static java.io.File.createTempFile;
import static java.lang.String.format; import static java.lang.String.format;
import static org.hamcrest.CoreMatchers.containsString; import static java.lang.System.getProperty;
import static java.nio.file.Files.createTempDirectory;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.isEmptyString; import static org.hamcrest.Matchers.emptyString;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class ConfigTests { public class ConfigTests {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
// Note: "DataDirProperties" in the test method names below represent the group of // Note: "DataDirProperties" in the test method names below represent the group of
// configuration options that influence the location of a Haveno node's data directory. // configuration options that influence the location of a Haveno node's data directory.
// These options include appName, userDataDir, appDataDir and configFile // These options include appName, userDataDir, appDataDir and configFile
@ -45,8 +44,8 @@ public class ConfigTests {
Config config = new Config(); Config config = new Config();
String defaultAppName = config.defaultAppName; String defaultAppName = config.defaultAppName;
String regex = "Haveno\\d{2,}Temp"; String regex = "Haveno\\d{2,}Temp";
assertTrue(format("Temp app name '%s' failed to match '%s'", defaultAppName, regex), assertTrue(defaultAppName.matches(regex),
defaultAppName.matches(regex)); format("Temp app name '%s' failed to match '%s'", defaultAppName, regex));
} }
@Test @Test
@ -76,7 +75,7 @@ public class ConfigTests {
@Test @Test
public void whenAppDataDirOptionIsSet_thenDataDirPropertiesReflectItsValue() throws IOException { public void whenAppDataDirOptionIsSet_thenDataDirPropertiesReflectItsValue() throws IOException {
File appDataDir = Files.createTempDirectory("myapp").toFile(); File appDataDir = createTempDirectory("myapp").toFile();
Config config = configWithOpts(opt(APP_DATA_DIR, appDataDir)); Config config = configWithOpts(opt(APP_DATA_DIR, appDataDir));
assertThat(config.appName, equalTo(config.defaultAppName)); assertThat(config.appName, equalTo(config.defaultAppName));
assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); assertThat(config.userDataDir, equalTo(config.defaultUserDataDir));
@ -86,7 +85,7 @@ public class ConfigTests {
@Test @Test
public void whenUserDataDirOptionIsSet_thenDataDirPropertiesReflectItsValue() throws IOException { public void whenUserDataDirOptionIsSet_thenDataDirPropertiesReflectItsValue() throws IOException {
File userDataDir = Files.createTempDirectory("myuserdata").toFile(); File userDataDir = createTempDirectory("myuserdata").toFile();
Config config = configWithOpts(opt(USER_DATA_DIR, userDataDir)); Config config = configWithOpts(opt(USER_DATA_DIR, userDataDir));
assertThat(config.appName, equalTo(config.defaultAppName)); assertThat(config.appName, equalTo(config.defaultAppName));
assertThat(config.userDataDir, equalTo(userDataDir)); assertThat(config.userDataDir, equalTo(userDataDir));
@ -96,7 +95,7 @@ public class ConfigTests {
@Test @Test
public void whenAppNameAndAppDataDirOptionsAreSet_thenDataDirPropertiesReflectTheirValues() throws IOException { public void whenAppNameAndAppDataDirOptionsAreSet_thenDataDirPropertiesReflectTheirValues() throws IOException {
File appDataDir = Files.createTempDirectory("myapp").toFile(); File appDataDir = createTempDirectory("myapp").toFile();
Config config = configWithOpts(opt(APP_NAME, "My-Haveno"), opt(APP_DATA_DIR, appDataDir)); Config config = configWithOpts(opt(APP_NAME, "My-Haveno"), opt(APP_DATA_DIR, appDataDir));
assertThat(config.appName, equalTo("My-Haveno")); assertThat(config.appName, equalTo("My-Haveno"));
assertThat(config.userDataDir, equalTo(config.defaultUserDataDir)); assertThat(config.userDataDir, equalTo(config.defaultUserDataDir));
@ -106,7 +105,7 @@ public class ConfigTests {
@Test @Test
public void whenOptionIsSetAtCommandLineAndInConfigFile_thenCommandLineValueTakesPrecedence() throws IOException { public void whenOptionIsSetAtCommandLineAndInConfigFile_thenCommandLineValueTakesPrecedence() throws IOException {
File configFile = File.createTempFile("haveno", "properties"); File configFile = createTempFile("haveno", "properties");
try (PrintWriter writer = new PrintWriter(configFile)) { try (PrintWriter writer = new PrintWriter(configFile)) {
writer.println(new ConfigFileOption(APP_NAME, "Haveno-configFileValue")); writer.println(new ConfigFileOption(APP_NAME, "Haveno-configFileValue"));
} }
@ -116,14 +115,17 @@ public class ConfigTests {
@Test @Test
public void whenUnrecognizedOptionIsSet_thenConfigExceptionIsThrown() { public void whenUnrecognizedOptionIsSet_thenConfigExceptionIsThrown() {
exceptionRule.expect(ConfigException.class); Exception exception = assertThrows(ConfigException.class, () -> configWithOpts(opt("bogus")));
exceptionRule.expectMessage("problem parsing option 'bogus': bogus is not a recognized option");
configWithOpts(opt("bogus")); String expectedMessage = "problem parsing option 'bogus': bogus is not a recognized option";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
} }
@Test @Test
public void whenUnrecognizedOptionIsSetInConfigFile_thenNoExceptionIsThrown() throws IOException { public void whenUnrecognizedOptionIsSetInConfigFile_thenNoExceptionIsThrown() throws IOException {
File configFile = File.createTempFile("haveno", "properties"); File configFile = createTempFile("haveno", "properties");
try (PrintWriter writer = new PrintWriter(configFile)) { try (PrintWriter writer = new PrintWriter(configFile)) {
writer.println(new ConfigFileOption("bogusOption", "bogusValue")); writer.println(new ConfigFileOption("bogusOption", "bogusValue"));
writer.println(new ConfigFileOption(APP_NAME, "HavenoTest")); writer.println(new ConfigFileOption(APP_NAME, "HavenoTest"));
@ -134,40 +136,43 @@ public class ConfigTests {
@Test @Test
public void whenOptionFileArgumentDoesNotExist_thenConfigExceptionIsThrown() { public void whenOptionFileArgumentDoesNotExist_thenConfigExceptionIsThrown() {
String filepath = "/does/not/exist"; String filepath = getProperty("os.name").startsWith("Windows") ? "C:\\does\\not\\exist" : "/does/not/exist";
if (System.getProperty("os.name").startsWith("Windows")) { Exception exception = assertThrows(ConfigException.class, () -> configWithOpts(opt(TORRC_FILE, filepath)));
filepath = "C:\\does\\not\\exist";
} String expectedMessage = format("problem parsing option 'torrcFile': File [%s] does not exist", filepath);
exceptionRule.expect(ConfigException.class); String actualMessage = exception.getMessage();
exceptionRule.expectMessage(format("problem parsing option 'torrcFile': File [%s] does not exist", filepath));
configWithOpts(opt(TORRC_FILE, filepath)); assertTrue(actualMessage.contains(expectedMessage));
} }
@Test @Test
public void whenConfigFileOptionIsSetToNonExistentFile_thenConfigExceptionIsThrown() { public void whenConfigFileOptionIsSetToNonExistentFile_thenConfigExceptionIsThrown() {
String filepath = "/no/such/haveno.properties"; String filepath = getProperty("os.name").startsWith("Windows") ? "C:\\no\\such\\haveno.properties" : "/no/such/haveno.properties";
if (System.getProperty("os.name").startsWith("Windows")) { Exception exception = assertThrows(ConfigException.class, () -> configWithOpts(opt(CONFIG_FILE, filepath)));
filepath = "C:\\no\\such\\haveno.properties";
} String expectedMessage = format("The specified config file '%s' does not exist", filepath);
exceptionRule.expect(ConfigException.class); String actualMessage = exception.getMessage();
exceptionRule.expectMessage(format("The specified config file '%s' does not exist", filepath));
configWithOpts(opt(CONFIG_FILE, filepath)); assertTrue(actualMessage.contains(expectedMessage));
} }
@Test @Test
public void whenConfigFileOptionIsSetInConfigFile_thenConfigExceptionIsThrown() throws IOException { public void whenConfigFileOptionIsSetInConfigFile_thenConfigExceptionIsThrown() throws IOException {
File configFile = File.createTempFile("haveno", "properties"); File configFile = createTempFile("haveno", "properties");
try (PrintWriter writer = new PrintWriter(configFile)) { try (PrintWriter writer = new PrintWriter(configFile)) {
writer.println(new ConfigFileOption(CONFIG_FILE, "/tmp/other.haveno.properties")); writer.println(new ConfigFileOption(CONFIG_FILE, "/tmp/other.haveno.properties"));
} }
exceptionRule.expect(ConfigException.class); Exception exception = assertThrows(ConfigException.class, () -> configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath())));
exceptionRule.expectMessage(format("The '%s' option is disallowed in config files", CONFIG_FILE));
configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath())); String expectedMessage = format("The '%s' option is disallowed in config files", CONFIG_FILE);
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
} }
@Test @Test
public void whenConfigFileOptionIsSetToExistingFile_thenConfigFilePropertyReflectsItsValue() throws IOException { public void whenConfigFileOptionIsSetToExistingFile_thenConfigFilePropertyReflectsItsValue() throws IOException {
File configFile = File.createTempFile("haveno", "properties"); File configFile = createTempFile("haveno", "properties");
Config config = configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath())); Config config = configWithOpts(opt(CONFIG_FILE, configFile.getAbsolutePath()));
assertThat(config.configFile, equalTo(configFile)); assertThat(config.configFile, equalTo(configFile));
} }
@ -183,7 +188,7 @@ public class ConfigTests {
@Test @Test
public void whenAppNameIsSetInConfigFile_thenDataDirPropertiesReflectItsValue() throws IOException { public void whenAppNameIsSetInConfigFile_thenDataDirPropertiesReflectItsValue() throws IOException {
File configFile = File.createTempFile("haveno", "properties"); File configFile = createTempFile("haveno", "properties");
try (PrintWriter writer = new PrintWriter(configFile)) { try (PrintWriter writer = new PrintWriter(configFile)) {
writer.println(new ConfigFileOption(APP_NAME, "My-Haveno")); writer.println(new ConfigFileOption(APP_NAME, "My-Haveno"));
} }
@ -217,8 +222,8 @@ public class ConfigTests {
System.setOut(outTest); System.setOut(outTest);
System.setErr(errTest); System.setErr(errTest);
new Config(); new Config();
assertThat(outBytes.toString(), isEmptyString()); assertThat(outBytes.toString(), is(emptyString()));
assertThat(errBytes.toString(), isEmptyString()); assertThat(errBytes.toString(), is(emptyString()));
} finally { } finally {
System.setOut(outOrig); System.setOut(outOrig);
System.setErr(errOrig); System.setErr(errOrig);
@ -236,18 +241,22 @@ public class ConfigTests {
} }
@Test @Test
public void whenAppDataDirCannotBeCreated_thenUncheckedIoExceptionIsThrown() throws IOException { public void whenAppDataDirCannotBeCreatedThenUncheckedIoExceptionIsThrown() {
// set a userDataDir that is actually a file so appDataDir cannot be created // set a userDataDir that is actually a file so appDataDir cannot be created
File aFile = Files.createTempFile("A", "File").toFile(); Exception exception = assertThrows(UncheckedIOException.class, () -> {
exceptionRule.expect(UncheckedIOException.class); File aFile = Files.createTempFile("A", "File").toFile();
exceptionRule.expectMessage(containsString("Application data directory")); configWithOpts(opt(USER_DATA_DIR, aFile));
exceptionRule.expectMessage(containsString("could not be created")); });
configWithOpts(opt(USER_DATA_DIR, aFile));
String expectedMessage = "could not be created";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
} }
@Test @Test
public void whenAppDataDirIsSymbolicLink_thenAppDataDirCreationIsNoOp() throws IOException { public void whenAppDataDirIsSymbolicLink_thenAppDataDirCreationIsNoOp() throws IOException {
Path parentDir = Files.createTempDirectory("parent"); Path parentDir = createTempDirectory("parent");
Path targetDir = parentDir.resolve("target"); Path targetDir = parentDir.resolve("target");
Path symlink = parentDir.resolve("symlink"); Path symlink = parentDir.resolve("symlink");
Files.createDirectory(targetDir); Files.createDirectory(targetDir);

View file

@ -17,26 +17,27 @@
package haveno.common.util; package haveno.common.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MathUtilsTest { public class MathUtilsTest {
@Test(expected = IllegalArgumentException.class) @Test
public void testRoundDoubleWithInfiniteArg() { public void testRoundDoubleWithInfiniteArg() {
MathUtils.roundDouble(Double.POSITIVE_INFINITY, 2); assertThrows(IllegalArgumentException.class, () -> MathUtils.roundDouble(Double.POSITIVE_INFINITY, 2));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testRoundDoubleWithNaNArg() { public void testRoundDoubleWithNaNArg() {
MathUtils.roundDouble(Double.NaN, 2); assertThrows(IllegalArgumentException.class, () ->MathUtils.roundDouble(Double.NaN, 2));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testRoundDoubleWithNegativePrecision() { public void testRoundDoubleWithNegativePrecision() {
MathUtils.roundDouble(3, -1); assertThrows(IllegalArgumentException.class, () ->MathUtils.roundDouble(3, -1));
} }
@SuppressWarnings("OptionalGetWithoutIsPresent") @SuppressWarnings("OptionalGetWithoutIsPresent")

View file

@ -17,7 +17,7 @@
package haveno.common.util; package haveno.common.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -25,7 +25,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class PermutationTest { public class PermutationTest {

View file

@ -1,22 +1,20 @@
package haveno.common.util; package haveno.common.util;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import static haveno.common.util.Preconditions.checkDir; import static haveno.common.util.Preconditions.checkDir;
import static org.hamcrest.Matchers.equalTo; import static java.lang.String.format;
import static org.junit.Assert.assertSame; import static java.lang.System.getProperty;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class PreconditionsTests { public class PreconditionsTests {
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test @Test
public void whenDirIsValid_thenDirIsReturned() throws IOException { public void whenDirIsValid_thenDirIsReturned() throws IOException {
File dir = Files.createTempDirectory("TestDir").toFile(); File dir = Files.createTempDirectory("TestDir").toFile();
@ -26,12 +24,12 @@ public class PreconditionsTests {
@Test @Test
public void whenDirDoesNotExist_thenThrow() { public void whenDirDoesNotExist_thenThrow() {
String filepath = "/does/not/exist"; String filepath = getProperty("os.name").startsWith("Windows") ? "C:\\does\\not\\exist" : "/does/not/exist";
if (System.getProperty("os.name").startsWith("Windows")) { Exception exception = assertThrows(IllegalArgumentException.class, () -> checkDir(new File(filepath)));
filepath = "C:\\does\\not\\exist";
} String expectedMessage = format("Directory '%s' does not exist", filepath);
exceptionRule.expect(IllegalArgumentException.class); String actualMessage = exception.getMessage();
exceptionRule.expectMessage(equalTo(String.format("Directory '%s' does not exist", filepath)));
checkDir(new File(filepath)); assertTrue(actualMessage.contains(expectedMessage));
} }
} }

View file

@ -17,10 +17,10 @@
package haveno.common.util; package haveno.common.util;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class UtilitiesTest { public class UtilitiesTest {

View file

@ -30,8 +30,8 @@ import haveno.network.p2p.P2PService;
import haveno.network.p2p.storage.payload.PersistableNetworkPayload; import haveno.network.p2p.storage.payload.PersistableNetworkPayload;
import haveno.network.p2p.storage.persistence.AppendOnlyDataStoreService; import haveno.network.p2p.storage.persistence.AppendOnlyDataStoreService;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.KeyPair; import java.security.KeyPair;
@ -41,8 +41,8 @@ import java.util.Date;
import static haveno.core.account.sign.SignedWitness.VerificationMethod.ARBITRATOR; import static haveno.core.account.sign.SignedWitness.VerificationMethod.ARBITRATOR;
import static haveno.core.account.sign.SignedWitness.VerificationMethod.TRADE; import static haveno.core.account.sign.SignedWitness.VerificationMethod.TRADE;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -85,7 +85,7 @@ public class SignedWitnessServiceTest {
KeyPair peer2KeyPair; KeyPair peer2KeyPair;
KeyPair peer3KeyPair; KeyPair peer3KeyPair;
@Before @BeforeEach
public void setup() throws Exception { public void setup() throws Exception {
AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class); AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class);
ArbitratorManager arbitratorManager = mock(ArbitratorManager.class); ArbitratorManager arbitratorManager = mock(ArbitratorManager.class);

View file

@ -5,15 +5,15 @@ import haveno.common.crypto.Sig;
import haveno.common.util.Utilities; import haveno.common.util.Utilities;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Utils; import org.bitcoinj.core.Utils;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.time.Instant; import java.time.Instant;
import static haveno.core.account.sign.SignedWitness.VerificationMethod.ARBITRATOR; import static haveno.core.account.sign.SignedWitness.VerificationMethod.ARBITRATOR;
import static haveno.core.account.sign.SignedWitness.VerificationMethod.TRADE; import static haveno.core.account.sign.SignedWitness.VerificationMethod.TRADE;
import static org.junit.Assert.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class SignedWitnessTest { public class SignedWitnessTest {
@ -22,7 +22,7 @@ public class SignedWitnessTest {
private byte[] witnessHash; private byte[] witnessHash;
private byte[] witnessHashSignature; private byte[] witnessHashSignature;
@Before @BeforeEach
public void setUp() { public void setUp() {
arbitrator1Key = new ECKey(); arbitrator1Key = new ECKey();
witnessOwner1PubKey = Sig.getPublicKeyBytes(Sig.generateKeyPair().getPublic()); witnessOwner1PubKey = Sig.getPublicKeyBytes(Sig.generateKeyPair().getPublic());

View file

@ -43,10 +43,9 @@ import haveno.core.trade.HavenoUtils;
import haveno.network.p2p.P2PService; import haveno.network.p2p.P2PService;
import haveno.network.p2p.storage.persistence.AppendOnlyDataStoreService; import haveno.network.p2p.storage.persistence.AppendOnlyDataStoreService;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.junit.After; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Disabled;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -60,9 +59,9 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static haveno.core.payment.payload.PaymentMethod.getPaymentMethod; import static haveno.core.payment.payload.PaymentMethod.getPaymentMethod;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -82,7 +81,7 @@ public class AccountAgeWitnessServiceTest {
private File dir2; private File dir2;
private File dir3; private File dir3;
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
KeyRing keyRing = mock(KeyRing.class); KeyRing keyRing = mock(KeyRing.class);
setupService(keyRing); setupService(keyRing);
@ -113,12 +112,7 @@ public class AccountAgeWitnessServiceTest {
return dir; return dir;
} }
@After @Disabled
public void tearDown() {
// Do teardown stuff
}
@Ignore
@Test @Test
public void testIsTradeDateAfterReleaseDate() { public void testIsTradeDateAfterReleaseDate() {
Date ageWitnessReleaseDate = new GregorianCalendar(2017, Calendar.OCTOBER, 23).getTime(); Date ageWitnessReleaseDate = new GregorianCalendar(2017, Calendar.OCTOBER, 23).getTime();
@ -139,7 +133,7 @@ public class AccountAgeWitnessServiceTest {
})); }));
} }
@Ignore @Disabled
@Test @Test
public void testVerifySignatureOfNonce() throws CryptoException { public void testVerifySignatureOfNonce() throws CryptoException {
byte[] nonce = new byte[]{0x01}; byte[] nonce = new byte[]{0x01};

View file

@ -19,7 +19,7 @@ package haveno.core.app;
import haveno.common.config.HavenoHelpFormatter; import haveno.common.config.HavenoHelpFormatter;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -30,7 +30,7 @@ import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
public class HavenoHelpFormatterTest { public class HavenoHelpFormatterTest {

View file

@ -22,21 +22,19 @@ import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorManager;
import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorService; import haveno.core.support.dispute.arbitration.arbitrator.ArbitratorService;
import haveno.core.user.User; import haveno.core.user.User;
import haveno.network.p2p.NodeAddress; import haveno.network.p2p.NodeAddress;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class ArbitratorManagerTest { public class ArbitratorManagerTest {
@Test @Test
public void testIsArbitratorAvailableForLanguage() { public void testIsArbitratorAvailableForLanguage() {
User user = mock(User.class); User user = mock(User.class);

View file

@ -22,14 +22,14 @@ import haveno.common.crypto.PubKeyRing;
import haveno.core.support.dispute.arbitration.arbitrator.Arbitrator; import haveno.core.support.dispute.arbitration.arbitrator.Arbitrator;
import haveno.network.p2p.NodeAddress; import haveno.network.p2p.NodeAddress;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import java.util.Date; import java.util.Date;
@SuppressWarnings({"SameParameterValue", "UnusedAssignment"}) @SuppressWarnings({"SameParameterValue", "UnusedAssignment"})
public class ArbitratorTest { public class ArbitratorTest {
@Ignore("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)") @Disabled("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)")
public void testRoundtrip() { public void testRoundtrip() {
Arbitrator arbitrator = getArbitratorMock(); Arbitrator arbitrator = getArbitratorMock();

View file

@ -21,7 +21,7 @@ import com.google.common.collect.Lists;
import haveno.common.crypto.PubKeyRing; import haveno.common.crypto.PubKeyRing;
import haveno.core.support.dispute.mediation.mediator.Mediator; import haveno.core.support.dispute.mediation.mediator.Mediator;
import haveno.network.p2p.NodeAddress; import haveno.network.p2p.NodeAddress;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import java.util.Date; import java.util.Date;
@ -29,7 +29,7 @@ import static haveno.core.arbitration.ArbitratorTest.getBytes;
public class MediatorTest { public class MediatorTest {
@Ignore("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)") @Disabled("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)")
public void testRoundtrip() { public void testRoundtrip() {
Mediator Mediator = getMediatorMock(); Mediator Mediator = getMediatorMock();

View file

@ -3,14 +3,14 @@ package haveno.core.arbitration;
import haveno.core.account.witness.AccountAgeWitness; import haveno.core.account.witness.AccountAgeWitness;
import haveno.core.payment.payload.PaymentAccountPayload; import haveno.core.payment.payload.PaymentAccountPayload;
import haveno.core.support.dispute.arbitration.TraderDataItem; import haveno.core.support.dispute.arbitration.TraderDataItem;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.PublicKey; import java.security.PublicKey;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/* /*
@ -38,7 +38,7 @@ public class TraderDataItemTest {
private byte[] hash1 = "1".getBytes(); private byte[] hash1 = "1".getBytes();
private byte[] hash2 = "2".getBytes(); private byte[] hash2 = "2".getBytes();
@Before @BeforeEach
public void setup() { public void setup() {
accountAgeWitness1 = new AccountAgeWitness(hash1, 123); accountAgeWitness1 = new AccountAgeWitness(hash1, 123);
accountAgeWitness2 = new AccountAgeWitness(hash2, 124); accountAgeWitness2 = new AccountAgeWitness(hash2, 124);

View file

@ -21,10 +21,8 @@ import haveno.common.crypto.CryptoException;
import haveno.common.crypto.KeyRing; import haveno.common.crypto.KeyRing;
import haveno.common.crypto.KeyStorage; import haveno.common.crypto.KeyStorage;
import haveno.common.file.FileUtil; import haveno.common.file.FileUtil;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -33,11 +31,10 @@ import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
public class EncryptionTest { public class EncryptionTest {
private static final Logger log = LoggerFactory.getLogger(EncryptionTest.class);
private KeyRing keyRing; private KeyRing keyRing;
private File dir; private File dir;
@Before @BeforeEach
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException { public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
dir = File.createTempFile("temp_tests", ""); dir = File.createTempFile("temp_tests", "");
@ -49,7 +46,7 @@ public class EncryptionTest {
keyRing = new KeyRing(keyStorage, null, true); keyRing = new KeyRing(keyStorage, null, true);
} }
@After @AfterEach
public void tearDown() throws IOException { public void tearDown() throws IOException {
FileUtil.deleteDirectory(dir); FileUtil.deleteDirectory(dir);
} }

View file

@ -22,9 +22,9 @@ import haveno.common.crypto.KeyRing;
import haveno.common.crypto.KeyStorage; import haveno.common.crypto.KeyStorage;
import haveno.common.crypto.Sig; import haveno.common.crypto.Sig;
import haveno.common.file.FileUtil; import haveno.common.file.FileUtil;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,14 +32,14 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Random; import java.util.Random;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class SigTest { public class SigTest {
private static final Logger log = LoggerFactory.getLogger(SigTest.class); private static final Logger log = LoggerFactory.getLogger(SigTest.class);
private KeyRing keyRing; private KeyRing keyRing;
private File dir; private File dir;
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
dir = File.createTempFile("temp_tests", ""); dir = File.createTempFile("temp_tests", "");
@ -51,7 +51,7 @@ public class SigTest {
keyRing = new KeyRing(keyStorage, null, true); keyRing = new KeyRing(keyStorage, null, true);
} }
@After @AfterEach
public void tearDown() throws IOException { public void tearDown() throws IOException {
FileUtil.deleteDirectory(dir); FileUtil.deleteDirectory(dir);
} }

View file

@ -1,17 +1,17 @@
package haveno.core.locale; package haveno.core.locale;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
import static junit.framework.TestCase.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue;
public class BankUtilTest { public class BankUtilTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
GlobalSettings.setLocale(new Locale("en", "US")); GlobalSettings.setLocale(new Locale("en", "US"));

View file

@ -22,9 +22,8 @@ import haveno.asset.AssetRegistry;
import haveno.asset.Coin; import haveno.asset.Coin;
import haveno.asset.coins.Ether; import haveno.asset.coins.Ether;
import haveno.common.config.BaseCurrencyNetwork; import haveno.common.config.BaseCurrencyNetwork;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,13 +32,14 @@ import java.util.Optional;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class CurrencyUtilTest { public class CurrencyUtilTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
@ -55,7 +55,7 @@ public class CurrencyUtilTest {
assertTrue(euro.isPresent()); assertTrue(euro.isPresent());
assertTrue(naira.isPresent()); assertTrue(naira.isPresent());
assertFalse("Fake currency shouldn't exist", fake.isPresent()); assertFalse(fake.isPresent(), "Fake currency shouldn't exist");
} }
@Test @Test
@ -68,11 +68,11 @@ public class CurrencyUtilTest {
assetRegistry.addAsset(mockTestnetCoin); assetRegistry.addAsset(mockTestnetCoin);
CurrencyUtil.findAsset(assetRegistry, "MOCK_COIN", CurrencyUtil.findAsset(assetRegistry, "MOCK_COIN",
BaseCurrencyNetwork.XMR_MAINNET); BaseCurrencyNetwork.XMR_MAINNET);
Assert.fail("Expected an IllegalArgumentException"); fail("Expected an IllegalArgumentException");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
String wantMessage = "We are on mainnet and we could not find an asset with network type mainnet"; String wantMessage = "We are on mainnet and we could not find an asset with network type mainnet";
Assert.assertTrue("Unexpected exception, want message starting with " + assertTrue(e.getMessage().startsWith(wantMessage), "Unexpected exception, want message starting with " +
"'" + wantMessage + "', got '" + e.getMessage() + "'", e.getMessage().startsWith(wantMessage)); "'" + wantMessage + "', got '" + e.getMessage() + "'");
} }
// For testnet its ok // For testnet its ok

View file

@ -17,15 +17,14 @@
package haveno.core.message; package haveno.core.message;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@Slf4j @Slf4j
public class MarshallerTest { public class MarshallerTest {

View file

@ -17,117 +17,121 @@
package haveno.core.monetary; package haveno.core.monetary;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static haveno.core.monetary.Price.parse;
import static haveno.core.monetary.Price.valueOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class PriceTest { public class PriceTest {
@Test @Test
public void testParse() { public void testParse() {
Price result = Price.parse("USD", "0.1"); Price result = parse("USD", "0.1");
Assert.assertEquals( assertEquals(
"Fiat value should be formatted with two decimals.",
"0.10 XMR/USD", "0.10 XMR/USD",
result.toFriendlyString() result.toFriendlyString(),
"Fiat value should be formatted with two decimals."
); );
result = Price.parse("EUR", "0.1234"); result = parse("EUR", "0.1234");
Assert.assertEquals( assertEquals(
"Fiat value should be given two decimals",
"0.1234 XMR/EUR", "0.1234 XMR/EUR",
result.toFriendlyString() result.toFriendlyString(),
"Fiat value should be given two decimals"
); );
try { try {
Price.parse("EUR", "0.12345"); parse("EUR", "0.12345");
Assert.fail("Expected IllegalArgumentException to be thrown when too many decimals are used."); fail("Expected IllegalArgumentException to be thrown when too many decimals are used.");
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
Assert.assertEquals( assertEquals(
"Unexpected exception message.",
"java.lang.ArithmeticException: Rounding necessary", "java.lang.ArithmeticException: Rounding necessary",
iae.getMessage() iae.getMessage(),
"Unexpected exception message."
); );
} }
Assert.assertEquals( assertEquals(
"Negative value should be parsed correctly.",
-100000000L, -100000000L,
Price.parse("LTC", "-1").getValue() parse("LTC", "-1").getValue(),
"Negative value should be parsed correctly."
); );
Assert.assertEquals( assertEquals(
"Comma (',') as decimal separator should be converted to period ('.')",
"0.0001 XMR/USD", "0.0001 XMR/USD",
Price.parse("USD", "0,0001").toFriendlyString() parse("USD", "0,0001").toFriendlyString(),
"Comma (',') as decimal separator should be converted to period ('.')"
); );
Assert.assertEquals( assertEquals(
"Too many decimals should get rounded up properly.",
"10000.2346 LTC/XMR", "10000.2346 LTC/XMR",
Price.parse("LTC", "10000,23456789").toFriendlyString() parse("LTC", "10000,23456789").toFriendlyString(),
"Too many decimals should get rounded up properly."
); );
Assert.assertEquals( assertEquals(
"Too many decimals should get rounded down properly.",
"10000.2345 LTC/XMR", "10000.2345 LTC/XMR",
Price.parse("LTC", "10000,23454999").toFriendlyString() parse("LTC", "10000,23454999").toFriendlyString(),
"Too many decimals should get rounded down properly."
); );
Assert.assertEquals( assertEquals(
"Underlying long value should be correct.",
1000023456789L, 1000023456789L,
Price.parse("LTC", "10000,23456789").getValue() parse("LTC", "10000,23456789").getValue(),
"Underlying long value should be correct."
); );
try { try {
Price.parse("XMR", "56789.123456789"); parse("XMR", "56789.123456789");
Assert.fail("Expected IllegalArgumentException to be thrown when too many decimals are used."); fail("Expected IllegalArgumentException to be thrown when too many decimals are used.");
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
Assert.assertEquals( assertEquals(
"Unexpected exception message.",
"java.lang.ArithmeticException: Rounding necessary", "java.lang.ArithmeticException: Rounding necessary",
iae.getMessage() iae.getMessage(),
"Unexpected exception message."
); );
} }
} }
@Test @Test
public void testValueOf() { public void testValueOf() {
Price result = Price.valueOf("USD", 1); Price result = valueOf("USD", 1);
Assert.assertEquals( assertEquals(
"Fiat value should have four decimals.",
"0.0001 XMR/USD", "0.0001 XMR/USD",
result.toFriendlyString() result.toFriendlyString(),
"Fiat value should have four decimals."
); );
result = Price.valueOf("EUR", 1234); result = valueOf("EUR", 1234);
Assert.assertEquals( assertEquals(
"Fiat value should be given two decimals",
"0.1234 XMR/EUR", "0.1234 XMR/EUR",
result.toFriendlyString() result.toFriendlyString(),
"Fiat value should be given two decimals"
); );
Assert.assertEquals( assertEquals(
"Negative value should be parsed correctly.",
-1L, -1L,
Price.valueOf("LTC", -1L).getValue() valueOf("LTC", -1L).getValue(),
"Negative value should be parsed correctly."
); );
Assert.assertEquals( assertEquals(
"Too many decimals should get rounded up properly.",
"10000.2346 LTC/XMR", "10000.2346 LTC/XMR",
Price.valueOf("LTC", 1000023456789L).toFriendlyString() valueOf("LTC", 1000023456789L).toFriendlyString(),
"Too many decimals should get rounded up properly."
); );
Assert.assertEquals( assertEquals(
"Too many decimals should get rounded down properly.",
"10000.2345 LTC/XMR", "10000.2345 LTC/XMR",
Price.valueOf("LTC", 1000023454999L).toFriendlyString() valueOf("LTC", 1000023454999L).toFriendlyString(),
"Too many decimals should get rounded down properly."
); );
Assert.assertEquals( assertEquals(
"Underlying long value should be correct.",
1000023456789L, 1000023456789L,
Price.valueOf("LTC", 1000023456789L).getValue() valueOf("LTC", 1000023456789L).getValue(),
"Underlying long value should be correct."
); );
} }
} }

View file

@ -19,17 +19,19 @@ package haveno.core.network.p2p.seed;
import haveno.common.config.Config; import haveno.common.config.Config;
import haveno.network.p2p.NodeAddress; import haveno.network.p2p.NodeAddress;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static java.lang.String.format; import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class DefaultSeedNodeRepositoryTest { public class DefaultSeedNodeRepositoryTest {
@Test @Test
public void getSeedNodes() { public void getSeedNodes() {
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new Config()); DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new Config());
Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty()); assertFalse(DUT.getSeedNodeAddresses().isEmpty());
} }
@Test @Test
@ -38,9 +40,9 @@ public class DefaultSeedNodeRepositoryTest {
String seed2 = "fdsa:6001"; String seed2 = "fdsa:6001";
String seedNodesOption = format("--%s=%s,%s", Config.SEED_NODES, seed1, seed2); String seedNodesOption = format("--%s=%s,%s", Config.SEED_NODES, seed1, seed2);
DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new Config(seedNodesOption)); DefaultSeedNodeRepository DUT = new DefaultSeedNodeRepository(new Config(seedNodesOption));
Assert.assertFalse(DUT.getSeedNodeAddresses().isEmpty()); assertFalse(DUT.getSeedNodeAddresses().isEmpty());
Assert.assertEquals(2, DUT.getSeedNodeAddresses().size()); assertEquals(2, DUT.getSeedNodeAddresses().size());
Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed1))); assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed1)));
Assert.assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed2))); assertTrue(DUT.getSeedNodeAddresses().contains(new NodeAddress(seed2)));
} }
} }

View file

@ -19,12 +19,12 @@ package haveno.core.notifications;
import haveno.common.util.Tuple2; import haveno.common.util.Tuple2;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static common.utils.GenUtils.assertEquals;
@Slf4j @Slf4j
public class MobileModelTest { public class MobileModelTest {

View file

@ -17,10 +17,10 @@
package haveno.core.offer; package haveno.core.offer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View file

@ -11,16 +11,16 @@ import haveno.core.api.CoreMoneroConnectionsService;
import haveno.core.trade.TradableList; import haveno.core.trade.TradableList;
import haveno.network.p2p.P2PService; import haveno.network.p2p.P2PService;
import haveno.network.p2p.peers.PeerManager; import haveno.network.p2p.peers.PeerManager;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static com.natpryce.makeiteasy.MakeItEasy.make; import static com.natpryce.makeiteasy.MakeItEasy.make;
import static haveno.core.offer.OfferMaker.btcUsdOffer; import static haveno.core.offer.OfferMaker.btcUsdOffer;
import static junit.framework.TestCase.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -33,7 +33,7 @@ public class OpenOfferManagerTest {
private PersistenceManager<SignedOfferList> signedOfferPersistenceManager; private PersistenceManager<SignedOfferList> signedOfferPersistenceManager;
private CoreContext coreContext; private CoreContext coreContext;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
var corruptedStorageFileHandler = mock(CorruptedStorageFileHandler.class); var corruptedStorageFileHandler = mock(CorruptedStorageFileHandler.class);
var storageDir = Files.createTempDirectory("storage").toFile(); var storageDir = Files.createTempDirectory("storage").toFile();
@ -43,7 +43,7 @@ public class OpenOfferManagerTest {
coreContext = new CoreContext(); coreContext = new CoreContext();
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
persistenceManager.shutdown(); persistenceManager.shutdown();
signedOfferPersistenceManager.shutdown(); signedOfferPersistenceManager.shutdown();

View file

@ -17,14 +17,14 @@
package haveno.core.offer.availability; package haveno.core.offer.availability;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class ArbitratorSelectionTest { public class ArbitratorSelectionTest {
@Test @Test

View file

@ -21,11 +21,11 @@ import haveno.core.account.witness.AccountAgeWitness;
import haveno.core.account.witness.AccountAgeWitnessService; import haveno.core.account.witness.AccountAgeWitnessService;
import haveno.core.offer.Offer; import haveno.core.offer.Offer;
import haveno.core.payment.payload.PaymentAccountPayload; import haveno.core.payment.payload.PaymentAccountPayload;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View file

@ -21,10 +21,10 @@ import com.google.common.collect.Lists;
import haveno.core.locale.CryptoCurrency; import haveno.core.locale.CryptoCurrency;
import haveno.core.offer.Offer; import haveno.core.offer.Offer;
import haveno.core.payment.payload.PaymentMethod; import haveno.core.payment.payload.PaymentMethod;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View file

@ -18,28 +18,25 @@
package haveno.core.payment; package haveno.core.payment;
import haveno.core.offer.Offer; import haveno.core.offer.Offer;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class ReceiptValidatorTest { public class ReceiptValidatorTest {
private ReceiptValidator validator; private ReceiptValidator validator;
private PaymentAccount account; private PaymentAccount account;
private Offer offer; private Offer offer;
private ReceiptPredicates predicates; private ReceiptPredicates predicates;
@Before @BeforeEach
public void setUp() { public void setUp() {
this.predicates = mock(ReceiptPredicates.class); this.predicates = mock(ReceiptPredicates.class);
this.account = mock(CountryBasedPaymentAccount.class); this.account = mock(CountryBasedPaymentAccount.class);
@ -47,7 +44,7 @@ public class ReceiptValidatorTest {
this.validator = new ReceiptValidator(offer, account, predicates); this.validator = new ReceiptValidator(offer, account, predicates);
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
verifyNoMoreInteractions(offer); verifyNoMoreInteractions(offer);
} }

View file

@ -17,7 +17,7 @@
package haveno.core.payment; package haveno.core.payment;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class TradeLimitsTest { public class TradeLimitsTest {
@Test @Test

View file

@ -22,10 +22,10 @@ import haveno.common.config.BaseCurrencyNetwork;
import haveno.common.config.Config; import haveno.common.config.Config;
import haveno.core.locale.CurrencyUtil; import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class AltCoinAddressValidatorTest { public class AltCoinAddressValidatorTest {

View file

@ -20,8 +20,7 @@ package haveno.core.provider.mempool;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -32,6 +31,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TxValidatorTest { public class TxValidatorTest {
private static final Logger log = LoggerFactory.getLogger(TxValidatorTest.class); private static final Logger log = LoggerFactory.getLogger(TxValidatorTest.class);
@ -70,12 +72,12 @@ public class TxValidatorTest {
String jsonTxt = mempoolData.get(txValidator.getTxId()); String jsonTxt = mempoolData.get(txValidator.getTxId());
if (jsonTxt == null || jsonTxt.isEmpty()) { if (jsonTxt == null || jsonTxt.isEmpty()) {
log.warn("{} was not found in the mempool", txValidator.getTxId()); log.warn("{} was not found in the mempool", txValidator.getTxId());
Assert.assertFalse(expectedResult); // tx was not found in explorer assertFalse(expectedResult); // tx was not found in explorer
} else { } else {
//txValidator.parseJsonValidateMakerFeeTx(jsonTxt, btcFeeReceivers); //txValidator.parseJsonValidateMakerFeeTx(jsonTxt, btcFeeReceivers);
log.warn("expectedResult {}", expectedResult ); log.warn("expectedResult {}", expectedResult );
log.warn("getResult {}", txValidator.getResult() ); log.warn("getResult {}", txValidator.getResult() );
Assert.assertTrue(expectedResult == txValidator.getResult()); assertTrue(expectedResult == txValidator.getResult());
} }
}); });
} }

View file

@ -17,14 +17,14 @@
package haveno.core.provider.price; package haveno.core.provider.price;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static junit.framework.TestCase.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@Ignore @Disabled
public class MarketPriceFeedServiceTest { public class MarketPriceFeedServiceTest {
private static final Logger log = LoggerFactory.getLogger(MarketPriceFeedServiceTest.class); private static final Logger log = LoggerFactory.getLogger(MarketPriceFeedServiceTest.class);

View file

@ -20,9 +20,9 @@ package haveno.core.trade;
import haveno.core.offer.Offer; import haveno.core.offer.Offer;
import haveno.core.offer.OfferPayload; import haveno.core.offer.OfferPayload;
import haveno.core.offer.OpenOffer; import haveno.core.offer.OpenOffer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static protobuf.PersistableEnvelope.MessageCase.TRADABLE_LIST; import static protobuf.PersistableEnvelope.MessageCase.TRADABLE_LIST;

View file

@ -27,16 +27,16 @@ import haveno.core.locale.GlobalSettings;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.xmr.nodes.LocalBitcoinNode; import haveno.core.xmr.nodes.LocalBitcoinNode;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Currency; import java.util.Currency;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -46,7 +46,7 @@ public class PreferencesTest {
private Preferences preferences; private Preferences preferences;
private PersistenceManager persistenceManager; private PersistenceManager persistenceManager;
@Before @BeforeEach
public void setUp() { public void setUp() {
final Locale en_US = new Locale("en", "US"); final Locale en_US = new Locale("en", "US");
Locale.setDefault(en_US); Locale.setDefault(en_US);

View file

@ -23,19 +23,19 @@ import haveno.core.arbitration.ArbitratorTest;
import haveno.core.arbitration.MediatorTest; import haveno.core.arbitration.MediatorTest;
import haveno.core.filter.Filter; import haveno.core.filter.Filter;
import haveno.core.proto.CoreProtoResolver; import haveno.core.proto.CoreProtoResolver;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import java.util.HashSet; import java.util.HashSet;
public class UserPayloadModelVOTest { public class UserPayloadModelVOTest {
@Ignore("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)") @Disabled("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)")
public void testRoundtrip() { public void testRoundtrip() {
UserPayload vo = new UserPayload(); UserPayload vo = new UserPayload();
vo.setAccountId("accountId"); vo.setAccountId("accountId");
UserPayload newVo = UserPayload.fromProto(vo.toProtoMessage().getUserPayload(), new CoreProtoResolver()); UserPayload newVo = UserPayload.fromProto(vo.toProtoMessage().getUserPayload(), new CoreProtoResolver());
} }
@Ignore("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)") @Disabled("TODO InvalidKeySpecException at haveno.common.crypto.Sig.getPublicKeyFromBytes(Sig.java:135)")
public void testRoundtripFull() { public void testRoundtripFull() {
UserPayload vo = new UserPayload(); UserPayload vo = new UserPayload();
vo.setAccountId("accountId"); vo.setAccountId("accountId");

View file

@ -6,8 +6,8 @@ import haveno.core.locale.GlobalSettings;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.monetary.Price; import haveno.core.monetary.Price;
import org.bitcoinj.utils.Fiat; import org.bitcoinj.utils.Fiat;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -15,8 +15,8 @@ import java.util.concurrent.TimeUnit;
import static com.natpryce.makeiteasy.MakeItEasy.a; import static com.natpryce.makeiteasy.MakeItEasy.a;
import static com.natpryce.makeiteasy.MakeItEasy.make; import static com.natpryce.makeiteasy.MakeItEasy.make;
import static com.natpryce.makeiteasy.MakeItEasy.with; import static com.natpryce.makeiteasy.MakeItEasy.with;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class FormattingUtilsTest { public class FormattingUtilsTest {
private static final Property<Price, String> currencyCode = new Property<>(); private static final Property<Price, String> currencyCode = new Property<>();
@ -24,7 +24,7 @@ public class FormattingUtilsTest {
private static final Maker<Price> usdPrice = a(lookup -> private static final Maker<Price> usdPrice = a(lookup ->
new Price(Fiat.parseFiat(lookup.valueOf(currencyCode, "USD"), lookup.valueOf(priceString, "100")))); new Price(Fiat.parseFiat(lookup.valueOf(currencyCode, "USD"), lookup.valueOf(priceString, "100"))));
@Before @BeforeEach
public void setUp() { public void setUp() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
GlobalSettings.setLocale(new Locale("en", "US")); GlobalSettings.setLocale(new Locale("en", "US"));

View file

@ -17,13 +17,14 @@
package haveno.core.util; package haveno.core.util;
import haveno.common.proto.ProtoUtil;
import haveno.core.offer.OfferDirection; import haveno.core.offer.OfferDirection;
import haveno.core.offer.OpenOffer; import haveno.core.offer.OpenOffer;
import org.junit.Test; import org.junit.jupiter.api.Test;
import protobuf.OpenOffer.State;
import static org.junit.Assert.assertEquals; import static haveno.common.proto.ProtoUtil.enumFromProto;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@SuppressWarnings("UnusedAssignment") @SuppressWarnings("UnusedAssignment")
public class ProtoUtilTest { public class ProtoUtilTest {
@ -41,9 +42,9 @@ public class ProtoUtilTest {
@Test @Test
public void testUnknownEnum() { public void testUnknownEnum() {
protobuf.OpenOffer.State result = protobuf.OpenOffer.State.PB_ERROR; State result = State.PB_ERROR;
try { try {
OpenOffer.State finalResult = OpenOffer.State.valueOf(result.name()); OpenOffer.State.valueOf(result.name());
fail(); fail();
} catch (IllegalArgumentException ignore) { } catch (IllegalArgumentException ignore) {
} }
@ -51,10 +52,10 @@ public class ProtoUtilTest {
@Test @Test
public void testUnknownEnumFix() { public void testUnknownEnumFix() {
protobuf.OpenOffer.State result = protobuf.OpenOffer.State.PB_ERROR; State result = State.PB_ERROR;
try { try {
OpenOffer.State finalResult = ProtoUtil.enumFromProto(OpenOffer.State.class, result.name()); enumFromProto(OpenOffer.State.class, result.name());
assertEquals(OpenOffer.State.AVAILABLE, ProtoUtil.enumFromProto(OpenOffer.State.class, "AVAILABLE")); assertEquals(OpenOffer.State.AVAILABLE, enumFromProto(OpenOffer.State.class, "AVAILABLE"));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
fail(); fail();
} }

View file

@ -21,18 +21,18 @@ import haveno.core.locale.GlobalSettings;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import haveno.core.util.validation.RegexValidatorFactory; import haveno.core.util.validation.RegexValidatorFactory;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class RegexValidatorTest { public class RegexValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
GlobalSettings.setLocale(new Locale("en", "US")); GlobalSettings.setLocale(new Locale("en", "US"));

View file

@ -21,12 +21,12 @@ import haveno.core.monetary.Price;
import haveno.core.trade.HavenoUtils; import haveno.core.trade.HavenoUtils;
import haveno.core.xmr.wallet.Restrictions; import haveno.core.xmr.wallet.Restrictions;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.math.BigInteger; import java.math.BigInteger;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
public class CoinUtilTest { public class CoinUtilTest {
@ -64,9 +64,9 @@ public class CoinUtilTest {
HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(), HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(),
1); 1);
assertEquals( assertEquals(
"Minimum trade amount allowed should be adjusted to the smallest trade allowed.",
HavenoUtils.formatXmr(Restrictions.MIN_TRADE_AMOUNT, true), HavenoUtils.formatXmr(Restrictions.MIN_TRADE_AMOUNT, true),
HavenoUtils.formatXmr(result, true) HavenoUtils.formatXmr(result, true),
"Minimum trade amount allowed should be adjusted to the smallest trade allowed."
); );
try { try {
@ -78,9 +78,9 @@ public class CoinUtilTest {
fail("Expected IllegalArgumentException to be thrown when amount is too low."); fail("Expected IllegalArgumentException to be thrown when amount is too low.");
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
assertEquals( assertEquals(
"Unexpected exception message.",
"amount needs to be above minimum of 0.0001 xmr", "amount needs to be above minimum of 0.0001 xmr",
iae.getMessage() iae.getMessage(),
"Unexpected exception message."
); );
} }
@ -90,9 +90,9 @@ public class CoinUtilTest {
HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(), HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(),
1); 1);
assertEquals( assertEquals(
"Minimum allowed trade amount should not be adjusted.",
"0.10 XMR", "0.10 XMR",
HavenoUtils.formatXmr(result, true) HavenoUtils.formatXmr(result, true),
"Minimum allowed trade amount should not be adjusted."
); );
result = CoinUtil.getAdjustedAmount( result = CoinUtil.getAdjustedAmount(
@ -101,9 +101,9 @@ public class CoinUtilTest {
HavenoUtils.xmrToAtomicUnits(0.25).longValueExact(), HavenoUtils.xmrToAtomicUnits(0.25).longValueExact(),
1); 1);
assertEquals( assertEquals(
"Minimum trade amount allowed should respect maxTradeLimit and factor, if possible.",
"0.10 XMR", "0.10 XMR",
HavenoUtils.formatXmr(result, true) HavenoUtils.formatXmr(result, true),
"Minimum trade amount allowed should respect maxTradeLimit and factor, if possible."
); );
// TODO(chirhonul): The following seems like it should raise an exception or otherwise fail. // TODO(chirhonul): The following seems like it should raise an exception or otherwise fail.
@ -117,9 +117,9 @@ public class CoinUtilTest {
HavenoUtils.xmrToAtomicUnits(0.00005).longValueExact(), HavenoUtils.xmrToAtomicUnits(0.00005).longValueExact(),
1); 1);
assertEquals( assertEquals(
"Minimum trade amount allowed with low maxTradeLimit should still respect that limit, even if result does not respect the factor specified.",
"0.00005 XMR", "0.00005 XMR",
HavenoUtils.formatXmr(result, true) HavenoUtils.formatXmr(result, true),
"Minimum trade amount allowed with low maxTradeLimit should still respect that limit, even if result does not respect the factor specified."
); );
} }
} }

View file

@ -22,8 +22,8 @@ import haveno.core.xmr.setup.WalletConfig;
import haveno.network.Socks5MultiDiscovery; import haveno.network.Socks5MultiDiscovery;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.PeerAddress; import org.bitcoinj.core.PeerAddress;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
@ -37,7 +37,7 @@ public class BtcNetworkConfigTest {
private WalletConfig delegate; private WalletConfig delegate;
@Before @BeforeEach
public void setUp() { public void setUp() {
delegate = mock(WalletConfig.class); delegate = mock(WalletConfig.class);
} }

View file

@ -22,11 +22,11 @@ import haveno.core.xmr.nodes.BtcNodeConverter.Facade;
import haveno.core.xmr.nodes.BtcNodes.BtcNode; import haveno.core.xmr.nodes.BtcNodes.BtcNode;
import haveno.network.DnsLookupException; import haveno.network.DnsLookupException;
import org.bitcoinj.core.PeerAddress; import org.bitcoinj.core.PeerAddress;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.InetAddress; import java.net.InetAddress;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View file

@ -21,14 +21,14 @@ import com.google.common.collect.Lists;
import com.runjva.sourceforge.jsocks.protocol.Socks5Proxy; import com.runjva.sourceforge.jsocks.protocol.Socks5Proxy;
import haveno.core.xmr.nodes.BtcNodes.BtcNode; import haveno.core.xmr.nodes.BtcNodes.BtcNode;
import org.bitcoinj.core.PeerAddress; import org.bitcoinj.core.PeerAddress;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View file

@ -19,14 +19,14 @@ package haveno.core.xmr.nodes;
import haveno.core.user.Preferences; import haveno.core.user.Preferences;
import haveno.core.xmr.nodes.BtcNodes.BtcNode; import haveno.core.xmr.nodes.BtcNodes.BtcNode;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
import static haveno.core.xmr.nodes.BtcNodes.BitcoinNodesOption.CUSTOM; import static haveno.core.xmr.nodes.BtcNodes.BitcoinNodesOption.CUSTOM;
import static haveno.core.xmr.nodes.BtcNodes.BitcoinNodesOption.PUBLIC; import static haveno.core.xmr.nodes.BtcNodes.BitcoinNodesOption.PUBLIC;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View file

@ -18,10 +18,10 @@
package haveno.core.xmr.wallet; package haveno.core.xmr.wallet;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public class RestrictionsTest { public class RestrictionsTest {

View file

@ -20,10 +20,10 @@ package haveno.daemon.grpc.interceptor;
import haveno.daemon.grpc.GrpcVersionService; import haveno.daemon.grpc.GrpcVersionService;
import io.grpc.ServerInterceptor; import io.grpc.ServerInterceptor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -49,7 +49,7 @@ public class GrpcServiceRateMeteringConfigTest {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private static Optional<ServerInterceptor> versionServiceInterceptor; private static Optional<ServerInterceptor> versionServiceInterceptor;
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
// This is the tested rate meter, it allows 3 calls every 2 seconds. // This is the tested rate meter, it allows 3 calls every 2 seconds.
builder.addCallRateMeter(GrpcVersionService.class.getSimpleName(), builder.addCallRateMeter(GrpcVersionService.class.getSimpleName(),
@ -77,7 +77,7 @@ public class GrpcServiceRateMeteringConfigTest {
HOURS); HOURS);
} }
@Before @BeforeEach
public void buildConfigFile() { public void buildConfigFile() {
if (configFile == null) if (configFile == null)
configFile = builder.build(); configFile = builder.build();
@ -157,7 +157,7 @@ public class GrpcServiceRateMeteringConfigTest {
assertEquals(expectedCallsCount, rateMeter.getCallsCount()); assertEquals(expectedCallsCount, rateMeter.getCallsCount());
} }
@AfterClass @AfterAll
public static void teardown() { public static void teardown() {
if (configFile != null) if (configFile != null)
configFile.deleteOnExit(); configFile.deleteOnExit();

View file

@ -55,18 +55,18 @@ import haveno.desktop.main.presentation.MarketPricePresentation;
import haveno.desktop.util.Transitions; import haveno.desktop.util.Transitions;
import haveno.network.p2p.network.BridgeAddressProvider; import haveno.network.p2p.network.BridgeAddressProvider;
import haveno.network.p2p.seed.SeedNodeRepository; import haveno.network.p2p.seed.SeedNodeRepository;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static junit.framework.TestCase.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class GuiceSetupTest { public class GuiceSetupTest {
private Injector injector; private Injector injector;
@Before @BeforeEach
public void setUp() { public void setUp() {
Res.setup(); Res.setup();
CurrencyUtil.setup(); CurrencyUtil.setup();

View file

@ -24,30 +24,28 @@ import haveno.desktop.common.view.View;
import haveno.desktop.common.view.ViewFactory; import haveno.desktop.common.view.ViewFactory;
import haveno.desktop.common.view.ViewLoader; import haveno.desktop.common.view.ViewLoader;
import javafx.fxml.LoadException; import javafx.fxml.LoadException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
// TODO Some refactorings seem to have broken those tests. Investigate and remove @Ignore as soon its fixed. // TODO Some refactorings seem to have broken those tests. Investigate and remove @Disabled as soon its fixed.
@Ignore @Disabled
public class FxmlViewLoaderTests { public class FxmlViewLoaderTests {
private ViewLoader viewLoader; private ViewLoader viewLoader;
private ViewFactory viewFactory; private ViewFactory viewFactory;
@Rule @BeforeEach
public ExpectedException thrown = ExpectedException.none();
@Before
public void setUp() { public void setUp() {
viewFactory = mock(ViewFactory.class); viewFactory = mock(ViewFactory.class);
ResourceBundle resourceBundle = mock(ResourceBundle.class); ResourceBundle resourceBundle = mock(ResourceBundle.class);
@ -73,9 +71,8 @@ public class FxmlViewLoaderTests {
@Test @Test
public void fxmlFileMissingFxControllerAttributeShouldThrow() { public void fxmlFileMissingFxControllerAttributeShouldThrow() {
thrown.expect(ViewfxException.class); Throwable exception = assertThrows(ViewfxException.class, () -> viewLoader.load(MissingFxController.class));
thrown.expectMessage("Does it declare an fx:controller attribute?"); assertEquals("Does it declare an fx:controller attribute?", exception.getMessage());
viewLoader.load(MissingFxController.class);
} }
@ -96,10 +93,9 @@ public class FxmlViewLoaderTests {
@Test @Test
public void malformedFxmlFileShouldThrow() { public void malformedFxmlFileShouldThrow() {
thrown.expect(ViewfxException.class); Throwable exception = assertThrows(ViewfxException.class, () -> viewLoader.load(Malformed.class));
thrown.expectMessage("Failed to load view from FXML file"); assertTrue(exception.getCause() instanceof LoadException);
thrown.expectCause(instanceOf(LoadException.class)); assertEquals("Failed to load view from FXML file", exception.getMessage());
viewLoader.load(Malformed.class);
} }
@ -109,9 +105,8 @@ public class FxmlViewLoaderTests {
@Test @Test
public void missingFxmlFileShouldThrow() { public void missingFxmlFileShouldThrow() {
thrown.expect(ViewfxException.class); Throwable exception = assertThrows(ViewfxException.class, () -> viewLoader.load(MissingFxmlFile.class));
thrown.expectMessage("Does it exist?"); assertEquals("Does it exist?", exception.getMessage());
viewLoader.load(MissingFxmlFile.class);
} }
@ -121,11 +116,10 @@ public class FxmlViewLoaderTests {
@Test @Test
public void customFxmlFileLocationShouldOverrideDefaultConvention() { public void customFxmlFileLocationShouldOverrideDefaultConvention() {
thrown.expect(ViewfxException.class); Throwable exception = assertThrows(ViewfxException.class, () -> viewLoader.load(CustomLocation.class));
thrown.expectMessage("Failed to load view class"); assertTrue(exception.getMessage().contains("Failed to load view class"));
thrown.expectMessage("CustomLocation"); assertTrue(exception.getMessage().contains("CustomLocation"));
thrown.expectMessage("[unconventionally/located.fxml] could not be loaded"); assertTrue(exception.getMessage().contains("[unconventionally/located.fxml] could not be loaded"));
viewLoader.load(CustomLocation.class);
} }
} }

View file

@ -20,7 +20,7 @@ package haveno.desktop.common.support;
import haveno.desktop.common.view.AbstractView; import haveno.desktop.common.view.AbstractView;
import haveno.desktop.common.view.CachingViewLoader; import haveno.desktop.common.view.CachingViewLoader;
import haveno.desktop.common.view.ViewLoader; import haveno.desktop.common.view.ViewLoader;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View file

@ -19,13 +19,13 @@ package haveno.desktop.components;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class ColoredDecimalPlacesWithZerosTextTest { public class ColoredDecimalPlacesWithZerosTextTest {
@Ignore @Disabled
public void testOnlyZeroDecimals() { public void testOnlyZeroDecimals() {
ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.0000", 3); ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.0000", 3);
Label beforeZeros = (Label) text.getChildren().get(0); Label beforeZeros = (Label) text.getChildren().get(0);
@ -34,7 +34,7 @@ public class ColoredDecimalPlacesWithZerosTextTest {
assertEquals("000", zeroDecimals.getText()); assertEquals("000", zeroDecimals.getText());
} }
@Ignore @Disabled
public void testOneZeroDecimal() { public void testOneZeroDecimal() {
ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.2570", 3); ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.2570", 3);
Text beforeZeros = (Text) text.getChildren().get(0); Text beforeZeros = (Text) text.getChildren().get(0);
@ -43,7 +43,7 @@ public class ColoredDecimalPlacesWithZerosTextTest {
assertEquals("0", zeroDecimals.getText()); assertEquals("0", zeroDecimals.getText());
} }
@Ignore @Disabled
public void testMultipleZeroDecimal() { public void testMultipleZeroDecimal() {
ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.2000", 3); ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.2000", 3);
Text beforeZeros = (Text) text.getChildren().get(0); Text beforeZeros = (Text) text.getChildren().get(0);
@ -52,7 +52,7 @@ public class ColoredDecimalPlacesWithZerosTextTest {
assertEquals("000", zeroDecimals.getText()); assertEquals("000", zeroDecimals.getText());
} }
@Ignore @Disabled
public void testZeroDecimalsWithRange() { public void testZeroDecimalsWithRange() {
ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("0.1000 - 0.1250", 3); ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("0.1000 - 0.1250", 3);
assertEquals(5, text.getChildren().size()); assertEquals(5, text.getChildren().size());
@ -68,7 +68,7 @@ public class ColoredDecimalPlacesWithZerosTextTest {
assertEquals("0", zeroDecimals2.getText()); assertEquals("0", zeroDecimals2.getText());
} }
@Ignore @Disabled
public void testNoColorizing() { public void testNoColorizing() {
ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.2570", 0); ColoredDecimalPlacesWithZerosText text = new ColoredDecimalPlacesWithZerosText("1.2570", 0);
Text beforeZeros = (Text) text.getChildren().get(0); Text beforeZeros = (Text) text.getChildren().get(0);

View file

@ -21,12 +21,12 @@ import com.google.common.collect.Lists;
import haveno.core.xmr.wallet.XmrWalletService; import haveno.core.xmr.wallet.XmrWalletService;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import monero.wallet.model.MoneroTxWallet; import monero.wallet.model.MoneroTxWallet;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.RETURNS_DEEP_STUBS;

View file

@ -18,12 +18,12 @@
package haveno.desktop.main.funds.transactions; package haveno.desktop.main.funds.transactions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collection; import java.util.Collection;
import java.util.function.Supplier; import java.util.function.Supplier;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;

View file

@ -22,9 +22,9 @@ import haveno.core.support.dispute.arbitration.ArbitrationManager;
import haveno.core.trade.Tradable; import haveno.core.trade.Tradable;
import haveno.core.trade.Trade; import haveno.core.trade.Trade;
import monero.wallet.model.MoneroTxWallet; import monero.wallet.model.MoneroTxWallet;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class TransactionAwareTradableFactoryTest { public class TransactionAwareTradableFactoryTest {

View file

@ -25,12 +25,12 @@ import haveno.core.xmr.wallet.XmrWalletService;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import monero.wallet.model.MoneroTxWallet; import monero.wallet.model.MoneroTxWallet;
import org.bitcoinj.core.Sha256Hash; import org.bitcoinj.core.Sha256Hash;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -45,7 +45,7 @@ public class TransactionAwareTradeTest {
private RefundManager refundManager; private RefundManager refundManager;
private XmrWalletService xmrWalletService; private XmrWalletService xmrWalletService;
@Before @BeforeEach
public void setUp() { public void setUp() {
this.transaction = mock(MoneroTxWallet.class); this.transaction = mock(MoneroTxWallet.class);
when(transaction.getHash()).thenReturn(XID.toString()); when(transaction.getHash()).thenReturn(XID.toString());

View file

@ -25,8 +25,8 @@ import haveno.desktop.main.offer.offerbook.OfferBookListItemMaker;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static com.natpryce.makeiteasy.MakeItEasy.make; import static com.natpryce.makeiteasy.MakeItEasy.make;
import static com.natpryce.makeiteasy.MakeItEasy.with; import static com.natpryce.makeiteasy.MakeItEasy.with;
@ -34,14 +34,14 @@ import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrBuyI
import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrSellItem; import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrSellItem;
import static haveno.desktop.maker.PreferenceMakers.empty; import static haveno.desktop.maker.PreferenceMakers.empty;
import static haveno.desktop.maker.TradeCurrencyMakers.usd; import static haveno.desktop.maker.TradeCurrencyMakers.usd;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class OfferBookChartViewModelTest { public class OfferBookChartViewModelTest {
@Before @BeforeEach
public void setUp() { public void setUp() {
GlobalSettings.setDefaultTradeCurrency(usd); GlobalSettings.setDefaultTradeCurrency(usd);
} }

View file

@ -27,14 +27,14 @@ import haveno.desktop.main.offer.offerbook.OfferBookListItem;
import haveno.desktop.main.offer.offerbook.OfferBookListItemMaker; import haveno.desktop.main.offer.offerbook.OfferBookListItemMaker;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static com.natpryce.makeiteasy.MakeItEasy.make; import static com.natpryce.makeiteasy.MakeItEasy.make;
import static com.natpryce.makeiteasy.MakeItEasy.with; import static com.natpryce.makeiteasy.MakeItEasy.with;
import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.id; import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.id;
import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrBuyItem; import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrBuyItem;
import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrSellItem; import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrSellItem;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View file

@ -32,9 +32,9 @@ import javafx.collections.ObservableSet;
import javafx.util.Pair; import javafx.util.Pair;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.Fiat; import org.bitcoinj.utils.Fiat;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -47,7 +47,7 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
public class TradesChartsViewModelTest { public class TradesChartsViewModelTest {
@ -94,7 +94,7 @@ public class TradesChartsViewModelTest {
null, null,
null); null);
@Before @BeforeEach
public void setup() throws IOException { public void setup() throws IOException {
tradeStatisticsManager = mock(TradeStatisticsManager.class); tradeStatisticsManager = mock(TradeStatisticsManager.class);
model = new TradesChartsViewModel(tradeStatisticsManager, mock(Preferences.class), mock(PriceFeedService.class), model = new TradesChartsViewModel(tradeStatisticsManager, mock(Preferences.class), mock(PriceFeedService.class),
@ -177,7 +177,7 @@ public class TradesChartsViewModelTest {
} }
// TODO JMOCKIT // TODO JMOCKIT
@Ignore @Disabled
@Test @Test
public void testItemLists() throws ParseException { public void testItemLists() throws ParseException {
// Helper class to add historic trades // Helper class to add historic trades

View file

@ -17,13 +17,13 @@ import haveno.core.user.User;
import haveno.core.xmr.model.XmrAddressEntry; import haveno.core.xmr.model.XmrAddressEntry;
import haveno.core.xmr.wallet.XmrWalletService; import haveno.core.xmr.wallet.XmrWalletService;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -36,7 +36,7 @@ public class CreateOfferDataModelTest {
private Preferences preferences; private Preferences preferences;
private OfferUtil offerUtil; private OfferUtil offerUtil;
@Before @BeforeEach
public void setUp() { public void setUp() {
final CryptoCurrency xmr = new CryptoCurrency("XMR", "monero"); final CryptoCurrency xmr = new CryptoCurrency("XMR", "monero");
GlobalSettings.setDefaultTradeCurrency(xmr); GlobalSettings.setDefaultTradeCurrency(xmr);

View file

@ -44,16 +44,16 @@ import haveno.core.xmr.model.XmrAddressEntry;
import haveno.core.xmr.wallet.XmrWalletService; import haveno.core.xmr.wallet.XmrWalletService;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.math.BigInteger; import java.math.BigInteger;
import java.time.Instant; import java.time.Instant;
import java.util.UUID; import java.util.UUID;
import static haveno.desktop.maker.PreferenceMakers.empty; import static haveno.desktop.maker.PreferenceMakers.empty;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -65,7 +65,7 @@ public class CreateOfferViewModelTest {
private final CoinFormatter coinFormatter = new ImmutableCoinFormatter( private final CoinFormatter coinFormatter = new ImmutableCoinFormatter(
Config.baseCurrencyNetworkParameters().getMonetaryFormat()); Config.baseCurrencyNetworkParameters().getMonetaryFormat());
@Before @BeforeEach
public void setUp() { public void setUp() {
final CryptoCurrency btc = new CryptoCurrency("XMR", "monero"); final CryptoCurrency btc = new CryptoCurrency("XMR", "monero");
GlobalSettings.setDefaultTradeCurrency(btc); GlobalSettings.setDefaultTradeCurrency(btc);

View file

@ -51,9 +51,9 @@ import haveno.core.util.coin.ImmutableCoinFormatter;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -73,10 +73,10 @@ import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrBuyI
import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrItemWithRange; import static haveno.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrItemWithRange;
import static haveno.desktop.maker.PreferenceMakers.empty; import static haveno.desktop.maker.PreferenceMakers.empty;
import static haveno.desktop.maker.TradeCurrencyMakers.usd; import static haveno.desktop.maker.TradeCurrencyMakers.usd;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -87,7 +87,7 @@ public class OfferBookViewModelTest {
private static final Logger log = LoggerFactory.getLogger(OfferBookViewModelTest.class); private static final Logger log = LoggerFactory.getLogger(OfferBookViewModelTest.class);
private User user; private User user;
@Before @BeforeEach
public void setUp() { public void setUp() {
GlobalSettings.setDefaultTradeCurrency(usd); GlobalSettings.setDefaultTradeCurrency(usd);
Res.setBaseCurrencyCode(usd.getCode()); Res.setBaseCurrencyCode(usd.getCode());
@ -103,7 +103,7 @@ public class OfferBookViewModelTest {
return new PriceUtil(priceFeedService, tradeStatisticsManager, empty); return new PriceUtil(priceFeedService, tradeStatisticsManager, empty);
} }
@Ignore("PaymentAccountPayload needs to be set (has been changed with PB changes)") @Disabled("PaymentAccountPayload needs to be set (has been changed with PB changes)")
public void testIsAnyPaymentAccountValidForOffer() { public void testIsAnyPaymentAccountValidForOffer() {
Collection<PaymentAccount> paymentAccounts; Collection<PaymentAccount> paymentAccounts;
paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSepaAccount("EUR", "DE", "1212324", paymentAccounts = new ArrayList<>(FXCollections.singletonObservableList(getSepaAccount("EUR", "DE", "1212324",

View file

@ -17,7 +17,9 @@
package haveno.desktop.main.overlays; package haveno.desktop.main.overlays;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class OverlayTest { public class OverlayTest {
@ -28,9 +30,9 @@ public class OverlayTest {
new D<>(); new D<>();
} }
@Test(expected = RuntimeException.class) @Test
public void typeUnsafeCreation() { public void typeUnsafeCreation() {
new B(); assertThrows(RuntimeException.class, () -> new B());
} }
private static class A extends Overlay<A> { private static class A extends Overlay<A> {

View file

@ -20,13 +20,13 @@ package haveno.desktop.main.overlays.windows.downloadupdate;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import haveno.desktop.main.overlays.windows.downloadupdate.HavenoInstaller.FileDescriptor; import haveno.desktop.main.overlays.windows.downloadupdate.HavenoInstaller.FileDescriptor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@Slf4j @Slf4j
public class HavenoInstallerTest { public class HavenoInstallerTest {

View file

@ -17,7 +17,7 @@
package haveno.desktop.main.overlays.windows.downloadupdate; package haveno.desktop.main.overlays.windows.downloadupdate;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class VerifyTaskTest { public class VerifyTaskTest {

View file

@ -26,12 +26,12 @@ import haveno.desktop.maker.PreferenceMakers;
import haveno.network.p2p.NodeAddress; import haveno.network.p2p.NodeAddress;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableMap; import javafx.collections.ObservableMap;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View file

@ -22,15 +22,15 @@ import haveno.core.locale.CryptoCurrency;
import haveno.core.locale.FiatCurrency; import haveno.core.locale.FiatCurrency;
import haveno.core.locale.TradeCurrency; import haveno.core.locale.TradeCurrency;
import haveno.core.user.Preferences; import haveno.core.user.Preferences;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Currency; import java.util.Currency;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -46,7 +46,7 @@ public class CurrencyListTest {
private List<CurrencyListItem> delegate; private List<CurrencyListItem> delegate;
private CurrencyList testedEntity; private CurrencyList testedEntity;
@Before @BeforeEach
public void setUp() { public void setUp() {
Locale.setDefault(locale); Locale.setDefault(locale);

View file

@ -9,8 +9,8 @@ import haveno.core.offer.OfferPayload;
import haveno.core.util.VolumeUtil; import haveno.core.util.VolumeUtil;
import haveno.core.util.coin.CoinFormatter; import haveno.core.util.coin.CoinFormatter;
import haveno.core.util.coin.ImmutableCoinFormatter; import haveno.core.util.coin.ImmutableCoinFormatter;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Locale; import java.util.Locale;
@ -21,14 +21,14 @@ import static com.natpryce.makeiteasy.MakeItEasy.with;
import static haveno.desktop.maker.OfferMaker.xmrUsdOffer; import static haveno.desktop.maker.OfferMaker.xmrUsdOffer;
import static haveno.desktop.maker.VolumeMaker.usdVolume; import static haveno.desktop.maker.VolumeMaker.usdVolume;
import static haveno.desktop.maker.VolumeMaker.volumeString; import static haveno.desktop.maker.VolumeMaker.volumeString;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class DisplayUtilsTest { public class DisplayUtilsTest {
private final CoinFormatter formatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat()); private final CoinFormatter formatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat());
@Before @BeforeEach
public void setUp() { public void setUp() {
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
GlobalSettings.setLocale(Locale.US); GlobalSettings.setLocale(Locale.US);

View file

@ -24,8 +24,8 @@ import haveno.core.trade.HavenoUtils;
import haveno.core.user.DontShowAgainLookup; import haveno.core.user.DontShowAgainLookup;
import haveno.core.user.Preferences; import haveno.core.user.Preferences;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
@ -34,14 +34,14 @@ import java.util.Map;
import static haveno.desktop.maker.TradeCurrencyMakers.euro; import static haveno.desktop.maker.TradeCurrencyMakers.euro;
import static haveno.desktop.maker.TradeCurrencyMakers.monero; import static haveno.desktop.maker.TradeCurrencyMakers.monero;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class GUIUtilTest { public class GUIUtilTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
GlobalSettings.setLocale(new Locale("en", "US")); GlobalSettings.setLocale(new Locale("en", "US"));

View file

@ -22,8 +22,8 @@ import haveno.core.locale.Res;
import haveno.core.util.coin.CoinFormatter; import haveno.core.util.coin.CoinFormatter;
import haveno.core.util.coin.ImmutableCoinFormatter; import haveno.core.util.coin.ImmutableCoinFormatter;
import org.bitcoinj.core.CoinMaker; import org.bitcoinj.core.CoinMaker;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
@ -32,13 +32,13 @@ import static com.natpryce.makeiteasy.MakeItEasy.make;
import static com.natpryce.makeiteasy.MakeItEasy.with; import static com.natpryce.makeiteasy.MakeItEasy.with;
import static org.bitcoinj.core.CoinMaker.oneBitcoin; import static org.bitcoinj.core.CoinMaker.oneBitcoin;
import static org.bitcoinj.core.CoinMaker.satoshis; import static org.bitcoinj.core.CoinMaker.satoshis;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class ImmutableCoinFormatterTest { public class ImmutableCoinFormatterTest {
private final CoinFormatter formatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat()); private final CoinFormatter formatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat());
@Before @BeforeEach
public void setUp() { public void setUp() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
Res.setBaseCurrencyCode("XMR"); Res.setBaseCurrencyCode("XMR");

View file

@ -17,12 +17,14 @@
package haveno.desktop.util; package haveno.desktop.util;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MovingAverageUtilsTest { public class MovingAverageUtilsTest {
private static final int NAN = -99; private static final int NAN = -99;
@ -50,7 +52,7 @@ public class MovingAverageUtilsTest {
private static void testMA(int period, int[] input, int[] expected) { private static void testMA(int period, int[] input, int[] expected) {
var output = calcMA(period, input); var output = calcMA(period, input);
Assert.assertArrayEquals(output, expected); assertArrayEquals(output, expected);
} }
@Test @Test
@ -107,24 +109,28 @@ public class MovingAverageUtilsTest {
); );
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nonsensicalPeriod1() { public void nonsensicalPeriod1() {
var impossible = new int[]{}; assertThrows(IllegalArgumentException.class, () -> {
testMA( var impossible = new int[]{};
0, testMA(
new int[]{10, 20}, 0,
impossible new int[]{10, 20},
); impossible
);
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void nonsensicalPeriod2() { public void nonsensicalPeriod2() {
var impossible = new int[]{}; assertThrows(IllegalArgumentException.class, () -> {
testMA( var impossible = new int[]{};
-1, testMA(
new int[]{10, 20}, -1,
impossible new int[]{10, 20},
); impossible
);
});
} }
@Test @Test

View file

@ -2,16 +2,16 @@ package haveno.desktop.util.validation;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.AccountNrValidator; import haveno.core.payment.validation.AccountNrValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class AccountNrValidatorTest { public class AccountNrValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
Res.setBaseCurrencyCode("XMR"); Res.setBaseCurrencyCode("XMR");

View file

@ -7,14 +7,14 @@ import haveno.core.locale.Res;
import haveno.core.payment.validation.AdvancedCashValidator; import haveno.core.payment.validation.AdvancedCashValidator;
import haveno.core.payment.validation.EmailValidator; import haveno.core.payment.validation.EmailValidator;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class AdvancedCashValidatorTest { public class AdvancedCashValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -2,17 +2,17 @@ package haveno.desktop.util.validation;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.BranchIdValidator; import haveno.core.payment.validation.BranchIdValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class BranchIdValidatorTest { public class BranchIdValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
Res.setBaseCurrencyCode("XMR"); Res.setBaseCurrencyCode("XMR");

View file

@ -6,14 +6,14 @@ import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.CapitualValidator; import haveno.core.payment.validation.CapitualValidator;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class CapitualValidatorTest { public class CapitualValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -22,15 +22,15 @@ import haveno.common.config.Config;
import haveno.core.locale.CurrencyUtil; import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.FiatVolumeValidator; import haveno.core.payment.validation.FiatVolumeValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class FiatVolumeValidatorTest { public class FiatVolumeValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -24,15 +24,15 @@ import haveno.core.locale.Res;
import haveno.core.payment.validation.InteracETransferAnswerValidator; import haveno.core.payment.validation.InteracETransferAnswerValidator;
import haveno.core.payment.validation.LengthValidator; import haveno.core.payment.validation.LengthValidator;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class InteracETransferAnswerValidatorTest { public class InteracETransferAnswerValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -24,15 +24,15 @@ import haveno.core.locale.Res;
import haveno.core.payment.validation.InteracETransferQuestionValidator; import haveno.core.payment.validation.InteracETransferQuestionValidator;
import haveno.core.payment.validation.LengthValidator; import haveno.core.payment.validation.LengthValidator;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class InteracETransferQuestionValidatorTest { public class InteracETransferQuestionValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -27,15 +27,15 @@ import haveno.core.payment.validation.InteracETransferQuestionValidator;
import haveno.core.payment.validation.InteracETransferValidator; import haveno.core.payment.validation.InteracETransferValidator;
import haveno.core.payment.validation.LengthValidator; import haveno.core.payment.validation.LengthValidator;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class InteracETransferValidatorTest { public class InteracETransferValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -22,15 +22,15 @@ import haveno.common.config.Config;
import haveno.core.locale.CurrencyUtil; import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.LengthValidator; import haveno.core.payment.validation.LengthValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class LengthValidatorTest { public class LengthValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -2,17 +2,17 @@ package haveno.desktop.util.validation;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.NationalAccountIdValidator; import haveno.core.payment.validation.NationalAccountIdValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Locale; import java.util.Locale;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class NationalAccountIdValidatorTest { public class NationalAccountIdValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
Res.setBaseCurrencyCode("XMR"); Res.setBaseCurrencyCode("XMR");

View file

@ -3,19 +3,19 @@ package haveno.desktop.util.validation;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.PhoneNumberValidator; import haveno.core.payment.validation.PhoneNumberValidator;
import haveno.core.util.validation.InputValidator.ValidationResult; import haveno.core.util.validation.InputValidator.ValidationResult;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class PhoneNumberValidatorTest { public class PhoneNumberValidatorTest {
private PhoneNumberValidator validator; private PhoneNumberValidator validator;
private ValidationResult validationResult; private ValidationResult validationResult;
@Before @BeforeEach
public void setup() { public void setup() {
Res.setup(); Res.setup();
} }
@ -24,7 +24,7 @@ public class PhoneNumberValidatorTest {
public void testMissingCountryCode() { public void testMissingCountryCode() {
validator = new PhoneNumberValidator(); validator = new PhoneNumberValidator();
validationResult = validator.validate("+12124567890"); validationResult = validator.validate("+12124567890");
assertFalse("Should not be valid if validator's country code is missing", validationResult.isValid); assertFalse(validationResult.isValid, "Should not be valid if validator's country code is missing");
assertEquals(Res.get("validation.phone.missingCountryCode"), validationResult.errorMessage); assertEquals(Res.get("validation.phone.missingCountryCode"), validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
} }
@ -33,12 +33,12 @@ public class PhoneNumberValidatorTest {
public void testNoInput() { public void testNoInput() {
validator = new PhoneNumberValidator("AT"); validator = new PhoneNumberValidator("AT");
validationResult = validator.validate(""); validationResult = validator.validate("");
assertFalse("'' should not be a valid number in AT", validationResult.isValid); assertFalse(validationResult.isValid, "'' should not be a valid number in AT");
assertEquals(Res.get("validation.empty"), validationResult.errorMessage); assertEquals(Res.get("validation.empty"), validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
validationResult = validator.validate(null); validationResult = validator.validate(null);
assertFalse("'' should not be a valid number in AT", validationResult.isValid); assertFalse(validationResult.isValid, "'' should not be a valid number in AT");
assertEquals(Res.get("validation.empty"), validationResult.errorMessage); assertEquals(Res.get("validation.empty"), validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
} }
@ -69,12 +69,12 @@ public class PhoneNumberValidatorTest {
public void testInvalidAustriaNumbers() { public void testInvalidAustriaNumbers() {
validator = new PhoneNumberValidator("AT"); // AT country code is +43 validator = new PhoneNumberValidator("AT"); // AT country code is +43
validationResult = validator.validate("+43 1 214"); validationResult = validator.validate("+43 1 214");
assertFalse("+43 1 214 should not be a valid number in AT", validationResult.isValid); assertFalse(validationResult.isValid, "+43 1 214 should not be a valid number in AT");
assertEquals(Res.get("validation.phone.insufficientDigits", "+43 1 214"), validationResult.errorMessage); assertEquals(Res.get("validation.phone.insufficientDigits", "+43 1 214"), validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
validationResult = validator.validate("+42 1 650 454 0987"); validationResult = validator.validate("+42 1 650 454 0987");
assertFalse("+42 1 650 454 0987 should not be a valid number in AT", validationResult.isValid); assertFalse(validationResult.isValid, "+42 1 650 454 0987 should not be a valid number in AT");
assertEquals(Res.get("validation.phone.invalidDialingCode", "+42 1 650 454 0987", "AT", validator.getCallingCode()), assertEquals(Res.get("validation.phone.invalidDialingCode", "+42 1 650 454 0987", "AT", validator.getCallingCode()),
validationResult.errorMessage); validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
@ -136,7 +136,7 @@ public class PhoneNumberValidatorTest {
public void testInvalidCanadaNumber() { public void testInvalidCanadaNumber() {
validator = new PhoneNumberValidator("CA"); validator = new PhoneNumberValidator("CA");
validationResult = validator.validate("+2 1 650 454 0987"); validationResult = validator.validate("+2 1 650 454 0987");
assertFalse("+2 1 650 454 0987 should not be a valid number in CA", validationResult.isValid); assertFalse(validationResult.isValid, "+2 1 650 454 0987 should not be a valid number in CA");
assertEquals(Res.get("validation.phone.invalidDialingCode", "+2 1 650 454 0987", "CA", validator.getCallingCode()), assertEquals(Res.get("validation.phone.invalidDialingCode", "+2 1 650 454 0987", "CA", validator.getCallingCode()),
validationResult.errorMessage); validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
@ -263,13 +263,13 @@ public class PhoneNumberValidatorTest {
public void testInvalidUSNumbers() { public void testInvalidUSNumbers() {
validator = new PhoneNumberValidator("US"); validator = new PhoneNumberValidator("US");
validationResult = validator.validate("+1 512 GR8 0150"); validationResult = validator.validate("+1 512 GR8 0150");
assertFalse("+1 512 GR8 0150 should not be a valid number in US", validationResult.isValid); assertFalse(validationResult.isValid, "+1 512 GR8 0150 should not be a valid number in US");
assertEquals(Res.get("validation.phone.invalidCharacters", "+1 512 GR8 0150", "US", validator.getCallingCode()), assertEquals(Res.get("validation.phone.invalidCharacters", "+1 512 GR8 0150", "US", validator.getCallingCode()),
validationResult.errorMessage); validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());
validationResult = validator.validate("+1 212-3456-0150-9832"); validationResult = validator.validate("+1 212-3456-0150-9832");
assertFalse("+1 212-3456-0150-9832 should not be a valid number in US", validationResult.isValid); assertFalse(validationResult.isValid, "+1 212-3456-0150-9832 should not be a valid number in US");
assertEquals(Res.get("validation.phone.tooManyDigits", "+1 212-3456-0150-9832", "US", validator.getCallingCode()), assertEquals(Res.get("validation.phone.tooManyDigits", "+1 212-3456-0150-9832", "US", validator.getCallingCode()),
validationResult.errorMessage); validationResult.errorMessage);
assertNull(validator.getNormalizedPhoneNumber()); assertNull(validator.getNormalizedPhoneNumber());

View file

@ -22,15 +22,15 @@ import haveno.common.config.Config;
import haveno.core.locale.CurrencyUtil; import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.util.validation.RegexValidator; import haveno.core.util.validation.RegexValidator;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class RegexValidatorTest { public class RegexValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -23,15 +23,15 @@ import haveno.core.locale.CurrencyUtil;
import haveno.core.locale.Res; import haveno.core.locale.Res;
import haveno.core.payment.validation.XmrValidator; import haveno.core.payment.validation.XmrValidator;
import haveno.core.trade.HavenoUtils; import haveno.core.trade.HavenoUtils;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class XmrValidatorTest { public class XmrValidatorTest {
@Before @BeforeEach
public void setup() { public void setup() {
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork(); final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
final String currencyCode = baseCurrencyNetwork.getCurrencyCode(); final String currencyCode = baseCurrencyNetwork.getCurrencyCode();

View file

@ -2578,6 +2578,11 @@
<sha256 value="a0f823d513c8d4692935f24c2fe6e77cc4a7b6147a9e8a518f722e50bbf86138" origin="Generated by Gradle"/> <sha256 value="a0f823d513c8d4692935f24c2fe6e77cc4a7b6147a9e8a518f722e50bbf86138" origin="Generated by Gradle"/>
</artifact> </artifact>
</component> </component>
<component group="org.junit.jupiter" name="junit-jupiter-api" version="5.9.2">
<artifact name="junit-jupiter-api-5.9.2.jar">
<sha256 value="f767a170f97127b0ad3582bf3358eabbbbe981d9f96411853e629d9276926fd5" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.7.0"> <component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.7.0">
<artifact name="junit-jupiter-engine-5.7.0.jar"> <artifact name="junit-jupiter-engine-5.7.0.jar">
<sha256 value="dfa26af94644ac2612dde6625852fcb550a0d21caa243257de54cba738ba87af" origin="Generated by Gradle"/> <sha256 value="dfa26af94644ac2612dde6625852fcb550a0d21caa243257de54cba738ba87af" origin="Generated by Gradle"/>
@ -2586,6 +2591,11 @@
<sha256 value="b702e250875d331ee3c6b88f37299fbe951f43992f4b2e4a8f144e2e4cf2c7e8" origin="Generated by Gradle"/> <sha256 value="b702e250875d331ee3c6b88f37299fbe951f43992f4b2e4a8f144e2e4cf2c7e8" origin="Generated by Gradle"/>
</artifact> </artifact>
</component> </component>
<component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.9.2">
<artifact name="junit-jupiter-engine-5.9.2.jar">
<sha256 value="74cfc49388f760413ff348ca2c9ab39527484b57deecd157f2275a5f8a5fe971" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.jupiter" name="junit-jupiter-params" version="5.7.0"> <component group="org.junit.jupiter" name="junit-jupiter-params" version="5.7.0">
<artifact name="junit-jupiter-params-5.7.0.jar"> <artifact name="junit-jupiter-params-5.7.0.jar">
<sha256 value="ca9f555c37b9bf79effd2e834af549e4feb52ad8ac9e348fe5b430d4d8a482b7" origin="Generated by Gradle"/> <sha256 value="ca9f555c37b9bf79effd2e834af549e4feb52ad8ac9e348fe5b430d4d8a482b7" origin="Generated by Gradle"/>
@ -2594,6 +2604,11 @@
<sha256 value="23873e305a9751109839ad08b6b37dfadd1036f43b359b3b1b7bd2601fc73260" origin="Generated by Gradle"/> <sha256 value="23873e305a9751109839ad08b6b37dfadd1036f43b359b3b1b7bd2601fc73260" origin="Generated by Gradle"/>
</artifact> </artifact>
</component> </component>
<component group="org.junit.jupiter" name="junit-jupiter-params" version="5.9.2">
<artifact name="junit-jupiter-params-5.9.2.jar">
<sha256 value="bde91900a5ce5d6663bb44bc708494b35daefcd73e1bb7afa61a4affe38ea97d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.platform" name="junit-platform-commons" version="1.7.0"> <component group="org.junit.platform" name="junit-platform-commons" version="1.7.0">
<artifact name="junit-platform-commons-1.7.0.jar"> <artifact name="junit-platform-commons-1.7.0.jar">
<sha256 value="5330ee87cc7586e6e25175a34e9251624ff12ff525269d3415d0b4ca519b6fea" origin="Generated by Gradle"/> <sha256 value="5330ee87cc7586e6e25175a34e9251624ff12ff525269d3415d0b4ca519b6fea" origin="Generated by Gradle"/>
@ -2610,6 +2625,11 @@
<sha256 value="ce852e34c6a184aa6c80ee8df0471713a7408134134f08e3c1c3dd87c6b59ab7" origin="Generated by Gradle"/> <sha256 value="ce852e34c6a184aa6c80ee8df0471713a7408134134f08e3c1c3dd87c6b59ab7" origin="Generated by Gradle"/>
</artifact> </artifact>
</component> </component>
<component group="org.junit.platform" name="junit-platform-commons" version="1.9.2">
<artifact name="junit-platform-commons-1.9.2.jar">
<sha256 value="624a3d745ef1d28e955a6a67af8edba0fdfc5c9bad680a73f67a70bb950a683d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.platform" name="junit-platform-engine" version="1.7.0"> <component group="org.junit.platform" name="junit-platform-engine" version="1.7.0">
<artifact name="junit-platform-engine-1.7.0.jar"> <artifact name="junit-platform-engine-1.7.0.jar">
<sha256 value="75f21a20dc594afdc875736725b408cec6d0344874d29f34b2dd3075500236f2" origin="Generated by Gradle"/> <sha256 value="75f21a20dc594afdc875736725b408cec6d0344874d29f34b2dd3075500236f2" origin="Generated by Gradle"/>
@ -2626,6 +2646,11 @@
<sha256 value="0168643266060ed928ef5a81823003ecfae79a9a8c0bbfd76f4201c6c9d771c5" origin="Generated by Gradle"/> <sha256 value="0168643266060ed928ef5a81823003ecfae79a9a8c0bbfd76f4201c6c9d771c5" origin="Generated by Gradle"/>
</artifact> </artifact>
</component> </component>
<component group="org.junit.platform" name="junit-platform-engine" version="1.9.2">
<artifact name="junit-platform-engine-1.9.2.jar">
<sha256 value="25f23dc535a091e9dc80c008faf29dcb92be902e6911f77a736fbaf019908367" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.knowm.xchange" name="xchange-binance" version="4.4.2"> <component group="org.knowm.xchange" name="xchange-binance" version="4.4.2">
<artifact name="xchange-binance-4.4.2.jar"> <artifact name="xchange-binance-4.4.2.jar">
<sha256 value="751a8cb76d75613ed38440a1a69e3a053e3cf869882b89eb8978b51c497111bb" origin="Generated by Gradle"/> <sha256 value="751a8cb76d75613ed38440a1a69e3a053e3cf869882b89eb8978b51c497111bb" origin="Generated by Gradle"/>

View file

@ -22,10 +22,8 @@ import haveno.common.crypto.KeyRing;
import haveno.common.crypto.KeyStorage; import haveno.common.crypto.KeyStorage;
import haveno.common.file.FileUtil; import haveno.common.file.FileUtil;
import haveno.common.proto.network.NetworkEnvelope; import haveno.common.proto.network.NetworkEnvelope;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -38,13 +36,10 @@ import java.security.cert.CertificateException;
public class EncryptionServiceTests { public class EncryptionServiceTests {
private static final Logger log = LoggerFactory.getLogger(EncryptionServiceTests.class); private static final Logger log = LoggerFactory.getLogger(EncryptionServiceTests.class);
@Rule
public ExpectedException thrown = ExpectedException.none();
private KeyRing keyRing; private KeyRing keyRing;
private File dir; private File dir;
@Before @BeforeEach
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException { public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
dir = File.createTempFile("temp_tests", ""); dir = File.createTempFile("temp_tests", "");
@ -56,7 +51,7 @@ public class EncryptionServiceTests {
keyRing = new KeyRing(keyStorage, null, true); keyRing = new KeyRing(keyStorage, null, true);
} }
@After @AfterEach
public void tearDown() throws IOException { public void tearDown() throws IOException {
FileUtil.deleteDirectory(dir); FileUtil.deleteDirectory(dir);
} }

View file

@ -18,10 +18,10 @@
package haveno.network.p2p; package haveno.network.p2p;
import haveno.network.p2p.network.LocalhostNetworkNode; import haveno.network.p2p.network.LocalhostNetworkNode;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -40,7 +40,7 @@ import java.util.concurrent.CountDownLatch;
// TODO deactivated because outdated // TODO deactivated because outdated
@SuppressWarnings({"UnusedAssignment", "EmptyMethod"}) @SuppressWarnings({"UnusedAssignment", "EmptyMethod"})
@Ignore @Disabled
public class PeerServiceTest { public class PeerServiceTest {
private static final Logger log = LoggerFactory.getLogger(PeerServiceTest.class); private static final Logger log = LoggerFactory.getLogger(PeerServiceTest.class);
private static final int MAX_CONNECTIONS = 100; private static final int MAX_CONNECTIONS = 100;
@ -53,7 +53,7 @@ public class PeerServiceTest {
private final List<DummySeedNode> seedNodes = new ArrayList<>(); private final List<DummySeedNode> seedNodes = new ArrayList<>();
private final String test_dummy_dir = "test_dummy_dir"; private final String test_dummy_dir = "test_dummy_dir";
@Before @BeforeEach
public void setup() throws InterruptedException { public void setup() throws InterruptedException {
LocalhostNetworkNode.setSimulateTorDelayTorNode(50); LocalhostNetworkNode.setSimulateTorDelayTorNode(50);
LocalhostNetworkNode.setSimulateTorDelayHiddenService(8); LocalhostNetworkNode.setSimulateTorDelayHiddenService(8);
@ -73,7 +73,7 @@ public class PeerServiceTest {
} }
} }
@After @AfterEach
public void tearDown() throws InterruptedException { public void tearDown() throws InterruptedException {
Thread.sleep(sleepTime); Thread.sleep(sleepTime);

View file

@ -18,8 +18,8 @@
package haveno.network.p2p.network; package haveno.network.p2p.network;
import haveno.network.p2p.TestUtils; import haveno.network.p2p.TestUtils;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -31,7 +31,7 @@ import java.util.concurrent.CountDownLatch;
// Connection establishment takes about 4 sec. // Connection establishment takes about 4 sec.
//TODO P2P network tests are outdated //TODO P2P network tests are outdated
@Ignore @Disabled
public class LocalhostNetworkNodeTest { public class LocalhostNetworkNodeTest {
private static final Logger log = LoggerFactory.getLogger(LocalhostNetworkNodeTest.class); private static final Logger log = LoggerFactory.getLogger(LocalhostNetworkNodeTest.class);

View file

@ -24,8 +24,8 @@ import com.google.common.util.concurrent.SettableFuture;
import haveno.network.p2p.TestUtils; import haveno.network.p2p.TestUtils;
import haveno.network.p2p.mocks.MockPayload; import haveno.network.p2p.mocks.MockPayload;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -40,7 +40,7 @@ import java.util.concurrent.CountDownLatch;
// Connection establishment takes about 4 sec. // Connection establishment takes about 4 sec.
//TODO P2P network tests are outdated //TODO P2P network tests are outdated
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@Ignore @Disabled
public class TorNetworkNodeTest { public class TorNetworkNodeTest {
private static final Logger log = LoggerFactory.getLogger(TorNetworkNodeTest.class); private static final Logger log = LoggerFactory.getLogger(TorNetworkNodeTest.class);
private CountDownLatch latch; private CountDownLatch latch;

View file

@ -22,19 +22,19 @@ import haveno.network.p2p.network.CloseConnectionReason;
import haveno.network.p2p.network.Connection; import haveno.network.p2p.network.Connection;
import haveno.network.p2p.network.InboundConnection; import haveno.network.p2p.network.InboundConnection;
import haveno.network.p2p.network.PeerType; import haveno.network.p2p.network.PeerType;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
@ -46,14 +46,14 @@ public class PeerManagerTest {
private int maxConnectionsPeer; private int maxConnectionsPeer;
private int maxConnectionsNonDirect; private int maxConnectionsNonDirect;
@Before @BeforeEach
public void setUp() throws IOException { public void setUp() throws IOException {
node = new MockNode(2); node = new MockNode(2);
maxConnectionsPeer = Math.max(4, (int) Math.round(node.getMaxConnections() * 1.3)); maxConnectionsPeer = Math.max(4, (int) Math.round(node.getMaxConnections() * 1.3));
maxConnectionsNonDirect = Math.max(8, (int) Math.round(node.getMaxConnections() * 1.7)); maxConnectionsNonDirect = Math.max(8, (int) Math.round(node.getMaxConnections() * 1.7));
} }
@After @AfterEach
public void tearDown() { public void tearDown() {
node.getPersistenceManager().shutdown(); node.getPersistenceManager().shutdown();
} }
@ -151,7 +151,7 @@ public class PeerManagerTest {
} }
@Test @Test
@Ignore @Disabled
public void testCheckMaxConnectionsNonDirectLimitExceeded() throws InterruptedException { public void testCheckMaxConnectionsNonDirectLimitExceeded() throws InterruptedException {
for (int i = 0; i < maxConnectionsNonDirect + 1; i++) { for (int i = 0; i < maxConnectionsNonDirect + 1; i++) {
node.addOutboundConnection(PeerType.INITIAL_DATA_EXCHANGE); node.addOutboundConnection(PeerType.INITIAL_DATA_EXCHANGE);

View file

@ -33,9 +33,8 @@ import haveno.network.p2p.storage.payload.CapabilityRequiringPayload;
import haveno.network.p2p.storage.payload.PersistableNetworkPayload; import haveno.network.p2p.storage.payload.PersistableNetworkPayload;
import haveno.network.p2p.storage.payload.ProtectedStorageEntry; import haveno.network.p2p.storage.payload.ProtectedStorageEntry;
import haveno.network.p2p.storage.payload.ProtectedStoragePayload; import haveno.network.p2p.storage.payload.ProtectedStoragePayload;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@ -46,6 +45,9 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -63,7 +65,7 @@ public class P2PDataStorageBuildGetDataResponseTest {
private NodeAddress localNodeAddress; private NodeAddress localNodeAddress;
@Before @BeforeEach
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
this.testState = new TestState(); this.testState = new TestState();
@ -144,13 +146,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/ known PNP, nothing is sent back // TESTCASE: Given a GetDataRequest w/ known PNP, nothing is sent back
@ -172,13 +174,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/o known PNP, send it back // TESTCASE: Given a GetDataRequest w/o known PNP, send it back
@ -198,13 +200,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().contains(onlyLocal)); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().contains(onlyLocal));
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/o known PNP, don't send more than truncation limit // TESTCASE: Given a GetDataRequest w/o known PNP, don't send more than truncation limit
@ -227,17 +229,17 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertTrue(outPNPTruncated.get()); assertTrue(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertEquals(1, getDataResponse.getPersistableNetworkPayloadSet().size()); assertEquals(1, getDataResponse.getPersistableNetworkPayloadSet().size());
Set<PersistableNetworkPayload> persistableNetworkPayloadSet = getDataResponse.getPersistableNetworkPayloadSet(); Set<PersistableNetworkPayload> persistableNetworkPayloadSet = getDataResponse.getPersistableNetworkPayloadSet();
// We use a set at the filter so it is not deterministic which item get truncated // We use a set at the filter so it is not deterministic which item get truncated
Assert.assertEquals(1, persistableNetworkPayloadSet.size()); assertEquals(1, persistableNetworkPayloadSet.size());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/o known PNP, but missing required capabilities, nothing is sent back // TESTCASE: Given a GetDataRequest w/o known PNP, but missing required capabilities, nothing is sent back
@ -259,13 +261,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/o known PNP that requires capabilities (and they match) send it back // TESTCASE: Given a GetDataRequest w/o known PNP that requires capabilities (and they match) send it back
@ -287,13 +289,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().contains(onlyLocal)); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().contains(onlyLocal));
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/ unknown PSE, nothing is sent back // TESTCASE: Given a GetDataRequest w/ unknown PSE, nothing is sent back
@ -312,13 +314,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/ known PSE, nothing is sent back // TESTCASE: Given a GetDataRequest w/ known PSE, nothing is sent back
@ -340,13 +342,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/o known PSE, send it back // TESTCASE: Given a GetDataRequest w/o known PSE, send it back
@ -365,13 +367,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().contains(onlyLocal)); assertTrue(getDataResponse.getDataSet().contains(onlyLocal));
} }
// TESTCASE: Given a GetDataRequest w/o known PNP, don't send more than truncation limit // TESTCASE: Given a GetDataRequest w/o known PNP, don't send more than truncation limit
@ -393,14 +395,14 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 1, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertTrue(outPSETruncated.get()); assertTrue(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertEquals(1, getDataResponse.getDataSet().size()); assertEquals(1, getDataResponse.getDataSet().size());
Assert.assertTrue( assertTrue(
getDataResponse.getDataSet().contains(onlyLocal1) getDataResponse.getDataSet().contains(onlyLocal1)
|| getDataResponse.getDataSet().contains(onlyLocal2)); || getDataResponse.getDataSet().contains(onlyLocal2));
} }
@ -422,13 +424,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().isEmpty()); assertTrue(getDataResponse.getDataSet().isEmpty());
} }
// TESTCASE: Given a GetDataRequest w/o known PNP that requires capabilities (and they match) send it back // TESTCASE: Given a GetDataRequest w/o known PNP that requires capabilities (and they match) send it back
@ -449,13 +451,13 @@ public class P2PDataStorageBuildGetDataResponseTest {
GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse( GetDataResponse getDataResponse = this.testState.mockedStorage.buildGetDataResponse(
getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities); getDataRequest, 2, outPNPTruncated, outPSETruncated, peerCapabilities);
Assert.assertFalse(outPNPTruncated.get()); assertFalse(outPNPTruncated.get());
Assert.assertFalse(outPSETruncated.get()); assertFalse(outPSETruncated.get());
Assert.assertEquals(1, getDataResponse.getRequestNonce()); assertEquals(1, getDataResponse.getRequestNonce());
Assert.assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse()); assertEquals(getDataRequest instanceof GetUpdatedDataRequest, getDataResponse.isGetUpdatedDataResponse());
Assert.assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app); assertEquals(getDataResponse.getSupportedCapabilities(), Capabilities.app);
Assert.assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty()); assertTrue(getDataResponse.getPersistableNetworkPayloadSet().isEmpty());
Assert.assertTrue(getDataResponse.getDataSet().contains(onlyLocal)); assertTrue(getDataResponse.getDataSet().contains(onlyLocal));
} }
} }

View file

@ -28,15 +28,16 @@ import haveno.network.p2p.storage.payload.MailboxStoragePayload;
import haveno.network.p2p.storage.payload.ProtectedMailboxStorageEntry; import haveno.network.p2p.storage.payload.ProtectedMailboxStorageEntry;
import haveno.network.p2p.storage.payload.ProtectedStorageEntry; import haveno.network.p2p.storage.payload.ProtectedStorageEntry;
import haveno.network.p2p.storage.payload.ProtectedStoragePayload; import haveno.network.p2p.storage.payload.ProtectedStoragePayload;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Optional; import java.util.Optional;
import static haveno.network.p2p.storage.TestState.SavedTestState; import static haveno.network.p2p.storage.TestState.SavedTestState;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -49,7 +50,7 @@ import static org.mockito.Mockito.when;
public class P2PDataStorageClientAPITest { public class P2PDataStorageClientAPITest {
private TestState testState; private TestState testState;
@Before @BeforeEach
public void setUp() { public void setUp() {
this.testState = new TestState(); this.testState = new TestState();
@ -67,9 +68,9 @@ public class P2PDataStorageClientAPITest {
ProtectedStorageEntry protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys); ProtectedStorageEntry protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys);
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry); SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
Assert.assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null)); assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null));
this.testState.verifyProtectedStorageAdd(beforeState, protectedStorageEntry, true, true, true, true); this.testState.assertProtectedStorageAdd(beforeState, protectedStorageEntry, true, true, true, true);
} }
// TESTCASE: Adding an entry from the getProtectedStorageEntry API of an existing item correctly updates the item // TESTCASE: Adding an entry from the getProtectedStorageEntry API of an existing item correctly updates the item
@ -80,13 +81,13 @@ public class P2PDataStorageClientAPITest {
ProtectedStoragePayload protectedStoragePayload = new ExpirableProtectedStoragePayloadStub(ownerKeys.getPublic()); ProtectedStoragePayload protectedStoragePayload = new ExpirableProtectedStoragePayloadStub(ownerKeys.getPublic());
ProtectedStorageEntry protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys); ProtectedStorageEntry protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys);
Assert.assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null)); assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null));
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry); SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys); protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys);
this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null); this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null);
this.testState.verifyProtectedStorageAdd(beforeState, protectedStorageEntry, true, true, true, true); this.testState.assertProtectedStorageAdd(beforeState, protectedStorageEntry, true, true, true, true);
} }
// TESTCASE: Adding an entry from the getProtectedStorageEntry API of an existing item (added from onMessage path) correctly updates the item // TESTCASE: Adding an entry from the getProtectedStorageEntry API of an existing item (added from onMessage path) correctly updates the item
@ -104,9 +105,9 @@ public class P2PDataStorageClientAPITest {
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry); SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys); protectedStorageEntry = this.testState.mockedStorage.getProtectedStorageEntry(protectedStoragePayload, ownerKeys);
Assert.assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null)); assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedStorageEntry, TestState.getTestNodeAddress(), null));
this.testState.verifyProtectedStorageAdd(beforeState, protectedStorageEntry, true, true, true, true); this.testState.assertProtectedStorageAdd(beforeState, protectedStorageEntry, true, true, true, true);
} }
// TESTCASE: Updating an entry from the getRefreshTTLMessage API correctly errors if the item hasn't been seen // TESTCASE: Updating an entry from the getRefreshTTLMessage API correctly errors if the item hasn't been seen
@ -119,7 +120,7 @@ public class P2PDataStorageClientAPITest {
RefreshOfferMessage refreshOfferMessage = this.testState.mockedStorage.getRefreshTTLMessage(protectedStoragePayload, ownerKeys); RefreshOfferMessage refreshOfferMessage = this.testState.mockedStorage.getRefreshTTLMessage(protectedStoragePayload, ownerKeys);
SavedTestState beforeState = this.testState.saveTestState(refreshOfferMessage); SavedTestState beforeState = this.testState.saveTestState(refreshOfferMessage);
Assert.assertFalse(this.testState.mockedStorage.refreshTTL(refreshOfferMessage, TestState.getTestNodeAddress())); assertFalse(this.testState.mockedStorage.refreshTTL(refreshOfferMessage, TestState.getTestNodeAddress()));
this.testState.verifyRefreshTTL(beforeState, refreshOfferMessage, false); this.testState.verifyRefreshTTL(beforeState, refreshOfferMessage, false);
} }
@ -141,7 +142,7 @@ public class P2PDataStorageClientAPITest {
this.testState.incrementClock(); this.testState.incrementClock();
SavedTestState beforeState = this.testState.saveTestState(refreshOfferMessage); SavedTestState beforeState = this.testState.saveTestState(refreshOfferMessage);
Assert.assertTrue(this.testState.mockedStorage.refreshTTL(refreshOfferMessage, TestState.getTestNodeAddress())); assertTrue(this.testState.mockedStorage.refreshTTL(refreshOfferMessage, TestState.getTestNodeAddress()));
this.testState.verifyRefreshTTL(beforeState, refreshOfferMessage, true); this.testState.verifyRefreshTTL(beforeState, refreshOfferMessage, true);
} }
@ -165,7 +166,7 @@ public class P2PDataStorageClientAPITest {
this.testState.incrementClock(); this.testState.incrementClock();
SavedTestState beforeState = this.testState.saveTestState(refreshOfferMessage); SavedTestState beforeState = this.testState.saveTestState(refreshOfferMessage);
Assert.assertTrue(this.testState.mockedStorage.refreshTTL(refreshOfferMessage, TestState.getTestNodeAddress())); assertTrue(this.testState.mockedStorage.refreshTTL(refreshOfferMessage, TestState.getTestNodeAddress()));
this.testState.verifyRefreshTTL(beforeState, refreshOfferMessage, true); this.testState.verifyRefreshTTL(beforeState, refreshOfferMessage, true);
} }
@ -182,7 +183,7 @@ public class P2PDataStorageClientAPITest {
this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic()); this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic());
SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry); SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry);
Assert.assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress())); assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress()));
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, false, false, true, true); this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, false, false, true, true);
} }
@ -198,13 +199,13 @@ public class P2PDataStorageClientAPITest {
ProtectedMailboxStorageEntry protectedMailboxStorageEntry = ProtectedMailboxStorageEntry protectedMailboxStorageEntry =
this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, senderKeys, receiverKeys.getPublic()); this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, senderKeys, receiverKeys.getPublic());
Assert.assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedMailboxStorageEntry, TestState.getTestNodeAddress(), null)); assertTrue(this.testState.mockedStorage.addProtectedStorageEntry(protectedMailboxStorageEntry, TestState.getTestNodeAddress(), null));
protectedMailboxStorageEntry = protectedMailboxStorageEntry =
this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic()); this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic());
SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry); SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry);
Assert.assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress())); assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress()));
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true, true); this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true, true);
} }
@ -231,7 +232,7 @@ public class P2PDataStorageClientAPITest {
this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic()); this.testState.mockedStorage.getMailboxDataWithSignedSeqNr(mailboxStoragePayload, receiverKeys, receiverKeys.getPublic());
SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry); SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry);
Assert.assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress())); assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress()));
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true, true); this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true, true);
} }

Some files were not shown because too many files have changed in this diff Show more