mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-23 04:36:50 +00:00
Adding support for BitcoinyTBD, version parsing and crosschain offer message building.
This commit is contained in:
140
src/test/java/org/qortal/test/api/CrossChainUtilsTests.java
Normal file
140
src/test/java/org/qortal/test/api/CrossChainUtilsTests.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package org.qortal.test.api;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.test.common.ApiCommon;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CrossChainUtilsTests extends ApiCommon {
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters1() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("", 1, ',');
|
||||
|
||||
Assert.assertEquals("", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters2() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("0.17.0", 1, ',');
|
||||
|
||||
Assert.assertEquals("0.17.0", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters3() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("0.17.0", 1, '.');
|
||||
|
||||
Assert.assertEquals("0.17", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters4() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("0.17.0", 2, '.');
|
||||
|
||||
Assert.assertEquals("0.17.0", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters5() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("0.17.0", 10, '.');
|
||||
|
||||
Assert.assertEquals("0.17.0", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters6() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("0.17.0", -1, '.');
|
||||
|
||||
Assert.assertEquals("0.17.0", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceDelimeters7() {
|
||||
|
||||
String string = CrossChainUtils.reduceDelimeters("abcdef abcdef", 1, 'd');
|
||||
|
||||
Assert.assertEquals("abcdef abc", string);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVersionDecimalThrowNumberFormatExceptionTrue() {
|
||||
|
||||
boolean thrown = false;
|
||||
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("x", "v");
|
||||
double versionDecimal = CrossChainUtils.getVersionDecimal(new JSONObject(map), "x");
|
||||
}
|
||||
catch( NumberFormatException e ) {
|
||||
thrown = true;
|
||||
}
|
||||
|
||||
Assert.assertTrue(thrown);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVersionDecimalThrowNullPointerExceptionTrue() {
|
||||
|
||||
boolean thrown = false;
|
||||
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
double versionDecimal = CrossChainUtils.getVersionDecimal(new JSONObject(map), "x");
|
||||
}
|
||||
catch( NullPointerException e ) {
|
||||
thrown = true;
|
||||
}
|
||||
|
||||
Assert.assertTrue(thrown);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVersionDecimalThrowAnyExceptionFalse() {
|
||||
|
||||
boolean thrown = false;
|
||||
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("x", "5");
|
||||
double versionDecimal = CrossChainUtils.getVersionDecimal(new JSONObject(map), "x");
|
||||
}
|
||||
catch( NullPointerException | NumberFormatException e ) {
|
||||
thrown = true;
|
||||
}
|
||||
|
||||
Assert.assertFalse(thrown);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVersionDecimal1() {
|
||||
|
||||
boolean thrown = false;
|
||||
|
||||
double versionDecimal = 0d;
|
||||
|
||||
try {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("x", "5.0.0");
|
||||
versionDecimal = CrossChainUtils.getVersionDecimal(new JSONObject(map), "x");
|
||||
}
|
||||
catch( NullPointerException | NumberFormatException e ) {
|
||||
thrown = true;
|
||||
}
|
||||
|
||||
Assert.assertEquals(5, versionDecimal, 0.001);
|
||||
Assert.assertFalse(thrown);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user