Skip to content

Commit

Permalink
Update JUnit version and dependencies
Browse files Browse the repository at this point in the history
Migrated tests from JUnit 4 to JUnit 5 and updated test dependencies in build.gradle. Removed deprecated imports and updated test assertions to use JUnit Jupiter API and AssertJ. Also, updated Gradle wrapper to version 8.10.2 for improved compatibility.
  • Loading branch information
satran004 committed Nov 15, 2024
1 parent 6e0787d commit 68ed926
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 85 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ dependencies {
compileOnly 'org.projectlombok:lombok:1.18.34'

annotationProcessor 'org.projectlombok:lombok:1.18.34'
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.3'
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation 'org.mockito:mockito-inline:4.6.1'
testImplementation 'org.mockito:mockito-junit-jupiter:4.6.1'
testImplementation('org.assertj:assertj-core:3.23.1')
testRuntimeOnly 'org.slf4j:slf4j-log4j12:1.7.36'
}

sourceSets.main.java.srcDirs('src/main/gen', 'src/main/idea')
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.bloxbean.intelliada.idea.configuration.common;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;

public class HeaderParserUtilTest {

Expand All @@ -15,8 +14,8 @@ public void parseHeaders() {
Map<String, String> map = HeaderParserUtil.parseHeaders(str);

System.out.println(map);
assertThat(map.get("key1"), is("value1"));
assertThat(map.get("key2"), is("value%$_@="));
assertThat(map.get("key3"), is("Hello world"));
assertThat(map.get("key1")).isEqualTo("value1");
assertThat(map.get("key2")).isEqualTo("value%$_@=");
assertThat(map.get("key3")).isEqualTo("Hello world");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.bloxbean.intelliada.idea.core.util;

import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

public class CLIProviderUtilTest extends TestCase {
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CLIProviderUtilTest {

@Test
public void testDaedalusMacMainnetPath() {
String path = "/Applications/Daedalus Mainnet";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.bloxbean.intelliada.idea.core.util;

import org.junit.Test;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

public class NodeTypeTest {

@Test
public void valueOf() {
NodeType nodeType = NodeType.lookupByName(NodeType.CARDANO_WALLET.name());
assertNotNull(nodeType);

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bloxbean.intelliada.idea.nodeint;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class NetworkInfoTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bloxbean.intelliada.idea.nodeint.service.impl.yaciprovider;

import com.bloxbean.intelliada.idea.nodeint.service.api.LogListener;

public class DummyLogListener implements LogListener {

public DummyLogListener() {

}

@Override
public void info(String msg) {

}

@Override
public void error(String msg) {

}

@Override
public void warn(String msg) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import com.bloxbean.intelliada.idea.configuration.model.RemoteNode;
import com.bloxbean.intelliada.idea.nodeint.exception.ApiCallException;
import com.bloxbean.intelliada.idea.nodeint.exception.TargetNodeNotConfigured;
import com.bloxbean.intelliada.idea.nodeint.service.api.LogListener;
import com.bloxbean.intelliada.idea.nodeint.service.api.model.AssetBalance;
import junit.framework.TestCase;
import org.junit.jupiter.api.Disabled;

import java.util.List;

public class YaciAccountServiceImplTest extends TestCase {
import static org.junit.jupiter.api.Assertions.assertTrue;

public class YaciAccountServiceImplTest {

public static final String BASE_URL = "http://localhost:8080/api/v1/";

@Disabled
public void testGetAdaBalance() throws TargetNodeNotConfigured {
var remoteNode = new RemoteNode();
remoteNode.setApiEndpoint(BASE_URL);
Expand All @@ -23,6 +25,7 @@ public void testGetAdaBalance() throws TargetNodeNotConfigured {
assertTrue(result.isSuccessful());
}

@Disabled
public void testAssets() throws TargetNodeNotConfigured, ApiCallException {
var remoteNode = new RemoteNode();
remoteNode.setApiEndpoint("http://localhost:8080/api/v1/");
Expand All @@ -32,21 +35,4 @@ public void testAssets() throws TargetNodeNotConfigured, ApiCallException {
System.out.println(assetBalances);
}

class DummyLogListener implements LogListener {

@Override
public void info(String msg) {

}

@Override
public void error(String msg) {

}

@Override
public void warn(String msg) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import org.junit.Test;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

public class ScriptInfoTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.bloxbean.intelliada.idea.scripts.util;

import com.bloxbean.cardano.client.transaction.spec.script.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.*;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.assertThat;

public class ScriptParserTest {
private String scriptAllFile1 = "script-all-1.json";
Expand All @@ -23,23 +21,23 @@ public void parseSimpleScriptAll() throws IOException {
NativeScript script = ScriptParser.parse(loadJsonMetadata(scriptAllFile1));
ScriptAll scriptAll = (ScriptAll) script;

assertThat(scriptAll.getType(), is(ScriptType.all));
assertThat(scriptAll.getScripts().size(), is(3));
assertThat(scriptAll.getScripts().get(0), is(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a")));
assertThat(scriptAll.getScripts().get(1), is(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756")));
assertThat(scriptAll.getScripts().get(2), is(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d")));
assertThat(scriptAll.getType()).isEqualTo(ScriptType.all);
assertThat(scriptAll.getScripts().size()).isEqualTo(3);
assertThat(scriptAll.getScripts().get(0)).isEqualTo(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a"));
assertThat(scriptAll.getScripts().get(1)).isEqualTo(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756"));
assertThat(scriptAll.getScripts().get(2)).isEqualTo(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d"));
}

@Test
public void parseSimpleScriptAny() throws IOException {
NativeScript script = ScriptParser.parse(loadJsonMetadata(scriptAnyFile1));
ScriptAny scriptAny = (ScriptAny) script;

assertThat(scriptAny.getType(), is(ScriptType.any));
assertThat(scriptAny.getScripts().size(), is(3));
assertThat(scriptAny.getScripts().get(0), is(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a")));
assertThat(scriptAny.getScripts().get(1), is(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756")));
assertThat(scriptAny.getScripts().get(2), is(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d")));
assertThat(scriptAny.getType()).isEqualTo(ScriptType.any);
assertThat(scriptAny.getScripts().size()).isEqualTo(3);
assertThat(scriptAny.getScripts().get(0)).isEqualTo(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a"));
assertThat(scriptAny.getScripts().get(1)).isEqualTo(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756"));
assertThat(scriptAny.getScripts().get(2)).isEqualTo(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d"));
}

@Test
Expand All @@ -48,12 +46,12 @@ public void parseSimpleScriptAtLeast() throws IOException {

ScriptAtLeast scriptAtLeast = (ScriptAtLeast) script;

assertThat(scriptAtLeast.getType(), is(ScriptType.atLeast));
assertThat(scriptAtLeast.getRequired(), is(2));
assertThat(scriptAtLeast.getScripts().size(), is(3));
assertThat(scriptAtLeast.getScripts().get(0), is(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a")));
assertThat(scriptAtLeast.getScripts().get(1), is(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756")));
assertThat(scriptAtLeast.getScripts().get(2), is(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d")));
assertThat(scriptAtLeast.getType()).isEqualTo(ScriptType.atLeast);
assertThat(scriptAtLeast.getRequired().intValue()).isEqualTo(2);
assertThat(scriptAtLeast.getScripts().size()).isEqualTo(3);
assertThat(scriptAtLeast.getScripts().get(0)).isEqualTo(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a"));
assertThat(scriptAtLeast.getScripts().get(1)).isEqualTo(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756"));
assertThat(scriptAtLeast.getScripts().get(2)).isEqualTo(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d"));
}

@Test
Expand All @@ -62,8 +60,8 @@ public void parseSimpleScriptBefore() throws IOException {

RequireTimeBefore requireTimeBefore = (RequireTimeBefore) script;

assertThat(requireTimeBefore.getType(), is(ScriptType.before));
assertThat(requireTimeBefore.getSlot(), is(29273366L));
assertThat(requireTimeBefore.getType()).isEqualTo(ScriptType.before);
assertThat(requireTimeBefore.getSlot().longValue()).isEqualTo(29273366L);
}

@Test
Expand All @@ -72,48 +70,48 @@ public void parseSimpleScriptAfter() throws IOException {

RequireTimeAfter requireTimeAfter = (RequireTimeAfter) script;

assertThat(requireTimeAfter.getType(), is(ScriptType.after));
assertThat(requireTimeAfter.getSlot(), is(29273366L));
assertThat(requireTimeAfter.getType()).isEqualTo(ScriptType.after);
assertThat(requireTimeAfter.getSlot().longValue()).isEqualTo(29273366L);
}

@Test
public void parseNestedScript1() throws IOException {
NativeScript script = ScriptParser.parse(loadJsonMetadata(nestedScript1));
ScriptAll scriptAll = (ScriptAll) script;

assertThat(scriptAll.getType(), is(ScriptType.all));
assertThat(scriptAll.getScripts().size(), is(3));
assertThat(scriptAll.getScripts().get(0), is(new RequireTimeBefore(29273366)));
assertThat(scriptAll.getType()).isEqualTo((ScriptType.all));
assertThat(scriptAll.getScripts().size()).isEqualTo(3);
assertThat(scriptAll.getScripts().get(0)).isEqualTo(new RequireTimeBefore(29273366));

ScriptAtLeast scriptAtLeast = (ScriptAtLeast) scriptAll.getScripts().get(1);
assertThat(scriptAtLeast, notNullValue());
assertThat(scriptAtLeast.getRequired(), is(2));
assertThat(scriptAtLeast.getScripts().get(0), is(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a")));
assertThat(scriptAtLeast.getScripts().get(1), is(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756")));
assertThat(scriptAtLeast.getScripts().get(2), is(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d")));
assertThat(scriptAtLeast).isNotNull();
assertThat(scriptAtLeast.getRequired().intValue()).isEqualTo(2);
assertThat(scriptAtLeast.getScripts().get(0)).isEqualTo((new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a")));
assertThat(scriptAtLeast.getScripts().get(1)).isEqualTo((new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756")));
assertThat(scriptAtLeast.getScripts().get(2)).isEqualTo(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d"));

assertThat(scriptAll.getScripts().get(2), is(new ScriptPubkey("6b021a31fe9fddc92a234ea67ffcb1830a5e1f820c11db9cee226bc5")));
assertThat(scriptAll.getScripts().get(2)).isEqualTo(new ScriptPubkey("6b021a31fe9fddc92a234ea67ffcb1830a5e1f820c11db9cee226bc5"));
}

@Test
public void parseNestedScript2() throws IOException {
NativeScript script = ScriptParser.parse(loadJsonMetadata(nestedScript2));
ScriptAtLeast parentScript = (ScriptAtLeast) script;

assertThat(parentScript.getType(), is(ScriptType.atLeast));
assertThat(parentScript.getRequired(), is(3));
assertThat(parentScript.getType()).isEqualTo(ScriptType.atLeast);
assertThat(parentScript.getRequired().intValue()).isEqualTo(3);

assertThat(parentScript.getScripts().size(), is(3));
assertThat(parentScript.getScripts().get(0), is(new RequireTimeAfter(29273366)));
assertThat(parentScript.getScripts().size()).isEqualTo(3);
assertThat(parentScript.getScripts().get(0)).isEqualTo(new RequireTimeAfter(29273366));

ScriptAtLeast scriptAtLeast = (ScriptAtLeast) parentScript.getScripts().get(1);
assertThat(scriptAtLeast, notNullValue());
assertThat(scriptAtLeast.getRequired(), is(2));
assertThat(scriptAtLeast.getScripts().get(0), is(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a")));
assertThat(scriptAtLeast.getScripts().get(1), is(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756")));
assertThat(scriptAtLeast.getScripts().get(2), is(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d")));
assertThat(scriptAtLeast).isNotNull();
assertThat(scriptAtLeast.getRequired().intValue()).isEqualTo(2);
assertThat(scriptAtLeast.getScripts().get(0)).isEqualTo(new ScriptPubkey("e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a"));
assertThat(scriptAtLeast.getScripts().get(1)).isEqualTo(new ScriptPubkey("a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756"));
assertThat(scriptAtLeast.getScripts().get(2)).isEqualTo(new ScriptPubkey("0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d"));

assertThat(parentScript.getScripts().get(2), is(new ScriptPubkey("6b021a31fe9fddc92a234ea67ffcb1830a5e1f820c11db9cee226bc5")));
assertThat(parentScript.getScripts().get(2)).isEqualTo(new ScriptPubkey("6b021a31fe9fddc92a234ea67ffcb1830a5e1f820c11db9cee226bc5"));
}

private String loadJsonMetadata(String fileName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.bloxbean.intelliada.idea.util;

import com.bloxbean.cardano.client.transaction.model.PaymentTransaction;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.math.BigInteger;

import static com.bloxbean.intelliada.idea.util.AdaConversionUtil.LOVELACE;
import static org.junit.Assert.*;

public class JsonUtilTest {

Expand Down

0 comments on commit 68ed926

Please sign in to comment.