diff --git a/buildSrc/src/main/kotlin/jadx-java.gradle.kts b/buildSrc/src/main/kotlin/jadx-java.gradle.kts index c2c4e49e7..98c18e214 100644 --- a/buildSrc/src/main/kotlin/jadx-java.gradle.kts +++ b/buildSrc/src/main/kotlin/jadx-java.gradle.kts @@ -17,9 +17,8 @@ dependencies { compileOnly("org.jetbrains:annotations:24.1.0") testImplementation("ch.qos.logback:logback-classic:1.5.6") - testImplementation("org.hamcrest:hamcrest-library:2.2") - testImplementation("org.mockito:mockito-core:5.12.0") testImplementation("org.assertj:assertj-core:3.26.3") + testImplementation("org.mockito:mockito-core:5.12.0") testImplementation("org.junit.jupiter:junit-jupiter:5.10.3") testRuntimeOnly("org.junit.platform:junit-platform-launcher") diff --git a/jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java b/jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java index 54edbd5fd..8de22c50d 100644 --- a/jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java +++ b/jadx-cli/src/test/java/jadx/cli/JadxCLIArgsTest.java @@ -3,14 +3,12 @@ package jadx.cli; import java.util.Collections; import java.util.Map; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static jadx.core.utils.Utils.newConstStringMap; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static org.assertj.core.api.Assertions.assertThat; public class JadxCLIArgsTest { @@ -18,38 +16,38 @@ public class JadxCLIArgsTest { @Test public void testInvertedBooleanOption() { - assertThat(parse("--no-replace-consts").isReplaceConsts(), is(false)); - assertThat(parse("").isReplaceConsts(), is(true)); + assertThat(parse("--no-replace-consts").isReplaceConsts()).isFalse(); + assertThat(parse("").isReplaceConsts()).isTrue(); } @Test public void testEscapeUnicodeOption() { - assertThat(parse("--escape-unicode").isEscapeUnicode(), is(true)); - assertThat(parse("").isEscapeUnicode(), is(false)); + assertThat(parse("--escape-unicode").isEscapeUnicode()).isTrue(); + assertThat(parse("").isEscapeUnicode()).isFalse(); } @Test public void testSrcOption() { - assertThat(parse("--no-src").isSkipSources(), is(true)); - assertThat(parse("-s").isSkipSources(), is(true)); - assertThat(parse("").isSkipSources(), is(false)); + assertThat(parse("--no-src").isSkipSources()).isTrue(); + assertThat(parse("-s").isSkipSources()).isTrue(); + assertThat(parse("").isSkipSources()).isFalse(); } @Test public void testOptionsOverride() { - assertThat(override(new JadxCLIArgs(), "--no-imports").isUseImports(), is(false)); - assertThat(override(new JadxCLIArgs(), "--no-debug-info").isDebugInfo(), is(false)); - assertThat(override(new JadxCLIArgs(), "").isUseImports(), is(true)); + assertThat(override(new JadxCLIArgs(), "--no-imports").isUseImports()).isFalse(); + assertThat(override(new JadxCLIArgs(), "--no-debug-info").isDebugInfo()).isFalse(); + assertThat(override(new JadxCLIArgs(), "").isUseImports()).isTrue(); JadxCLIArgs args = new JadxCLIArgs(); args.useImports = false; - assertThat(override(args, "--no-imports").isUseImports(), is(false)); + assertThat(override(args, "--no-imports").isUseImports()).isFalse(); args.debugInfo = false; - assertThat(override(args, "--no-debug-info").isDebugInfo(), is(false)); + assertThat(override(args, "--no-debug-info").isDebugInfo()).isFalse(); args = new JadxCLIArgs(); args.useImports = false; - assertThat(override(args, "").isUseImports(), is(false)); + assertThat(override(args, "").isUseImports()).isFalse(); } @Test @@ -83,7 +81,7 @@ public class JadxCLIArgsTest { JadxCLIArgs args = new JadxCLIArgs(); args.pluginOptions = baseMap; Map resultMap = override(args, providedArgs).getPluginOptions(); - assertThat(resultMap, Matchers.equalTo(expectedMap)); + assertThat(resultMap).isEqualTo(expectedMap); } private JadxCLIArgs parse(String... args) { @@ -91,15 +89,15 @@ public class JadxCLIArgsTest { } private JadxCLIArgs parse(JadxCLIArgs jadxArgs, String... args) { - boolean res = jadxArgs.processArgs(args); - assertThat(res, is(true)); - LOG.info("Jadx args: {}", jadxArgs.toJadxArgs()); - return jadxArgs; + return check(jadxArgs, jadxArgs.processArgs(args)); } private JadxCLIArgs override(JadxCLIArgs jadxArgs, String... args) { - boolean res = jadxArgs.overrideProvided(args); - assertThat(res, is(true)); + return check(jadxArgs, jadxArgs.overrideProvided(args)); + } + + private static JadxCLIArgs check(JadxCLIArgs jadxArgs, boolean res) { + assertThat(res).isTrue(); LOG.info("Jadx args: {}", jadxArgs.toJadxArgs()); return jadxArgs; } diff --git a/jadx-cli/src/test/java/jadx/cli/RenameConverterTest.java b/jadx-cli/src/test/java/jadx/cli/RenameConverterTest.java index 3b0940fce..b000a13c9 100644 --- a/jadx-cli/src/test/java/jadx/cli/RenameConverterTest.java +++ b/jadx-cli/src/test/java/jadx/cli/RenameConverterTest.java @@ -9,9 +9,8 @@ import jadx.api.JadxArgs.RenameEnum; import jadx.cli.JadxCLIArgs.RenameConverter; import jadx.core.utils.exceptions.JadxArgsValidateException; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; public class RenameConverterTest { @@ -25,16 +24,16 @@ public class RenameConverterTest { @Test public void all() { Set set = converter.convert("all"); - assertEquals(3, set.size()); - assertTrue(set.contains(RenameEnum.CASE)); - assertTrue(set.contains(RenameEnum.VALID)); - assertTrue(set.contains(RenameEnum.PRINTABLE)); + assertThat(set).hasSize(3); + assertThat(set).contains(RenameEnum.CASE); + assertThat(set).contains(RenameEnum.VALID); + assertThat(set).contains(RenameEnum.PRINTABLE); } @Test public void none() { Set set = converter.convert("none"); - assertTrue(set.isEmpty()); + assertThat(set).isEmpty(); } @Test @@ -43,7 +42,6 @@ public class RenameConverterTest { () -> converter.convert("wrong"), "Expected convert() to throw, but it didn't"); - assertEquals("'wrong' is unknown for parameter someParam, possible values are case, valid, printable", - thrown.getMessage()); + assertThat(thrown.getMessage()).isEqualTo("'wrong' is unknown for parameter someParam, possible values are case, valid, printable"); } } diff --git a/jadx-cli/src/test/java/jadx/cli/TestInput.java b/jadx-cli/src/test/java/jadx/cli/TestInput.java index 22f180203..c4d1a4789 100644 --- a/jadx-cli/src/test/java/jadx/cli/TestInput.java +++ b/jadx-cli/src/test/java/jadx/cli/TestInput.java @@ -68,7 +68,7 @@ public class TestInput { 3, (file, attr) -> file.getFileName().toString().equalsIgnoreCase("AndroidManifest.xml")) .collect(Collectors.toList()); - assertThat(files.isEmpty()).isFalse(); + assertThat(files).isNotEmpty(); } private void decompile(String tmpDirName, String... inputSamples) throws URISyntaxException, IOException { diff --git a/jadx-core/src/main/java/jadx/api/JadxDecompiler.java b/jadx-core/src/main/java/jadx/api/JadxDecompiler.java index 1079f2c82..39678d2ea 100644 --- a/jadx-core/src/main/java/jadx/api/JadxDecompiler.java +++ b/jadx-core/src/main/java/jadx/api/JadxDecompiler.java @@ -196,7 +196,7 @@ public final class JadxDecompiler implements Closeable { try { resourcesLoader.close(); } catch (Exception e) { - LOG.error("Failed to close resource loader: " + resourcesLoader, e); + LOG.error("Failed to close resource loader: {}", resourcesLoader, e); } } customResourcesLoaders.clear(); diff --git a/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java b/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java index c3a2177de..b6a894517 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java @@ -123,7 +123,7 @@ public class FileUtils { try { deleteDir(dir); } catch (Exception e) { - LOG.error("Failed to delete dir: " + dir.toAbsolutePath(), e); + LOG.error("Failed to delete dir: {}", dir.toAbsolutePath(), e); } } } diff --git a/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java b/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java index 7bb6cd15f..f1ec8370d 100644 --- a/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java +++ b/jadx-core/src/test/java/jadx/api/JadxArgsValidatorOutDirsTest.java @@ -7,8 +7,7 @@ import org.slf4j.LoggerFactory; import jadx.core.utils.files.FileUtils; import static jadx.core.utils.files.FileUtils.toFile; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class JadxArgsValidatorOutDirsTest { @@ -59,9 +58,9 @@ public class JadxArgsValidatorOutDirsTest { private void checkOutDirs(String outDir, String srcDir, String resDir) { JadxArgsValidator.validate(new JadxDecompiler(args)); LOG.debug("Got dirs: out={}, src={}, res={}", args.getOutDir(), args.getOutDirSrc(), args.getOutDirRes()); - assertThat(args.getOutDir(), is(toFile(outDir))); - assertThat(args.getOutDirSrc(), is(toFile(srcDir))); - assertThat(args.getOutDirRes(), is(toFile(resDir))); + assertThat(args.getOutDir()).isEqualTo(toFile(outDir)); + assertThat(args.getOutDirSrc()).isEqualTo(toFile(srcDir)); + assertThat(args.getOutDirRes()).isEqualTo(toFile(resDir)); } private JadxArgs makeArgs() { diff --git a/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java b/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java index adbd5ce1b..75685655f 100644 --- a/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java +++ b/jadx-core/src/test/java/jadx/api/JadxDecompilerTest.java @@ -6,14 +6,12 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import jadx.core.utils.files.FileUtils; import jadx.plugins.input.dex.DexInputPlugin; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class JadxDecompilerTest { @@ -37,8 +35,8 @@ public class JadxDecompilerTest { System.out.println(cls.getCode()); } - assertThat(jadx.getClasses(), Matchers.hasSize(3)); - assertThat(jadx.getErrorsCount(), Matchers.is(0)); + assertThat(jadx.getClasses()).hasSize(3); + assertThat(jadx.getErrorsCount()).isEqualTo(0); } } @@ -51,8 +49,8 @@ public class JadxDecompilerTest { for (JavaClass cls : jadx.getClasses()) { System.out.println(cls.getCode()); } - assertThat(jadx.getClasses(), Matchers.hasSize(1)); - assertThat(jadx.getErrorsCount(), Matchers.is(0)); + assertThat(jadx.getClasses()).hasSize(1); + assertThat(jadx.getErrorsCount()).isEqualTo(0); } } @@ -60,7 +58,7 @@ public class JadxDecompilerTest { public static File getFileFromSampleDir(String fileName) { URL resource = JadxDecompilerTest.class.getClassLoader().getResource(TEST_SAMPLES_DIR + fileName); - assertThat(resource, notNullValue()); + assertThat(resource).isNotNull(); String pathStr = resource.getFile(); return new File(pathStr); } diff --git a/jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java b/jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java index 14278a707..9e8d2edbe 100644 --- a/jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java +++ b/jadx-core/src/test/java/jadx/core/deobf/NameMapperTest.java @@ -5,34 +5,33 @@ import org.junit.jupiter.api.Test; import static jadx.core.deobf.NameMapper.isValidIdentifier; import static jadx.core.deobf.NameMapper.removeInvalidChars; import static jadx.core.deobf.NameMapper.removeInvalidCharsMiddle; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class NameMapperTest { @Test public void validIdentifiers() { - assertThat(isValidIdentifier("ACls"), is(true)); + assertThat(isValidIdentifier("ACls")).isTrue(); } @Test public void notValidIdentifiers() { - assertThat(isValidIdentifier("1cls"), is(false)); - assertThat(isValidIdentifier("-cls"), is(false)); - assertThat(isValidIdentifier("A-cls"), is(false)); + assertThat(isValidIdentifier("1cls")).isFalse(); + assertThat(isValidIdentifier("-cls")).isFalse(); + assertThat(isValidIdentifier("A-cls")).isFalse(); } @Test public void testRemoveInvalidCharsMiddle() { - assertThat(removeInvalidCharsMiddle("1cls"), is("1cls")); - assertThat(removeInvalidCharsMiddle("-cls"), is("cls")); - assertThat(removeInvalidCharsMiddle("A-cls"), is("Acls")); + assertThat(removeInvalidCharsMiddle("1cls")).isEqualTo("1cls"); + assertThat(removeInvalidCharsMiddle("-cls")).isEqualTo("cls"); + assertThat(removeInvalidCharsMiddle("A-cls")).isEqualTo("Acls"); } @Test public void testRemoveInvalidChars() { - assertThat(removeInvalidChars("1cls", "C"), is("C1cls")); - assertThat(removeInvalidChars("-cls", "C"), is("cls")); - assertThat(removeInvalidChars("A-cls", "C"), is("Acls")); + assertThat(removeInvalidChars("1cls", "C")).isEqualTo("C1cls"); + assertThat(removeInvalidChars("-cls", "C")).isEqualTo("cls"); + assertThat(removeInvalidChars("A-cls", "C")).isEqualTo("Acls"); } } diff --git a/jadx-core/src/test/java/jadx/core/dex/info/AccessInfoTest.java b/jadx-core/src/test/java/jadx/core/dex/info/AccessInfoTest.java index f65b92a9c..8170c6ca2 100644 --- a/jadx-core/src/test/java/jadx/core/dex/info/AccessInfoTest.java +++ b/jadx-core/src/test/java/jadx/core/dex/info/AccessInfoTest.java @@ -5,9 +5,8 @@ import org.junit.jupiter.api.Test; import jadx.api.plugins.input.data.AccessFlags; import jadx.core.dex.info.AccessInfo.AFType; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertSame; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class AccessInfoTest { @@ -16,17 +15,17 @@ public class AccessInfoTest { AccessInfo accessInfo = new AccessInfo(AccessFlags.PROTECTED | AccessFlags.STATIC, AFType.METHOD); AccessInfo result = accessInfo.changeVisibility(AccessFlags.PUBLIC); - assertThat(result.isPublic(), is(true)); - assertThat(result.isPrivate(), is(false)); - assertThat(result.isProtected(), is(false)); + assertThat(result.isPublic()).isTrue(); + assertThat(result.isPrivate()).isFalse(); + assertThat(result.isProtected()).isFalse(); - assertThat(result.isStatic(), is(true)); + assertThat(result.isStatic()).isTrue(); } @Test public void changeVisibilityNoOp() { AccessInfo accessInfo = new AccessInfo(AccessFlags.PUBLIC, AFType.METHOD); AccessInfo result = accessInfo.changeVisibility(AccessFlags.PUBLIC); - assertSame(accessInfo, result); + assertThat(result).isSameAs(accessInfo); } } diff --git a/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java b/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java index 2a99d682b..8696815e2 100644 --- a/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java +++ b/jadx-core/src/test/java/jadx/core/dex/instructions/args/ArgTypeTest.java @@ -1,33 +1,30 @@ package jadx.core.dex.instructions.args; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.core.dex.instructions.args.ArgType.WildcardBound.SUPER; +import static jadx.core.dex.instructions.args.ArgType.generic; +import static jadx.core.dex.instructions.args.ArgType.genericType; +import static jadx.core.dex.instructions.args.ArgType.wildcard; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; class ArgTypeTest { - private static final Logger LOG = LoggerFactory.getLogger(ArgTypeTest.class); - @Test public void testEqualsOfGenericTypes() { ArgType first = ArgType.generic("java.lang.List", ArgType.STRING); ArgType second = ArgType.generic("Ljava/lang/List;", ArgType.STRING); - assertEquals(first, second); + assertThat(first).isEqualTo(second); } @Test void testContainsGenericType() { - ArgType wildcard = ArgType.wildcard(ArgType.genericType("T"), ArgType.WildcardBound.SUPER); - assertTrue(wildcard.containsTypeVariable()); + ArgType wildcard = wildcard(genericType("T"), SUPER); + assertThat(wildcard.containsTypeVariable()).isTrue(); - ArgType type = ArgType.generic("java.lang.List", wildcard); - assertTrue(type.containsTypeVariable()); + ArgType type = generic("java.lang.List", wildcard); + assertThat(type.containsTypeVariable()).isTrue(); } @Test @@ -36,11 +33,11 @@ class ArgTypeTest { ArgType base = ArgType.generic("java.util.Map", genericTypes); ArgType genericInner = ArgType.outerGeneric(base, ArgType.generic("Entry", genericTypes)); - assertThat(genericInner.toString(), is("java.util.Map$Entry")); - assertTrue(genericInner.containsTypeVariable()); + assertThat(genericInner.toString()).isEqualTo("java.util.Map$Entry"); + assertThat(genericInner.containsTypeVariable()).isTrue(); ArgType genericInner2 = ArgType.outerGeneric(base, ArgType.object("Entry")); - assertThat(genericInner2.toString(), is("java.util.Map$Entry")); - assertTrue(genericInner2.containsTypeVariable()); + assertThat(genericInner2.toString()).isEqualTo("java.util.Map$Entry"); + assertThat(genericInner2.containsTypeVariable()).isTrue(); } } diff --git a/jadx-core/src/test/java/jadx/core/dex/nodes/utils/TypeUtilsTest.java b/jadx-core/src/test/java/jadx/core/dex/nodes/utils/TypeUtilsTest.java index b349228ae..e0fecfb45 100644 --- a/jadx-core/src/test/java/jadx/core/dex/nodes/utils/TypeUtilsTest.java +++ b/jadx-core/src/test/java/jadx/core/dex/nodes/utils/TypeUtilsTest.java @@ -18,7 +18,7 @@ import static jadx.core.dex.instructions.args.ArgType.generic; import static jadx.core.dex.instructions.args.ArgType.genericType; import static jadx.core.dex.instructions.args.ArgType.object; import static jadx.core.dex.instructions.args.ArgType.outerGeneric; -import static org.assertj.core.api.Assertions.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; class TypeUtilsTest { private TypeUtils typeUtils; diff --git a/jadx-core/src/test/java/jadx/core/dex/visitors/typeinference/TypeCompareTest.java b/jadx-core/src/test/java/jadx/core/dex/visitors/typeinference/TypeCompareTest.java index cd6d71f49..2bfc2180d 100644 --- a/jadx-core/src/test/java/jadx/core/dex/visitors/typeinference/TypeCompareTest.java +++ b/jadx-core/src/test/java/jadx/core/dex/visitors/typeinference/TypeCompareTest.java @@ -34,7 +34,7 @@ import static jadx.core.dex.instructions.args.ArgType.generic; import static jadx.core.dex.instructions.args.ArgType.genericType; import static jadx.core.dex.instructions.args.ArgType.object; import static jadx.core.dex.instructions.args.ArgType.wildcard; -import static org.assertj.core.api.Assertions.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; @ExtendWith(NotYetImplementedExtension.class) public class TypeCompareTest { diff --git a/jadx-core/src/test/java/jadx/core/utils/PassMergeTest.java b/jadx-core/src/test/java/jadx/core/utils/PassMergeTest.java index e22aaf3b1..08c8c4f58 100644 --- a/jadx-core/src/test/java/jadx/core/utils/PassMergeTest.java +++ b/jadx-core/src/test/java/jadx/core/utils/PassMergeTest.java @@ -17,10 +17,10 @@ import jadx.core.dex.visitors.AbstractVisitor; import jadx.core.dex.visitors.IDexTreeVisitor; import jadx.core.utils.exceptions.JadxRuntimeException; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; class PassMergeTest { diff --git a/jadx-core/src/test/java/jadx/core/utils/TypeUtilsTest.java b/jadx-core/src/test/java/jadx/core/utils/TypeUtilsTest.java index 7b7b2b0e9..8aa09bf37 100644 --- a/jadx-core/src/test/java/jadx/core/utils/TypeUtilsTest.java +++ b/jadx-core/src/test/java/jadx/core/utils/TypeUtilsTest.java @@ -11,9 +11,7 @@ import jadx.api.JadxArgs; import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.nodes.RootNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; class TypeUtilsTest { private static final Logger LOG = LoggerFactory.getLogger(TypeUtilsTest.class); @@ -30,10 +28,10 @@ class TypeUtilsTest { public void testReplaceGenericsWithWildcards() { // check classpath graph List classGenerics = root.getTypeUtils().getClassGenerics(ArgType.object("java.util.ArrayList")); - assertThat(classGenerics, hasSize(1)); + assertThat(classGenerics).hasSize(1); ArgType genericInfo = classGenerics.get(0); - assertThat(genericInfo.getObject(), is("E")); - assertThat(genericInfo.getExtendTypes(), hasSize(0)); + assertThat(genericInfo.getObject()).isEqualTo("E"); + assertThat(genericInfo.getExtendTypes()).hasSize(0); // prepare input ArgType instanceType = ArgType.generic("java.util.ArrayList", ArgType.OBJECT); @@ -47,6 +45,6 @@ class TypeUtilsTest { LOG.debug("result: {}", result); ArgType expected = ArgType.generic("java.util.List", ArgType.wildcard(ArgType.OBJECT, ArgType.WildcardBound.SUPER)); - assertThat(result, is(expected)); + assertThat(result).isEqualTo(expected); } } diff --git a/jadx-core/src/test/java/jadx/core/utils/log/LogUtilsTest.java b/jadx-core/src/test/java/jadx/core/utils/log/LogUtilsTest.java index 04036b0bc..5b0e4653c 100644 --- a/jadx-core/src/test/java/jadx/core/utils/log/LogUtilsTest.java +++ b/jadx-core/src/test/java/jadx/core/utils/log/LogUtilsTest.java @@ -2,7 +2,7 @@ package jadx.core.utils.log; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; class LogUtilsTest { diff --git a/jadx-core/src/test/java/jadx/core/xmlgen/ResXmlGenTest.java b/jadx-core/src/test/java/jadx/core/xmlgen/ResXmlGenTest.java index 778139fb3..29d37942f 100644 --- a/jadx-core/src/test/java/jadx/core/xmlgen/ResXmlGenTest.java +++ b/jadx-core/src/test/java/jadx/core/xmlgen/ResXmlGenTest.java @@ -13,7 +13,7 @@ import jadx.core.xmlgen.entry.RawValue; import jadx.core.xmlgen.entry.ResourceEntry; import jadx.core.xmlgen.entry.ValuesParser; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; class ResXmlGenTest { private final JadxArgs args = new JadxArgs(); @@ -34,14 +34,14 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/attrs.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/attrs.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " \n" + " \n" - + "", input); + + ""); } @Test @@ -56,15 +56,15 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/attrs.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/attrs.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " \n" + " \n" + " \n" - + "", input); + + ""); } @Test @@ -79,15 +79,15 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/attrs.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/attrs.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " \n" + " \n" + " \n" - + "", input); + + ""); } @Test @@ -102,14 +102,14 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/attrs.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/attrs.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " \n" + " \n" - + "", input); + + ""); } @Test @@ -127,17 +127,17 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/styles.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/styles.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " \n" + " \n" - + "", input); + + ""); } @Test @@ -154,13 +154,13 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/strings.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/strings.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " Jadx Decompiler App\n" - + "", input); + + ""); } @Test @@ -177,13 +177,13 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/strings.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/strings.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " %s at %s\n" - + "", input); + + ""); } @Test @@ -200,14 +200,14 @@ class ResXmlGenTest { ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp); List files = resXmlGen.makeResourcesXml(args); - assertEquals(1, files.size()); - assertEquals("res/values/arrays.xml", files.get(0).getName()); + assertThat(files).hasSize(1); + assertThat(files.get(0).getName()).isEqualTo("res/values/arrays.xml"); String input = files.get(0).getText().toString(); - assertEquals("\n" + assertThat(input).isEqualTo("\n" + "\n" + " \n" + " Let\\'s go\n" + " \n" - + "", input); + + ""); } } diff --git a/jadx-core/src/test/java/jadx/core/xmlgen/entry/ValuesParserTest.java b/jadx-core/src/test/java/jadx/core/xmlgen/entry/ValuesParserTest.java index cfd8b9140..47cc009f3 100644 --- a/jadx-core/src/test/java/jadx/core/xmlgen/entry/ValuesParserTest.java +++ b/jadx-core/src/test/java/jadx/core/xmlgen/entry/ValuesParserTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; import jadx.core.utils.android.AndroidResourcesMap; -import static org.assertj.core.api.Assertions.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; class ValuesParserTest { diff --git a/jadx-core/src/test/java/jadx/tests/api/ExportGradleTest.java b/jadx-core/src/test/java/jadx/tests/api/ExportGradleTest.java index 1b513044a..c880c3ab4 100644 --- a/jadx-core/src/test/java/jadx/tests/api/ExportGradleTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/ExportGradleTest.java @@ -18,7 +18,7 @@ import jadx.core.export.ExportGradleProject; import jadx.core.export.ExportGradleTask; import jadx.core.xmlgen.ResContainer; -import static org.assertj.core.api.Assertions.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java index 3f44b75c1..0918468ed 100644 --- a/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java @@ -62,16 +62,10 @@ import jadx.tests.api.compiler.JavaUtils; import jadx.tests.api.compiler.TestCompiler; import jadx.tests.api.utils.TestUtils; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; import static org.apache.commons.lang3.StringUtils.leftPad; import static org.apache.commons.lang3.StringUtils.rightPad; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.emptyArray; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public abstract class IntegrationTest extends TestUtils { private static final Logger LOG = LoggerFactory.getLogger(IntegrationTest.class); @@ -179,7 +173,7 @@ public abstract class IntegrationTest extends TestUtils { public ClassNode getClassNode(Class clazz) { try { List files = compileClass(clazz); - assertThat("File list is empty", files, not(empty())); + assertThat(files).as("File list is empty").isNotEmpty(); return getClassNodeFromFiles(files, clazz.getName()); } catch (Exception e) { LOG.error("Failed to get class node", e); @@ -190,10 +184,10 @@ public abstract class IntegrationTest extends TestUtils { public List getClassNodes(Class... classes) { try { - assertThat("Class list is empty", classes, not(emptyArray())); + assertThat(classes).as("Class list is empty").isNotEmpty(); List srcFiles = Stream.of(classes).map(this::getSourceFileForClass).collect(Collectors.toList()); List clsFiles = compileSourceFiles(srcFiles); - assertThat("Class files list is empty", clsFiles, not(empty())); + assertThat(clsFiles).as("Class files list is empty").isNotEmpty(); return decompileFiles(clsFiles); } catch (Exception e) { LOG.error("Failed to get class node", e); @@ -207,9 +201,9 @@ public abstract class IntegrationTest extends TestUtils { RootNode root = JadxInternalAccess.getRoot(jadxDecompiler); ClassNode cls = root.resolveClass(clsName); - assertThat("Class not found: " + clsName, cls, notNullValue()); + assertThat(cls).as("Class not found: " + clsName).isNotNull(); if (removeParentClassOnInput) { - assertThat(clsName, is(cls.getClassInfo().getFullName())); + assertThat(clsName).isEqualTo(cls.getClassInfo().getFullName()); } else { LOG.info("Convert back to top level: {}", cls); cls.getTopParentClass().decompile(); // keep correct process order @@ -477,7 +471,7 @@ public abstract class IntegrationTest extends TestUtils { } public Object invoke(TestCompiler compiler, String clsFullName, String method) throws Exception { - assertNotNull(compiler, "compiler not ready"); + assertThat(compiler).as("compiler not ready").isNotNull(); return compiler.invoke(clsFullName, method, new Class[] {}, new Object[] {}); } diff --git a/jadx-core/src/test/java/jadx/tests/api/RaungTest.java b/jadx-core/src/test/java/jadx/tests/api/RaungTest.java index 91b79b98a..30ed06376 100644 --- a/jadx-core/src/test/java/jadx/tests/api/RaungTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/RaungTest.java @@ -12,8 +12,8 @@ import jadx.api.JadxInternalAccess; import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.RootNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public abstract class RaungTest extends IntegrationTest { @@ -53,7 +53,7 @@ public abstract class RaungTest extends IntegrationTest { String raungFilesDir = pkg + File.separatorChar + testDir + File.separatorChar; File raungDir = getRaungDir(raungFilesDir); String[] raungFileNames = raungDir.list((dir, name) -> name.endsWith(".raung")); - assertThat("Raung files not found in " + raungDir, raungFileNames, notNullValue()); + assertThat(raungFileNames).as("Raung files not found in " + raungDir).isNotNull(); return Stream.of(raungFileNames) .map(file -> new File(raungDir, file)) .collect(Collectors.toList()); diff --git a/jadx-core/src/test/java/jadx/tests/api/SmaliTest.java b/jadx-core/src/test/java/jadx/tests/api/SmaliTest.java index 533dfd556..1bdd1461c 100644 --- a/jadx-core/src/test/java/jadx/tests/api/SmaliTest.java +++ b/jadx-core/src/test/java/jadx/tests/api/SmaliTest.java @@ -14,8 +14,8 @@ import jadx.api.JadxInternalAccess; import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.RootNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public abstract class SmaliTest extends IntegrationTest { @@ -88,7 +88,7 @@ public abstract class SmaliTest extends IntegrationTest { } File smaliDir = getSmaliDir(smaliFilesDir); String[] smaliFileNames = smaliDir.list((dir, name) -> name.endsWith(".smali")); - assertThat("Smali files not found in " + smaliDir, smaliFileNames, notNullValue()); + assertThat(smaliFileNames).as("Smali files not found in " + smaliDir).isNotNull(); return Stream.of(smaliFileNames) .map(file -> new File(smaliDir, file)) .collect(Collectors.toList()); diff --git a/jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java b/jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java index cb16d2a55..32092a63f 100644 --- a/jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java +++ b/jadx-core/src/test/java/jadx/tests/api/compiler/TestCompiler.java @@ -25,7 +25,7 @@ import jadx.core.dex.nodes.ClassNode; import jadx.core.utils.files.FileUtils; import jadx.tests.api.IntegrationTest; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; public class TestCompiler implements Closeable { private final CompilerOptions options; @@ -115,7 +115,7 @@ public class TestCompiler implements Closeable { Class cls = getClass(clsFullName); Method mth = getMethod(cls, methodName, types); Object inst = cls.getConstructor().newInstance(); - assertNotNull(mth, "Failed to get method " + methodName + '(' + Arrays.toString(types) + ')'); + assertThat(mth).as("Failed to get method " + methodName + '(' + Arrays.toString(types) + ')').isNotNull(); return mth.invoke(inst, args); } catch (Throwable e) { IntegrationTest.rethrow("Invoke error for method: " + methodName, e); diff --git a/jadx-core/src/test/java/jadx/tests/api/utils/CountString.java b/jadx-core/src/test/java/jadx/tests/api/utils/CountString.java deleted file mode 100644 index 58382a41e..000000000 --- a/jadx-core/src/test/java/jadx/tests/api/utils/CountString.java +++ /dev/null @@ -1,34 +0,0 @@ -package jadx.tests.api.utils; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; - -public class CountString extends TypeSafeMatcher { - - private final int count; - private final String substring; - - public CountString(int count, String substring) { - this.count = count; - this.substring = substring; - } - - @Override - protected boolean matchesSafely(String item) { - return this.count == count(item); - } - - @Override - public void describeMismatchSafely(String item, Description mismatchDescription) { - mismatchDescription.appendText("found ").appendValue(count(item)); - } - - @Override - public void describeTo(Description description) { - description.appendText("containing <" + count + "> occurrence of ").appendValue(this.substring); - } - - private int count(String string) { - return TestUtils.count(string, this.substring); - } -} diff --git a/jadx-core/src/test/java/jadx/tests/api/utils/JadxMatchers.java b/jadx-core/src/test/java/jadx/tests/api/utils/JadxMatchers.java deleted file mode 100644 index 2ce7f8ec4..000000000 --- a/jadx-core/src/test/java/jadx/tests/api/utils/JadxMatchers.java +++ /dev/null @@ -1,35 +0,0 @@ -package jadx.tests.api.utils; - -import org.hamcrest.Matcher; - -public class JadxMatchers { - - public static Matcher countString(int count, String substring) { - return new CountString(count, substring); - } - - public static Matcher containsOne(String substring) { - return countString(1, substring); - } - - public static Matcher containsLines(String... lines) { - StringBuilder sb = new StringBuilder(); - for (String line : lines) { - sb.append(line).append('\n'); - } - return countString(1, sb.toString()); - } - - public static Matcher containsLines(int commonIndent, String... lines) { - String indent = TestUtils.indent(commonIndent); - StringBuilder sb = new StringBuilder(); - for (String line : lines) { - if (!line.isEmpty()) { - sb.append(indent); - sb.append(line); - } - sb.append('\n'); - } - return countString(1, sb.toString()); - } -} diff --git a/jadx-core/src/test/java/jadx/tests/api/utils/TestUtils.java b/jadx-core/src/test/java/jadx/tests/api/utils/TestUtils.java index 45f1460ea..2ace66222 100644 --- a/jadx-core/src/test/java/jadx/tests/api/utils/TestUtils.java +++ b/jadx-core/src/test/java/jadx/tests/api/utils/TestUtils.java @@ -13,11 +13,8 @@ import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.MethodNode; import jadx.core.utils.Utils; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.fail; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.fail; @ExtendWith(NotYetImplementedExtension.class) public class TestUtils { @@ -47,17 +44,19 @@ public class TestUtils { } protected static void checkCode(ClassNode cls, boolean allowWarnInCode) { - assertFalse(hasErrors(cls, allowWarnInCode), "Inconsistent cls: " + cls); + assertThat(hasErrors(cls, allowWarnInCode)).as("Inconsistent cls: " + cls).isFalse(); for (MethodNode mthNode : cls.getMethods()) { if (hasErrors(mthNode, allowWarnInCode)) { fail("Method with problems: " + mthNode + "\n " + Utils.listToString(mthNode.getAttributesStringsList(), "\n ")); } } - - String code = cls.getCode().getCodeStr(); - assertThat(code, not(containsString("inconsistent"))); - assertThat(code, not(containsString("JADX ERROR"))); + if (!cls.contains(AFlag.DONT_GENERATE)) { + assertThat(cls) + .code() + .doesNotContain("inconsistent") + .doesNotContain("JADX ERROR"); + } } protected static boolean hasErrors(IAttributeNode node, boolean allowWarnInCode) { diff --git a/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxAssertions.java b/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxAssertions.java index 7d49eee6c..163f1758c 100644 --- a/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxAssertions.java +++ b/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxAssertions.java @@ -18,7 +18,6 @@ public class JadxAssertions extends Assertions { } public static JadxCodeAssertions assertThat(String code) { - Assertions.assertThat(code).isNotNull(); return new JadxCodeAssertions(code); } } diff --git a/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxClassNodeAssertions.java b/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxClassNodeAssertions.java index f79e64587..a5b5b9398 100644 --- a/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxClassNodeAssertions.java +++ b/jadx-core/src/test/java/jadx/tests/api/utils/assertj/JadxClassNodeAssertions.java @@ -3,14 +3,13 @@ package jadx.tests.api.utils.assertj; import java.util.Map; import org.assertj.core.api.AbstractObjectAssert; -import org.assertj.core.api.Assertions; import jadx.api.ICodeInfo; import jadx.api.metadata.ICodeAnnotation; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; public class JadxClassNodeAssertions extends AbstractObjectAssert { @@ -21,14 +20,14 @@ public class JadxClassNodeAssertions extends AbstractObjectAssert entry : code.getCodeMetadata().getAsMap().entrySet()) { if (entry.getKey() == refPos) { - Assertions.assertThat(entry.getValue()).isEqualTo(node); + assertThat(entry.getValue()).isEqualTo(node); return this; } } diff --git a/jadx-core/src/test/java/jadx/tests/external/BaseExternalTest.java b/jadx-core/src/test/java/jadx/tests/external/BaseExternalTest.java index d9b9aec09..80e25be23 100644 --- a/jadx-core/src/test/java/jadx/tests/external/BaseExternalTest.java +++ b/jadx-core/src/test/java/jadx/tests/external/BaseExternalTest.java @@ -23,9 +23,7 @@ import jadx.core.utils.DebugChecks; import jadx.core.utils.exceptions.JadxRuntimeException; import jadx.tests.api.utils.TestUtils; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public abstract class BaseExternalTest extends TestUtils { private static final Logger LOG = LoggerFactory.getLogger(BaseExternalTest.class); @@ -82,7 +80,7 @@ public abstract class BaseExternalTest extends TestUtils { } } } - assertThat("No classes processed", processed, greaterThan(0)); + assertThat(processed).as("No classes processed").isGreaterThan(0); } private boolean processCls(@Nullable String mthPattern, ClassNode classNode) { @@ -192,6 +190,6 @@ public abstract class BaseExternalTest extends TestUtils { private void printErrorReport(JadxDecompiler jadx) { jadx.printErrorsReport(); - assertThat(jadx.getErrorsCount(), is(0)); + assertThat(jadx.getErrorsCount()).isEqualTo(0); } } diff --git a/jadx-core/src/test/java/jadx/tests/functional/AttributeStorageTest.java b/jadx-core/src/test/java/jadx/tests/functional/AttributeStorageTest.java index 88382b246..216bad339 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/AttributeStorageTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/AttributeStorageTest.java @@ -8,9 +8,7 @@ import jadx.core.dex.attributes.AType; import jadx.core.dex.attributes.AttributeStorage; import static jadx.core.dex.attributes.AFlag.SYNTHETIC; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class AttributeStorageTest { private AttributeStorage storage; @@ -23,14 +21,14 @@ public class AttributeStorageTest { @Test public void testAdd() { storage.add(SYNTHETIC); - assertThat(storage.contains(SYNTHETIC), is(true)); + assertThat(storage.contains(SYNTHETIC)).isTrue(); } @Test public void testRemove() { storage.add(SYNTHETIC); storage.remove(SYNTHETIC); - assertThat(storage.contains(SYNTHETIC), is(false)); + assertThat(storage.contains(SYNTHETIC)).isFalse(); } public static final AType TEST = new AType<>(); @@ -47,8 +45,8 @@ public class AttributeStorageTest { TestAttr attr = new TestAttr(); storage.add(attr); - assertThat(storage.contains(TEST), is(true)); - assertThat(storage.get(TEST), is(attr)); + assertThat(storage.contains(TEST)).isTrue(); + assertThat(storage.get(TEST)).isEqualTo(attr); } @Test @@ -57,8 +55,8 @@ public class AttributeStorageTest { storage.add(attr); storage.remove(attr); - assertThat(storage.contains(TEST), is(false)); - assertThat(storage.get(TEST), nullValue()); + assertThat(storage.contains(TEST)).isFalse(); + assertThat(storage.get(TEST)).isNull(); } @Test @@ -67,7 +65,7 @@ public class AttributeStorageTest { storage.add(attr); storage.remove(new TestAttr()); - assertThat(storage.contains(TEST), is(true)); - assertThat(storage.get(TEST), is(attr)); + assertThat(storage.contains(TEST)).isTrue(); + assertThat(storage.get(TEST)).isEqualTo(attr); } } diff --git a/jadx-core/src/test/java/jadx/tests/functional/JadxClasspathTest.java b/jadx-core/src/test/java/jadx/tests/functional/JadxClasspathTest.java index 310f1a975..b0e262d95 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/JadxClasspathTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/JadxClasspathTest.java @@ -10,10 +10,11 @@ import jadx.core.clsp.ClspGraph; import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.nodes.RootNode; +import static jadx.core.dex.instructions.args.ArgType.OBJECT; import static jadx.core.dex.instructions.args.ArgType.STRING; +import static jadx.core.dex.instructions.args.ArgType.isCastNeeded; import static jadx.core.dex.instructions.args.ArgType.object; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class JadxClasspathTest { @@ -36,12 +37,12 @@ public class JadxClasspathTest { ArgType objExc = object(JAVA_LANG_EXCEPTION); ArgType objThr = object(JAVA_LANG_THROWABLE); - assertTrue(clsp.isImplements(JAVA_LANG_EXCEPTION, JAVA_LANG_THROWABLE)); - assertFalse(clsp.isImplements(JAVA_LANG_THROWABLE, JAVA_LANG_EXCEPTION)); + assertThat(clsp.isImplements(JAVA_LANG_EXCEPTION, JAVA_LANG_THROWABLE)).isTrue(); + assertThat(clsp.isImplements(JAVA_LANG_THROWABLE, JAVA_LANG_EXCEPTION)).isFalse(); - assertFalse(ArgType.isCastNeeded(root, objExc, objThr)); - assertTrue(ArgType.isCastNeeded(root, objThr, objExc)); + assertThat(isCastNeeded(root, objExc, objThr)).isFalse(); + assertThat(isCastNeeded(root, objThr, objExc)).isTrue(); - assertTrue(ArgType.isCastNeeded(root, ArgType.OBJECT, STRING)); + assertThat(isCastNeeded(root, OBJECT, STRING)).isTrue(); } } diff --git a/jadx-core/src/test/java/jadx/tests/functional/JadxVisitorsOrderTest.java b/jadx-core/src/test/java/jadx/tests/functional/JadxVisitorsOrderTest.java index b6b15e7a7..95356bc44 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/JadxVisitorsOrderTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/JadxVisitorsOrderTest.java @@ -14,8 +14,7 @@ import jadx.core.Jadx; import jadx.core.dex.visitors.IDexTreeVisitor; import jadx.core.dex.visitors.JadxVisitor; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class JadxVisitorsOrderTest { private static final Logger LOG = LoggerFactory.getLogger(JadxVisitorsOrderTest.class); @@ -32,7 +31,7 @@ public class JadxVisitorsOrderTest { for (String str : errors) { LOG.error(str); } - assertThat(errors, empty()); + assertThat(errors).isEmpty(); } private static List check(List passes) { diff --git a/jadx-core/src/test/java/jadx/tests/functional/NameMapperTest.java b/jadx-core/src/test/java/jadx/tests/functional/NameMapperTest.java index 58f4b6968..547218665 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/NameMapperTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/NameMapperTest.java @@ -4,8 +4,7 @@ import org.junit.jupiter.api.Test; import jadx.core.deobf.NameMapper; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class NameMapperTest { @@ -23,7 +22,7 @@ public class NameMapperTest { "a.b.C9" }; for (String validName : validNames) { - assertThat(NameMapper.isValidFullIdentifier(validName), is(true)); + assertThat(NameMapper.isValidFullIdentifier(validName)).isTrue(); } } @@ -38,7 +37,7 @@ public class NameMapperTest { "b..C", }; for (String invalidName : invalidNames) { - assertThat(NameMapper.isValidFullIdentifier(invalidName), is(false)); + assertThat(NameMapper.isValidFullIdentifier(invalidName)).isFalse(); } } } diff --git a/jadx-core/src/test/java/jadx/tests/functional/SignatureParserTest.java b/jadx-core/src/test/java/jadx/tests/functional/SignatureParserTest.java index 82cb5d410..4087edd6b 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/SignatureParserTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/SignatureParserTest.java @@ -18,13 +18,10 @@ import static jadx.core.dex.instructions.args.ArgType.genericType; import static jadx.core.dex.instructions.args.ArgType.object; import static jadx.core.dex.instructions.args.ArgType.outerGeneric; import static jadx.core.dex.instructions.args.ArgType.wildcard; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; class SignatureParserTest { @@ -39,7 +36,7 @@ class SignatureParserTest { } private static void checkType(String str, ArgType type) { - assertThat(new SignatureParser(str).consumeType(), is(type)); + assertThat(new SignatureParser(str).consumeType()).isEqualTo(type); } @Test @@ -57,17 +54,17 @@ class SignatureParserTest { public void testInnerGeneric() { String signature = "La.LinkedHashIterator;>;"; String objectStr = new SignatureParser(signature).consumeType().getObject(); - assertThat(objectStr, is("a$LinkedHashIterator")); + assertThat(objectStr).isEqualTo("a$LinkedHashIterator"); } @Test public void testNestedInnerGeneric() { String signature = "La.I.X;"; ArgType result = new SignatureParser(signature).consumeType(); - assertThat(result.getObject(), is("a$I$X")); + assertThat(result.getObject()).isEqualTo("a$I$X"); // nested 'outerGeneric' objects ArgType obj = generic("La;", genericType("V")); - assertThat(result, equalTo(outerGeneric(outerGeneric(obj, object("I")), object("X")))); + assertThat(result).isEqualTo(outerGeneric(outerGeneric(obj, object("I")), object("X"))); } @Test @@ -76,11 +73,11 @@ class SignatureParserTest { String signature = "Lsome/long/pkg/ba.some/long/pkg/bb;"; ArgType result = new SignatureParser(signature).consumeType(); System.out.println(result); - assertThat(result.getObject(), is("some.long.pkg.ba$some.long.pkg.bb")); + assertThat(result.getObject()).isEqualTo("some.long.pkg.ba$some.long.pkg.bb"); ArgType baseObj = generic("Lsome/long/pkg/ba;", object("Lsome/pkg/s;")); ArgType innerObj = generic("Lsome/long/pkg/bb;", object("Lsome/pkg/p;"), object("Lsome/pkg/n;")); ArgType obj = outerGeneric(baseObj, innerObj); - assertThat(result, equalTo(obj)); + assertThat(result).isEqualTo(obj); } @Test @@ -104,7 +101,7 @@ class SignatureParserTest { private static void checkWildcards(String w, ArgType... types) { ArgType parsedType = new SignatureParser("La<" + w + ">;").consumeType(); ArgType expectedType = generic("La;", types); - assertThat(parsedType, is(expectedType)); + assertThat(parsedType).isEqualTo(expectedType); } @Test @@ -124,25 +121,25 @@ class SignatureParserTest { List list = (List) objs[i + 1]; expectedList.add(ArgType.genericType(typeVar, list)); } - assertThat(genericsList, is(expectedList)); + assertThat(genericsList).isEqualTo(expectedList); } @Test public void testMethodArgs() { List argTypes = new SignatureParser("(Ljava/util/List<*>;)V").consumeMethodArgs(1); - assertThat(argTypes, hasSize(1)); - assertThat(argTypes.get(0), is(generic("Ljava/util/List;", wildcard()))); + assertThat(argTypes).hasSize(1); + assertThat(argTypes.get(0)).isEqualTo(generic("Ljava/util/List;", wildcard())); } @Test public void testMethodArgs2() { List argTypes = new SignatureParser("(La/b/C.d/E;)V").consumeMethodArgs(1); - assertThat(argTypes, hasSize(1)); + assertThat(argTypes).hasSize(1); ArgType argType = argTypes.get(0); - assertThat(argType.getObject().indexOf('/'), is(-1)); - assertThat(argType, is(outerGeneric(generic("La/b/C;", genericType("T")), object("d.E")))); + assertThat(argType.getObject().indexOf('/')).isEqualTo(-1); + assertThat(argType).isEqualTo(outerGeneric(generic("La/b/C;", genericType("T")), object("d.E"))); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/functional/StringUtilsTest.java b/jadx-core/src/test/java/jadx/tests/functional/StringUtilsTest.java index 7989ae54f..0ef1243b4 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/StringUtilsTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/StringUtilsTest.java @@ -5,8 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.api.JadxArgs; import jadx.core.utils.StringUtils; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; class StringUtilsTest { @@ -33,7 +32,7 @@ class StringUtilsTest { } private void checkStringUnescape(String input, String result) { - assertThat(stringUtils.unescapeString(input), is('"' + result + '"')); + assertThat(stringUtils.unescapeString(input)).isEqualTo('"' + result + '"'); } @Test @@ -45,11 +44,11 @@ class StringUtilsTest { checkCharUnescape('\n', "\\n"); checkCharUnescape('\'', "\\'"); - assertThat(stringUtils.unescapeChar('\0'), is("0")); + assertThat(stringUtils.unescapeChar('\0')).isEqualTo("0"); } private void checkCharUnescape(char input, String result) { - assertThat(stringUtils.unescapeChar(input), is('\'' + result + '\'')); + assertThat(stringUtils.unescapeChar(input)).isEqualTo('\'' + result + '\''); } @Test @@ -60,6 +59,6 @@ class StringUtilsTest { } private void checkResStrValueEscape(String input, String result) { - assertThat(StringUtils.escapeResStrValue(input), is(result)); + assertThat(StringUtils.escapeResStrValue(input)).isEqualTo(result); } } diff --git a/jadx-core/src/test/java/jadx/tests/functional/TemplateFileTest.java b/jadx-core/src/test/java/jadx/tests/functional/TemplateFileTest.java index 753ad1f55..86a4bfb83 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/TemplateFileTest.java +++ b/jadx-core/src/test/java/jadx/tests/functional/TemplateFileTest.java @@ -4,8 +4,7 @@ import org.junit.jupiter.api.Test; import jadx.core.export.TemplateFile; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TemplateFileTest { @@ -21,9 +20,9 @@ public class TemplateFileTest { String res = tmpl.build(); System.out.println(res); - assertThat(res, containsString("applicationId 'SOME_ID'")); - assertThat(res, containsString("targetSdkVersion 2")); - assertThat(res, containsString("versionCode 3")); - assertThat(res, containsString("versionName \"1.2.3\"")); + assertThat(res).contains("applicationId 'SOME_ID'"); + assertThat(res).contains("targetSdkVersion 2"); + assertThat(res).contains("versionCode 3"); + assertThat(res).contains("versionName \"1.2.3\""); } } diff --git a/jadx-core/src/test/java/jadx/tests/functional/TestIfCondition.java b/jadx-core/src/test/java/jadx/tests/functional/TestIfCondition.java index 4422c79b9..6a9572500 100644 --- a/jadx-core/src/test/java/jadx/tests/functional/TestIfCondition.java +++ b/jadx-core/src/test/java/jadx/tests/functional/TestIfCondition.java @@ -18,8 +18,7 @@ import static jadx.core.dex.regions.conditions.IfCondition.Mode.OR; import static jadx.core.dex.regions.conditions.IfCondition.merge; import static jadx.core.dex.regions.conditions.IfCondition.not; import static jadx.core.dex.regions.conditions.IfCondition.simplify; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIfCondition { @@ -46,10 +45,10 @@ public class TestIfCondition { IfCondition c = makeCondition(IfOp.NE, a, LiteralArg.litFalse()); IfCondition simp = simplify(c); - assertThat(simp.getMode(), is(COMPARE)); + assertThat(simp.getMode()).isEqualTo(COMPARE); Compare compare = simp.getCompare(); - assertThat(compare.getA(), is(a)); - assertThat(compare.getB(), is(LiteralArg.litTrue())); + assertThat(compare.getA()).isEqualTo(a); + assertThat(compare.getB()).isEqualTo(LiteralArg.litTrue()); } @Test @@ -58,23 +57,23 @@ public class TestIfCondition { IfCondition b = makeSimpleCondition(); IfCondition c = merge(Mode.OR, a, b); - assertThat(c.getMode(), is(OR)); - assertThat(c.first(), is(a)); - assertThat(c.second(), is(b)); + assertThat(c.getMode()).isEqualTo(OR); + assertThat(c.first()).isEqualTo(a); + assertThat(c.second()).isEqualTo(b); } @Test public void testSimplifyNot() { // !(!a) => a IfCondition a = not(not(makeSimpleCondition())); - assertThat(simplify(a), is(a)); + assertThat(simplify(a)).isEqualTo(a); } @Test public void testSimplifyNot2() { // !(!a) => a IfCondition a = not(makeNegCondition()); - assertThat(simplify(a), is(a)); + assertThat(simplify(a)).isEqualTo(a); } @Test @@ -85,9 +84,9 @@ public class TestIfCondition { IfCondition c = not(merge(Mode.OR, not(a), not(b))); IfCondition simp = simplify(c); - assertThat(simp.getMode(), is(AND)); - assertThat(simp.first(), is(a)); - assertThat(simp.second(), is(b)); + assertThat(simp.getMode()).isEqualTo(AND); + assertThat(simp.first()).isEqualTo(a); + assertThat(simp.second()).isEqualTo(b); } @Test @@ -99,12 +98,12 @@ public class TestIfCondition { IfCondition cond = merge(Mode.AND, merge(Mode.OR, not(a), not(b)), not(c)); IfCondition simp = simplify(cond); - assertThat(simp.getMode(), is(NOT)); + assertThat(simp.getMode()).isEqualTo(NOT); IfCondition f = simp.first(); - assertThat(f.getMode(), is(OR)); - assertThat(f.first().getMode(), is(AND)); - assertThat(f.first().first(), is(a)); - assertThat(f.first().second(), is(b)); - assertThat(f.second(), is(c)); + assertThat(f.getMode()).isEqualTo(OR); + assertThat(f.first().getMode()).isEqualTo(AND); + assertThat(f.first().first()).isEqualTo(a); + assertThat(f.first().second()).isEqualTo(b); + assertThat(f.second()).isEqualTo(c); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldAccess.java b/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldAccess.java index a7bb2f302..253d63a41 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldAccess.java +++ b/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldAccess.java @@ -2,11 +2,9 @@ package jadx.tests.integration.android; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; @SuppressWarnings("TypeName") public class TestRFieldAccess extends IntegrationTest { @@ -25,8 +23,8 @@ public class TestRFieldAccess extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestRFieldAccess.class); - String code = cls.getCode().toString(); - assertThat(code, countString(2, "return R.id.BUTTON_01;")); + assertThat(getClassNode(TestRFieldAccess.class)) + .code() + .countString(2, "return R.id.BUTTON_01;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore.java b/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore.java index e7f3460d2..5b9214c01 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore.java +++ b/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore.java @@ -7,18 +7,13 @@ import java.util.Map; import org.junit.jupiter.api.Test; import jadx.api.plugins.input.data.annotations.EncodedValue; -import jadx.api.plugins.input.data.attributes.JadxAttrType; import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.FieldNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; +import static jadx.api.plugins.input.data.attributes.JadxAttrType.CONSTANT_VALUE; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestRFieldRestore extends IntegrationTest { @@ -39,25 +34,25 @@ public class TestRFieldRestore extends IntegrationTest { setResMap(map); ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - assertThat(code, containsOne("return R.id.Button;")); - assertThat(code, not(containsString("import R;"))); + assertThat(cls).code() + .containsOne("return R.id.Button;") + .doesNotContain("import R;"); // check 'R' class ClassNode rCls = cls.root().searchClassByFullAlias("R"); - assertThat(rCls, notNullValue()); + assertThat(rCls).isNotNull(); // check inner 'id' class List innerClasses = rCls.getInnerClasses(); - assertThat(innerClasses, hasSize(1)); + assertThat(innerClasses).hasSize(1); ClassNode idCls = innerClasses.get(0); - assertThat(idCls.getShortName(), is("id")); + assertThat(idCls.getShortName()).isEqualTo("id"); // check 'Button' field FieldNode buttonField = idCls.searchFieldByName("Button"); - assertThat(buttonField, notNullValue()); - EncodedValue constVal = buttonField.get(JadxAttrType.CONSTANT_VALUE); + assertThat(buttonField).isNotNull(); + EncodedValue constVal = buttonField.get(CONSTANT_VALUE); Integer buttonValue = (Integer) constVal.getValue(); - assertThat(buttonValue, is(buttonConstValue)); + assertThat(buttonValue).isEqualTo(buttonConstValue); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore2.java b/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore2.java index a672b4ce9..5427c4c8d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/android/TestRFieldRestore2.java @@ -5,11 +5,8 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestRFieldRestore2 extends IntegrationTest { @@ -29,8 +26,8 @@ public class TestRFieldRestore2 extends IntegrationTest { map.put(2131230730, "id.Button"); setResMap(map); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - assertThat(code, containsOne("R.id.Button;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("R.id.Button;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations.java b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations.java index 406b89338..e75897465 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations.java +++ b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations.java @@ -2,13 +2,9 @@ package jadx.tests.integration.annotations; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnnotations extends IntegrationTest { @@ -48,18 +44,15 @@ public class TestAnnotations extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("@A(a = 255)"))); - assertThat(code, containsOne("@A(a = -1)")); - assertThat(code, containsOne("@A(a = -253)")); - assertThat(code, containsOne("@A(a = -11253)")); - assertThat(code, containsOne("@V(false)")); - assertThat(code, not(containsString("@D()"))); - assertThat(code, containsOne("@D")); - - assertThat(code, containsOne("int a();")); - assertThat(code, containsOne("float value() default 1.1f;")); + assertThat(getClassNode(TestCls.class)).code() + .doesNotContain("@A(a = 255)") + .containsOne("@A(a = -1)") + .containsOne("@A(a = -253)") + .containsOne("@A(a = -11253)") + .containsOne("@V(false)") + .doesNotContain("@D()") + .containsOne("@D") + .containsOne("int a();") + .containsOne("float value() default 1.1f;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations2.java b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations2.java index 823dfeeeb..baed24779 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotations2.java @@ -7,11 +7,8 @@ import java.lang.annotation.Target; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnnotations2 extends IntegrationTest { @@ -28,13 +25,12 @@ public class TestAnnotations2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("@Target({ElementType.TYPE})")); - assertThat(code, containsString("@Retention(RetentionPolicy.RUNTIME)")); - assertThat(code, containsString("public @interface A {")); - assertThat(code, containsString("float f();")); - assertThat(code, containsString("int i();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("@Target({ElementType.TYPE})") + .contains("@Retention(RetentionPolicy.RUNTIME)") + .contains("public @interface A {") + .contains("float f();") + .contains("int i();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsMix.java b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsMix.java index 66e7b09dc..237343c22 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsMix.java +++ b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsMix.java @@ -10,15 +10,11 @@ import java.util.Arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static java.lang.Thread.State.TERMINATED; +import static org.assertj.core.api.Assertions.assertThat; public class TestAnnotationsMix extends IntegrationTest { @@ -29,18 +25,18 @@ public class TestAnnotationsMix extends IntegrationTest { new Thread(); Method err = cls.getMethod("error"); - assertTrue(err.getExceptionTypes().length > 0); - assertSame(err.getExceptionTypes()[0], Exception.class); + assertThat(err.getExceptionTypes().length > 0).isTrue(); + assertThat(err.getExceptionTypes()[0]).isSameAs(Exception.class); Method d = cls.getMethod("depr", String[].class); - assertTrue(d.getAnnotations().length > 0); - assertSame(d.getAnnotations()[0].annotationType(), Deprecated.class); + assertThat(d.getAnnotations().length > 0).isTrue(); + assertThat(d.getAnnotations()[0].annotationType()).isSameAs(Deprecated.class); Method ma = cls.getMethod("test", String[].class); - assertTrue(ma.getAnnotations().length > 0); + assertThat(ma.getAnnotations().length > 0).isTrue(); MyAnnotation a = (MyAnnotation) ma.getAnnotations()[0]; - assertEquals(7, a.num()); - assertSame(Thread.State.TERMINATED, a.state()); + assertThat(a.num()).isEqualTo(7); + assertThat(a.state()).isSameAs(TERMINATED); return true; } @@ -101,10 +97,9 @@ public class TestAnnotationsMix extends IntegrationTest { @Test public void test() { // useDexInput(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("int i = false;"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("int i = false;"); } @Test @@ -115,10 +110,9 @@ public class TestAnnotationsMix extends IntegrationTest { @Test public void testDeclaration() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("Thread thread = new Thread();"))); - assertThat(code, containsString("new Thread();")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("Thread thread = new Thread();") + .contains("new Thread();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRename.java b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRename.java index 1308d09b8..7951a08f3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRename.java +++ b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRename.java @@ -8,13 +8,10 @@ import java.lang.reflect.Method; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnnotationsRename extends IntegrationTest { @@ -33,17 +30,16 @@ public class TestAnnotationsRename extends IntegrationTest { public void check() throws NoSuchMethodException { Method test = TestCls.class.getDeclaredMethod("test"); A annotation = test.getAnnotation(A.class); - assertThat(annotation.x(), is(5)); + assertThat(annotation.x()).isEqualTo(5); } } @Test public void test() { enableDeobfuscation(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public @interface ")); - assertThat(code, not(containsString("(x = 5)"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("public @interface ") + .doesNotContain("(x = 5)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRenameDef.java b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRenameDef.java index d75ec013a..c33f30f80 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRenameDef.java +++ b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestAnnotationsRenameDef.java @@ -7,12 +7,8 @@ import java.lang.annotation.Target; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnnotationsRenameDef extends IntegrationTest { @@ -35,11 +31,10 @@ public class TestAnnotationsRenameDef extends IntegrationTest { // force rename 'value' method args.setDeobfuscationMinLength(20); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public @interface ")); - assertThat(code, not(containsString("int value();"))); - assertThat(code, not(containsString("(5)"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("public @interface ") + .doesNotContain("int value();") + .doesNotContain("(5)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestParamAnnotations.java b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestParamAnnotations.java index c3802238c..c7edaf804 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/annotations/TestParamAnnotations.java +++ b/jadx-core/src/test/java/jadx/tests/integration/annotations/TestParamAnnotations.java @@ -7,11 +7,8 @@ import java.lang.annotation.Target; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestParamAnnotations extends IntegrationTest { @@ -35,11 +32,10 @@ public class TestParamAnnotations extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("void test1(@A int i) {")); - assertThat(code, containsString("void test2(int i, @A int j) {")); - assertThat(code, containsString("void test3(@A(i = 5) int i) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("void test1(@A int i) {") + .contains("void test2(int i, @A int j) {") + .contains("void test3(@A(i = 5) int i) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith.java index f52cf6d8f..5036d53f0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith.java @@ -3,11 +3,10 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArith extends IntegrationTest { @@ -33,35 +32,33 @@ public class TestArith extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); + assertThat(getClassNode(TestCls.class)) + .code(); } @Test @NotYetImplemented public void test2() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("a += 2;")); - assertThat(code, containsString("a++;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("a += 2;") + .contains("a++;"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); + assertThat(getClassNode(TestCls.class)) + .code(); } @Test @NotYetImplemented public void testNoDebug2() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("i += 2;")); - assertThat(code, containsString("i++;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("i += 2;") + .contains("i++;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith2.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith2.java index b96077b34..df5a3d39b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith2.java @@ -2,12 +2,8 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArith2 extends IntegrationTest { @@ -40,25 +36,19 @@ public class TestArith2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return (a + 2) * 3;")); - assertThat(code, not(containsString("a + 2 * 3"))); - - assertThat(code, containsString("return a + b + c;")); - assertThat(code, not(containsString("return (a + b) + c;"))); - - assertThat(code, containsString("return a | b | c;")); - assertThat(code, not(containsString("return (a | b) | c;"))); - - assertThat(code, containsString("return a & b & c;")); - assertThat(code, not(containsString("return (a & b) & c;"))); - - assertThat(code, containsString("return a - (b - c);")); - assertThat(code, not(containsString("return a - b - c;"))); - - assertThat(code, containsString("return a / (b / c);")); - assertThat(code, not(containsString("return a / b / c;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return (a + 2) * 3;") + .doesNotContain("a + 2 * 3") + .contains("return a + b + c;") + .doesNotContain("return (a + b) + c;") + .contains("return a | b | c;") + .doesNotContain("return (a | b) | c;") + .contains("return a & b & c;") + .doesNotContain("return (a & b) & c;") + .contains("return a - (b - c);") + .doesNotContain("return a - b - c;") + .contains("return a / (b / c);") + .doesNotContain("return a / b / c;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith3.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith3.java index c94e2a85e..a9a61b375 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArith3.java @@ -2,13 +2,8 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArith3 extends IntegrationTest { @@ -33,21 +28,19 @@ public class TestArith3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while (n + 4 < buffer.length) {")); - assertThat(code, containsOne(indent() + "n += len + 5;")); - assertThat(code, not(containsString("; n += len + 5) {"))); - assertThat(code, not(containsString("default:"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while (n + 4 < buffer.length) {") + .containsOne(indent() + "n += len + 5;") + .doesNotContain("; n += len + 5) {") + .doesNotContain("default:"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while (")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while ("); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithConst.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithConst.java index 688733cea..107f54fa0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithConst.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithConst.java @@ -2,20 +2,17 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArithConst extends SmaliTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNodeFromSmaliWithPath("arith", "TestArithConst"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return i + CONST_INT;")); + assertThat(getClassNodeFromSmaliWithPath("arith", "TestArithConst")) + .code() + .containsOne("return i + CONST_INT;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithNot.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithNot.java index 598a040dc..77f049007 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithNot.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestArithNot.java @@ -2,12 +2,9 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArithNot extends SmaliTest { // @formatter:off @@ -27,11 +24,10 @@ public class TestArithNot extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPath("arith", "TestArithNot"); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return ~a;")); - assertThat(code, containsString("return ~b;")); - assertThat(code, not(containsString("^"))); + assertThat(getClassNodeFromSmaliWithPath("arith", "TestArithNot")) + .code() + .contains("return ~a;") + .contains("return ~b;") + .doesNotContain("^"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement.java index 728bf722e..65efe6453 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFieldIncrement extends IntegrationTest { @@ -30,11 +27,10 @@ public class TestFieldIncrement extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("instanceField++;")); - assertThat(code, containsString("staticField--;")); - assertThat(code, containsString("result += s + '_';")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("instanceField++;") + .contains("staticField--;") + .contains("result += s + '_';"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement2.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement2.java index 5a21259ec..01ffeab99 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement2.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFieldIncrement2 extends IntegrationTest { @@ -28,10 +25,9 @@ public class TestFieldIncrement2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("this.a.f += n;")); - assertThat(code, containsString("this.a.f *= n;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("this.a.f += n;") + .contains("this.a.f *= n;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement3.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement3.java index 0f39cabca..22322eaec 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestFieldIncrement3.java @@ -4,11 +4,8 @@ import java.util.Random; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFieldIncrement3 extends IntegrationTest { @@ -67,9 +64,8 @@ public class TestFieldIncrement3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("directVect.x = targetPos.x - newPos.x;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("directVect.x = targetPos.x - newPos.x;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arith/TestSpecialValues.java b/jadx-core/src/test/java/jadx/tests/integration/arith/TestSpecialValues.java index 4e162a0ec..ced7a66d9 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arith/TestSpecialValues.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arith/TestSpecialValues.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arith; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSpecialValues extends IntegrationTest { @@ -46,18 +43,15 @@ public class TestSpecialValues extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne( - "Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_NORMAL")); - - assertThat(code, containsOne("Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, " - + "Double.MIN_VALUE, Double.MAX_VALUE, Double.MIN_NORMAL")); - - assertThat(code, containsOne("Short.MIN_VALUE, Short.MAX_VALUE")); - assertThat(code, containsOne("Byte.MIN_VALUE, Byte.MAX_VALUE")); - assertThat(code, containsOne("Integer.MIN_VALUE, Integer.MAX_VALUE")); - assertThat(code, containsOne("Long.MIN_VALUE, Long.MAX_VALUE")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne( + "Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_NORMAL") + .containsOne("Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, " + + "Double.MIN_VALUE, Double.MAX_VALUE, Double.MIN_NORMAL") + .containsOne("Short.MIN_VALUE, Short.MAX_VALUE") + .containsOne("Byte.MIN_VALUE, Byte.MAX_VALUE") + .containsOne("Integer.MIN_VALUE, Integer.MAX_VALUE") + .containsOne("Long.MIN_VALUE, Long.MAX_VALUE"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill.java index a7b46934c..9d53312b4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArrayFill extends IntegrationTest { @@ -19,9 +16,8 @@ public class TestArrayFill extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return new String[]{\"1\", \"2\", \"3\"};")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return new String[]{\"1\", \"2\", \"3\"};"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill2.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill2.java index 896635a59..bb2911c54 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFill2.java @@ -3,11 +3,8 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArrayFill2 extends IntegrationTest { @@ -20,10 +17,9 @@ public class TestArrayFill2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return new int[]{1, a + 1, 2};")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return new int[]{1, a + 1, 2};"); } public static class TestCls2 { @@ -36,9 +32,8 @@ public class TestArrayFill2 extends IntegrationTest { @Test @NotYetImplemented public void test2() { - ClassNode cls = getClassNode(TestCls2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return new int[]{1, a++, a * 2};")); + JadxAssertions.assertThat(getClassNode(TestCls2.class)) + .code() + .contains("return new int[]{1, a++, a * 2};"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFillWithMove.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFillWithMove.java index 473dc6588..eaaa81c59 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFillWithMove.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayFillWithMove.java @@ -2,23 +2,18 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArrayFillWithMove extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliFiles("TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("// fill-array-data instruction"))); - assertThat(code, not(containsString("arr[0] = 0;"))); - - assertThat(code, containsString("return new long[]{0, 1}")); + assertThat(getClassNodeFromSmaliFiles("TestCls")) + .code() + .doesNotContain("// fill-array-data instruction") + .doesNotContain("arr[0] = 0;") + .contains("return new long[]{0, 1}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayInit.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayInit.java index 945fda785..5eab9e859 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayInit.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrayInit.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArrayInit extends IntegrationTest { @@ -26,10 +23,9 @@ public class TestArrayInit extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("= {10, 20, 30};")); - assertThat(code, containsString("this.bytes = new byte[]{10, 20, 30};")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("= {10, 20, 30};") + .contains("this.bytes = new byte[]{10, 20, 30};"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays.java index 59292e1bc..e5247ad3a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArrays extends IntegrationTest { public static class TestCls { @@ -25,9 +22,8 @@ public class TestArrays extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return new int[]{1, 2, 3, 5}[i];")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return new int[]{1, 2, 3, 5}[i];"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays2.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays2.java index d92fa572d..21f623813 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays2.java @@ -2,12 +2,9 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArrays2 extends IntegrationTest { public static class TestCls { @@ -27,16 +24,15 @@ public class TestArrays2 extends IntegrationTest { } public void check() { - assertThat(test4(4), instanceOf(byte[].class)); + assertThat(test4(4)).isInstanceOf(byte[].class); } } @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("new int[]{1, 2}")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("new int[]{1, 2}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays3.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays3.java index 5f7e7488f..063d33a17 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays3.java @@ -2,13 +2,9 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArrays3 extends IntegrationTest { public static class TestCls { @@ -20,25 +16,23 @@ public class TestArrays3 extends IntegrationTest { public void check() { byte[] inputArr = { 1, 2 }; Object result = test(inputArr); - assertThat(result, instanceOf(Object[].class)); - assertThat(((Object[]) result)[0], is(inputArr)); + assertThat(result).isInstanceOf(Object[].class); + assertThat(((Object[]) result)[0]).isEqualTo(inputArr); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return new Object[]{bArr};")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return new Object[]{bArr};"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return new Object[]{bArr};")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return new Object[]{bArr};"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays4.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays4.java index 9a8b768e4..ded82c5e2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestArrays4.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArrays4 extends IntegrationTest { @@ -27,9 +24,8 @@ public class TestArrays4 extends IntegrationTest { @Test public void testArrayTypeInference() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("char[] chars = toChars(bArr);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("char[] chars = toChars(bArr);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestFillArrayData.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestFillArrayData.java index cb1f28554..d143eb7dc 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestFillArrayData.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestFillArrayData.java @@ -2,20 +2,17 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestFillArrayData extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliFiles("TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, containsString("jArr[0] = 1;")); - assertThat(code, containsString("jArr[1] = 2;")); + assertThat(getClassNodeFromSmaliFiles("TestCls")) + .code() + .contains("jArr[0] = 1;") + .contains("jArr[1] = 2;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestMultiDimArrayFill.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestMultiDimArrayFill.java index e5ecc39bb..877f29b86 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestMultiDimArrayFill.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestMultiDimArrayFill.java @@ -2,11 +2,8 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestMultiDimArrayFill extends IntegrationTest { @@ -32,11 +29,10 @@ public class TestMultiDimArrayFill extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return new Obj(" - + "new int[][]{new int[]{1}, new int[]{2}, new int[]{3}, new int[]{4, 5}, new int[0]}, " - + "new int[]{a, a, a, a, b});")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return new Obj(" + + "new int[][]{new int[]{1}, new int[]{2}, new int[]{3}, new int[]{4, 5}, new int[0]}, " + + "new int[]{a, a, a, a, b});"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestRedundantType.java b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestRedundantType.java index 87aef843a..d1d5c067d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/arrays/TestRedundantType.java +++ b/jadx-core/src/test/java/jadx/tests/integration/arrays/TestRedundantType.java @@ -2,12 +2,10 @@ package jadx.tests.integration.arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestRedundantType extends IntegrationTest { @@ -20,10 +18,9 @@ public class TestRedundantType extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return new byte[]{10, 11, 12};")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return new byte[]{10, 11, 12};"); } public static class TestByte { @@ -40,14 +37,13 @@ public class TestRedundantType extends IntegrationTest { @Test public void testByte() { - ClassNode cls = getClassNode(TestByte.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("arr[10] = 126")); - assertThat(code, containsString("arr[20] = Byte.MAX_VALUE")); - assertThat(code, containsString("arr[30] = Byte.MIN_VALUE")); - assertThat(code, containsString("arr[40] = -127")); - assertEquals(-127, new TestByte().method()[40]); + JadxAssertions.assertThat(getClassNode(TestByte.class)) + .code() + .contains("arr[10] = 126") + .contains("arr[20] = Byte.MAX_VALUE") + .contains("arr[30] = Byte.MIN_VALUE") + .contains("arr[40] = -127"); + assertThat(new TestByte().method()[40]).isEqualTo((byte) -127); } public static class TestShort { @@ -64,13 +60,12 @@ public class TestRedundantType extends IntegrationTest { @Test public void testShort() { - ClassNode cls = getClassNode(TestShort.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("arr[10] = 32766")); - assertThat(code, containsString("arr[20] = Short.MAX_VALUE")); - assertThat(code, containsString("arr[30] = Short.MIN_VALUE")); - assertThat(code, containsString("arr[40] = -32767")); - assertEquals(-32767, new TestShort().method()[40]); + JadxAssertions.assertThat(getClassNode(TestShort.class)) + .code() + .contains("arr[10] = 32766") + .contains("arr[20] = Short.MAX_VALUE") + .contains("arr[30] = Short.MIN_VALUE") + .contains("arr[40] = -32767"); + assertThat(new TestShort().method()[40]).isEqualTo((short) -32767); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseAnd.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseAnd.java index f99da0693..993c0608c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseAnd.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseAnd.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; @SuppressWarnings({ "PointlessBooleanExpression", "unused" }) public class TestBitwiseAnd extends IntegrationTest { @@ -25,10 +22,9 @@ public class TestBitwiseAnd extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.a && this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (this.a && this.b) {"); } public static class TestCls2 { @@ -45,10 +41,9 @@ public class TestBitwiseAnd extends IntegrationTest { @Test public void test2() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (!this.a || !this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls2.class)) + .code() + .containsOne("if (!this.a || !this.b) {"); } public static class TestCls3 { @@ -65,10 +60,9 @@ public class TestBitwiseAnd extends IntegrationTest { @Test public void test3() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls3.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (!this.a || !this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls3.class)) + .code() + .containsOne("if (!this.a || !this.b) {"); } public static class TestCls4 { @@ -85,9 +79,8 @@ public class TestBitwiseAnd extends IntegrationTest { @Test public void test4() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls4.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.a && this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls4.class)) + .code() + .containsOne("if (this.a && this.b) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseOr.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseOr.java index c585347d3..20aa333b2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseOr.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBitwiseOr.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestBitwiseOr extends IntegrationTest { @@ -24,10 +21,9 @@ public class TestBitwiseOr extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.a || this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (this.a || this.b) {"); } public static class TestCls2 { @@ -44,10 +40,9 @@ public class TestBitwiseOr extends IntegrationTest { @Test public void test2() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (!this.a && !this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls2.class)) + .code() + .containsOne("if (!this.a && !this.b) {"); } public static class TestCls3 { @@ -64,10 +59,9 @@ public class TestBitwiseOr extends IntegrationTest { @Test public void test3() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls3.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (!this.a && !this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls3.class)) + .code() + .containsOne("if (!this.a && !this.b) {"); } public static class TestCls4 { @@ -84,9 +78,8 @@ public class TestBitwiseOr extends IntegrationTest { @Test public void test4() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls4.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.a || this.b) {")); + JadxAssertions.assertThat(getClassNode(TestCls4.class)) + .code() + .containsOne("if (this.a || this.b) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCast.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCast.java index b221b6992..8144eacf0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCast.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCast.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestCast extends IntegrationTest { @@ -48,15 +45,13 @@ public class TestCast extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("write(a ? (byte) 0 : (byte) 1);")); - assertThat(code, containsString("write(a ? (byte) 0 : this.myByte);")); - assertThat(code, containsString("write(a ? (byte) 0 : Byte.MAX_VALUE);")); - - assertThat(code, containsString("write(a ? (short) 0 : (short) 1);")); - assertThat(code, containsString("write(a ? this.myShort : (short) 0);")); - assertThat(code, containsString("write(a ? Short.MIN_VALUE : (short) 0);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("write(a ? (byte) 0 : (byte) 1);") + .contains("write(a ? (byte) 0 : this.myByte);") + .contains("write(a ? (byte) 0 : Byte.MAX_VALUE);") + .contains("write(a ? (short) 0 : (short) 1);") + .contains("write(a ? this.myShort : (short) 0);") + .contains("write(a ? Short.MIN_VALUE : (short) 0);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp.java index 22c866810..37cace27b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestCmpOp extends IntegrationTest { @@ -50,17 +47,15 @@ public class TestCmpOp extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return a > 3.0f;")); - assertThat(code, containsString("return b < 2.0f;")); - assertThat(code, containsString("return c == 1.0f;")); - assertThat(code, containsString("return d != 0.0f;")); - assertThat(code, containsString("return e >= -1.0f;")); - assertThat(code, containsString("return f <= -2.0f;")); - assertThat(code, containsString("return 4.0f > g;")); - assertThat(code, containsString("return 5 < h;")); - assertThat(code, containsString("return 6.5d < i;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return a > 3.0f;") + .contains("return b < 2.0f;") + .contains("return c == 1.0f;") + .contains("return d != 0.0f;") + .contains("return e >= -1.0f;") + .contains("return f <= -2.0f;") + .contains("return 4.0f > g;") + .contains("return 5 < h;").contains("return 6.5d < i;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp2.java index f823ba22d..a17cbbd2c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestCmpOp2.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestCmpOp2 extends IntegrationTest { @@ -22,10 +19,9 @@ public class TestCmpOp2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return a > b;")); - assertThat(code, containsString("return ((double) c) < d;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return a > b;") + .contains("return ((double) c) < d;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf.java index 170df93ab..300a1459c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf.java @@ -2,11 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestComplexIf extends SmaliTest { @@ -32,10 +30,9 @@ public class TestComplexIf extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPkg("conditions", "TestComplexIf"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.a.equals(\"GT-P6200\") || this.a.equals(\"GT-P6210\") || this.a.equals(\"A100\") " - + "|| this.a.equals(\"A101\") || this.a.equals(\"LIFETAB_S786X\") || this.a.equals(\"VS890 4G\")) {")); + assertThat(getClassNodeFromSmaliWithPkg("conditions", "TestComplexIf")) + .code() + .containsOne("if (this.a.equals(\"GT-P6200\") || this.a.equals(\"GT-P6210\") || this.a.equals(\"A100\") " + + "|| this.a.equals(\"A101\") || this.a.equals(\"LIFETAB_S786X\") || this.a.equals(\"VS890 4G\")) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf2.java index 8cbde0e09..66dc9047d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestComplexIf2.java @@ -2,11 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestComplexIf2 extends SmaliTest { @@ -32,9 +30,7 @@ public class TestComplexIf2 extends SmaliTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNodeFromSmaliWithPkg("conditions", "TestComplexIf2"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.project != null && \"simple\".equals(this.project)) {")); + assertThat(getClassNodeFromSmaliWithPkg("conditions", "TestComplexIf2")).code() + .containsOne("if (this.project != null && \"simple\".equals(this.project)) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditionInLoop.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditionInLoop.java index a369f6ef0..c24a5eefb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditionInLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditionInLoop.java @@ -2,12 +2,10 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestConditionInLoop extends IntegrationTest { @@ -26,27 +24,25 @@ public class TestConditionInLoop extends IntegrationTest { } public void check() { - assertThat(test(5, 9), is(115)); - assertThat(test(8, 23), is(1015807)); + assertThat(test(5, 9)).isEqualTo(115); + assertThat(test(8, 23)).isEqualTo(1015807); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (int i = a; i < b; i++) {")); - assertThat(code, containsOne("c += 2;")); - assertThat(code, containsOne("c *= 2;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (int i = a; i < b; i++) {") + .containsOne("c += 2;") + .containsOne("c *= 2;"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions.java index 55e298f83..020b635e1 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions.java @@ -2,12 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestConditions extends IntegrationTest { @@ -19,10 +16,9 @@ public class TestConditions extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("(!a || !b) && !c"))); - assertThat(code, containsString("return (a && b) || c;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("(!a || !b) && !c") + .contains("return (a && b) || c;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions10.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions10.java index 7fdebd6a2..7dbbac88e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions10.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions10.java @@ -2,13 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestConditions10 extends IntegrationTest { @@ -29,16 +25,15 @@ public class TestConditions10 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("return"))); - assertThat(code, containsOne("if (a || b > 2) {")); - assertThat(code, containsOne("b++;")); - assertThat(code, containsOne("if (!a || (b >= 0 && b <= 11)) {")); - assertThat(code, containsOne("System.out.println(\"1\");")); - assertThat(code, containsOne("} else {")); - assertThat(code, containsOne("System.out.println(\"2\");")); - assertThat(code, containsOne("System.out.println(\"3\");")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("return") + .containsOne("if (a || b > 2) {") + .containsOne("b++;") + .containsOne("if (!a || (b >= 0 && b <= 11)) {") + .containsOne("System.out.println(\"1\");") + .containsOne("} else {") + .containsOne("System.out.println(\"2\");") + .containsOne("System.out.println(\"3\");"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions11.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions11.java index bb9b6104d..4f7a42328 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions11.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions11.java @@ -2,13 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestConditions11 extends IntegrationTest { @@ -26,12 +22,11 @@ public class TestConditions11 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (a || b > 2) {")); - assertThat(code, containsOne("f();")); - assertThat(code, not(containsString("return"))); - assertThat(code, not(containsString("else"))); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (a || b > 2) {") + .containsOne("f();") + .doesNotContain("return") + .doesNotContain("else"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions12.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions12.java index 2d386159d..2f0551a81 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions12.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions12.java @@ -2,13 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions12 extends IntegrationTest { @@ -54,16 +49,15 @@ public class TestConditions12 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (quality >= 10 && raw != 0) {")); - assertThat(code, containsOne("} else if (raw == 0 || quality < 6 || !qualityReading) {")); - assertThat(code, containsOne("if (quality < 30) {")); - assertThat(code, containsOne("if (quality >= 10) {")); - assertThat(code, containsOne("if (raw > 0) {")); - assertThat(code, containsOne("if (quality >= 30 && autoStop) {")); - assertThat(code, containsOne("if (!autoStop && lastValidRaw > -1 && quality < 10) {")); - assertThat(code, not(containsString("return"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (quality >= 10 && raw != 0) {") + .containsOne("} else if (raw == 0 || quality < 6 || !qualityReading) {") + .containsOne("if (quality < 30) {") + .containsOne("if (quality >= 10) {") + .containsOne("if (raw > 0) {") + .containsOne("if (quality >= 30 && autoStop) {") + .containsOne("if (!autoStop && lastValidRaw > -1 && quality < 10) {") + .doesNotContain("return"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions13.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions13.java index 7c67f1a69..8972f77a1 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions13.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions13.java @@ -2,13 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions13 extends IntegrationTest { @@ -29,13 +24,12 @@ public class TestConditions13 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (quality >= 10 && raw != 0) {")); - assertThat(code, containsOne("System.out.println(\"OK\" + raw);")); - assertThat(code, containsOne("qualityReading = false;")); - assertThat(code, containsOne("} else if (raw == 0 || quality < 6 || !qualityReading) {")); - assertThat(code, not(containsString("return"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (quality >= 10 && raw != 0) {") + .containsOne("System.out.println(\"OK\" + raw);") + .containsOne("qualityReading = false;") + .containsOne("} else if (raw == 0 || quality < 6 || !qualityReading) {") + .doesNotContain("return"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions14.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions14.java index f7131a43c..80cb24c3b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions14.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions14.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions14 extends IntegrationTest { @@ -25,11 +22,10 @@ public class TestConditions14 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("boolean r = a == null ? b != null : !a.equals(b);")); - assertThat(code, containsOne("if (r) {")); - assertThat(code, containsOne("System.out.println(\"r=\" + r);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("boolean r = a == null ? b != null : !a.equals(b);") + .containsOne("if (r) {") + .containsOne("System.out.println(\"r=\" + r);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions15.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions15.java index 0a5e9eac4..f65b48392 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions15.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions15.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions15 extends IntegrationTest { @@ -59,10 +56,9 @@ public class TestConditions15 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("\"1\".equals(name)")); - assertThat(code, containsOne("\"30\".equals(name)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("\"1\".equals(name)") + .containsOne("\"30\".equals(name)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions16.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions16.java index 8bea89d55..eb33d9d1e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions16.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions16.java @@ -2,13 +2,10 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestConditions16 extends IntegrationTest { @@ -18,18 +15,17 @@ public class TestConditions16 extends IntegrationTest { } public void check() { - assertTrue(test(-1, 1)); - assertTrue(test(1, -1)); - assertTrue(test(29, 3)); - assertFalse(test(2, 2)); + assertThat(test(-1, 1)).isTrue(); + assertThat(test(1, -1)).isTrue(); + assertThat(test(29, 3)).isTrue(); + assertThat(test(2, 2)).isFalse(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return a < 0 || (b % 2 != 0 && a > 28) || b < 0;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return a < 0 || (b % 2 != 0 && a > 28) || b < 0;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions17.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions17.java index 21d93973a..ce3e8dca4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions17.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions17.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions17 extends IntegrationTest { @@ -27,9 +24,8 @@ public class TestConditions17 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne(" & ")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne(" & "); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions18.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions18.java index 5c689f9cf..f4b17ea83 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions18.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions18.java @@ -3,13 +3,11 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +@SuppressWarnings("CommentedOutCode") public class TestConditions18 extends SmaliTest { // @formatter:off @@ -30,23 +28,20 @@ public class TestConditions18 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, - "if (this != obj) {", - indent() + "return (obj instanceof TestConditions18) && st(this.map, ((TestConditions18) obj).map);", - "}", - "return true;")); + assertThat(getClassNodeFromSmali()) + .code() + .containsLines(2, + "if (this != obj) {", + indent() + "return (obj instanceof TestConditions18) && st(this.map, ((TestConditions18) obj).map);", + "}", + "return true;"); } @Test @NotYetImplemented public void testNYI() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, - containsOne("return this == obj || ((obj instanceof TestConditions18) && st(this.map, ((TestConditions18) obj).map));")); + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("return this == obj || ((obj instanceof TestConditions18) && st(this.map, ((TestConditions18) obj).map));"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions21.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions21.java index f7ddc6f37..ae69667d4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions21.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions21.java @@ -2,11 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestConditions21 extends SmaliTest { @@ -29,9 +27,7 @@ public class TestConditions21 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("!list.isEmpty() && list.contains(this)")); + assertThat(getClassNodeFromSmali()).code() + .containsOne("!list.isEmpty() && list.contains(this)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions4.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions4.java index 5331098ba..054b5879f 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions4.java @@ -2,12 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions4 extends IntegrationTest { @@ -20,11 +16,9 @@ public class TestConditions4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("num >= 59 && num <= 66")); - assertThat(code, containsString("? num + 1 : num;")); - assertThat(code, not(containsString("else"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("num >= 59 && num <= 66") + .contains("? num + 1 : num;").doesNotContain("else"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions5.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions5.java index c7b8281ef..ec295aaba 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions5.java @@ -2,12 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions5 extends IntegrationTest { @@ -37,13 +33,12 @@ public class TestConditions5 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("if (a1 == null) {")); - assertThat(code, containsString("if (a2 != null) {")); - assertThat(code, containsString("throw new AssertionError(a1 + \" != \" + a2);")); - assertThat(code, not(containsString("if (a1.equals(a2)) {"))); - assertThat(code, containsString("} else if (!a1.equals(a2)) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("if (a1 == null) {") + .contains("if (a2 != null) {") + .contains("throw new AssertionError(a1 + \" != \" + a2);") + .doesNotContain("if (a1.equals(a2)) {") + .contains("} else if (!a1.equals(a2)) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions6.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions6.java index 94da02fd0..ea38b4f1a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions6.java @@ -4,12 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions6 extends IntegrationTest { @@ -24,10 +20,9 @@ public class TestConditions6 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return l1.size() == 0;")); - assertThat(code, not(containsString("else"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return l1.size() == 0;") + .doesNotContain("else"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions7.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions7.java index add7b73e7..e9dba7802 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions7.java @@ -2,12 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions7 extends IntegrationTest { @@ -21,10 +17,9 @@ public class TestConditions7 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("if (i >= 0 && i < a.length) {")); - assertThat(code, not(containsString("||"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("if (i >= 0 && i < a.length) {") + .doesNotContain("||"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions8.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions8.java index 2cab61d52..8bf327035 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions8.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions8.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions8 extends IntegrationTest { @@ -60,9 +57,8 @@ public class TestConditions8 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("showMore();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("showMore();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions9.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions9.java index 9325627bb..ab0df2931 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions9.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestConditions9.java @@ -2,13 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConditions9 extends IntegrationTest { @@ -24,13 +19,12 @@ public class TestConditions9 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (!a || (b >= 0 && b <= 11)) {")); - assertThat(code, containsOne("System.out.println('1');")); - assertThat(code, containsOne("} else {")); - assertThat(code, containsOne("System.out.println('2');")); - assertThat(code, not(containsString("return;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (!a || (b >= 0 && b <= 11)) {") + .containsOne("System.out.println('1');") + .containsOne("} else {") + .containsOne("System.out.println('2');") + .doesNotContain("return;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestElseIf.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestElseIf.java index f3de85e2b..f346673e8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestElseIf.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestElseIf.java @@ -2,13 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; @SuppressWarnings("IfCanBeSwitch") public class TestElseIf extends IntegrationTest { @@ -35,16 +31,14 @@ public class TestElseIf extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("} else if (str.equals(\"b\")) {")); - assertThat(code, containsOne("} else {")); - assertThat(code, containsOne("int r;")); - assertThat(code, containsOne("r = 1;")); - assertThat(code, containsOne("r = -1;")); - // no ternary operator - assertThat(code, not(containsString(" ? "))); - assertThat(code, not(containsString(" : "))); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} else if (str.equals(\"b\")) {") + .containsOne("} else {") + .containsOne("int r;") + .containsOne("r = 1;") + .containsOne("r = -1;") + .doesNotContain(" ? ") + .doesNotContain(" : "); // no ternary operator } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestInnerAssign.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestInnerAssign.java index 888081c0f..3ce3881dd 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestInnerAssign.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestInnerAssign.java @@ -2,12 +2,10 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInnerAssign extends IntegrationTest { @@ -33,9 +31,9 @@ public class TestInnerAssign extends IntegrationTest { } public void check() { - assertThat(runTest(""), is("bad, str: ")); - assertThat(runTest("1234"), is("good, len: 4, str: 1234")); - assertThat(runTest("1234567"), is("bad, str: 1234567")); + assertThat(runTest("")).isEqualTo("bad, str: "); + assertThat(runTest("1234")).isEqualTo("good, len: 4, str: 1234"); + assertThat(runTest("1234567")).isEqualTo("bad, str: 1234567"); } } @@ -43,10 +41,9 @@ public class TestInnerAssign extends IntegrationTest { public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("str.length()")); - assertThat(code, containsOne("System.out.println(\"done\");")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("str.length()") + .containsOne("System.out.println(\"done\");"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf.java index 148bdb608..b8d4a04cb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf.java @@ -2,12 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestNestedIf extends IntegrationTest { @@ -33,14 +30,13 @@ public class TestNestedIf extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (this.a0) {")); - assertThat(code, containsOne("if (this.a1 == 0 || this.a2 == 0) {")); - assertThat(code, containsOne("} else if (this.a3 == 0 || this.a4 == 0) {")); - assertThat(code, countString(2, "return false;")); - assertThat(code, containsOne("test1();")); - assertThat(code, containsOne("return true;")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (this.a0) {") + .containsOne("if (this.a1 == 0 || this.a2 == 0) {") + .containsOne("} else if (this.a3 == 0 || this.a4 == 0) {") + .countString(2, "return false;") + .containsOne("test1();") + .containsOne("return true;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf2.java index 51c232e14..5bd939c1d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestNestedIf2.java @@ -2,13 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestNestedIf2 extends IntegrationTest { @@ -46,11 +41,10 @@ public class TestNestedIf2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (executedCount != repeatCount && isRun(delta, object)) {")); - assertThat(code, containsOne("if (finished) {")); - assertThat(code, not(containsString("else"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (executedCount != repeatCount && isRun(delta, object)) {") + .containsOne("if (finished) {") + .doesNotContain("else"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestSimpleConditions.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestSimpleConditions.java index fa1f4514c..60dbb1e32 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestSimpleConditions.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestSimpleConditions.java @@ -2,11 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSimpleConditions extends IntegrationTest { @@ -22,10 +19,9 @@ public class TestSimpleConditions extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return (a[0] && a[1] && a[2]) || (a[3] && a[4]);")); - assertThat(code, containsString("return a[0] || a[1] || a[2] || a[3];")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return (a[0] && a[1] && a[2]) || (a[3] && a[4]);") + .contains("return a[0] || a[1] || a[2] || a[3];"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary.java index c6c9c555f..bf3dfc69e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary.java @@ -2,12 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTernary extends IntegrationTest { @@ -30,12 +27,11 @@ public class TestTernary extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("else"))); - assertThat(code, containsString("return a != 2;")); - assertThat(code, containsString("checkTrue(a == 3)")); - assertThat(code, containsString("return a > 0 ? a : (a + 2) * 3;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("else") + .contains("return a != 2;") + .contains("checkTrue(a == 3)") + .contains("return a > 0 ? a : (a + 2) * 3;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary2.java index 4080695d3..69437a6a3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary2.java @@ -3,12 +3,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTernary2 extends IntegrationTest { @@ -31,18 +28,16 @@ public class TestTernary2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertEquals(1, count(code, "f(1, 0)")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("f(1, 0)"); } @Test @NotYetImplemented public void test2() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("assertTrue(f(1, 0) == 0);")); + assertThat(getClassNode(TestCls.class)) + .code() + .contains("assertTrue(f(1, 0) == 0);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary3.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary3.java index a0bcfc107..34766ca1c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernary3.java @@ -5,13 +5,8 @@ import org.junit.jupiter.api.Test; import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.Named; import jadx.core.dex.instructions.args.RegisterArg; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTernary3 extends IntegrationTest { @@ -38,12 +33,10 @@ public class TestTernary3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (n == null || !(arg instanceof Named)) {")); - assertThat(code, containsOne("return n.equals(((Named) arg).getName());")); - - assertThat(code, not(containsString("if ((arg instanceof RegisterArg)) {"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (n == null || !(arg instanceof Named)) {") + .containsOne("return n.equals(((Named) arg).getName());") + .doesNotContain("if ((arg instanceof RegisterArg)) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryInIf2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryInIf2.java index c3e033b4c..334b1ec16 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryInIf2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryInIf2.java @@ -3,12 +3,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTernaryInIf2 extends SmaliTest { @@ -29,39 +26,36 @@ public class TestTernaryInIf2 extends SmaliTest { TestCls other = new TestCls(); other.a = "a"; other.b = "b"; - assertThat(this.equals(other), is(true)); + assertThat(this.equals(other)).isTrue(); other.b = "not-b"; - assertThat(this.equals(other), is(false)); + assertThat(this.equals(other)).isFalse(); other.b = null; - assertThat(this.equals(other), is(false)); + assertThat(this.equals(other)).isFalse(); this.b = null; - assertThat(this.equals(other), is(true)); + assertThat(this.equals(other)).isTrue(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, "if (this.a != null ? this.a.equals(other.a) : other.a == null) {")); - // assertThat(code, containsLines(3, "if (this.b != null ? this.b.equals(other.b) : other.b == null) - // {")); - // assertThat(code, containsLines(4, "return true;")); - // assertThat(code, containsLines(2, "return false;")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(2, "if (this.a != null ? this.a.equals(other.a) : other.a == null) {"); + // .containsLines(3, "if (this.b != null ? this.b.equals(other.b) : other.b == null) {") + // .containsLines(4, "return true;") + // .containsLines(2, "return false;") } @Test @NotYetImplemented public void testNYI() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, "return (this.a != null ? this.a.equals(other.a) : other.a == null) " - + "&& (this.b == null ? other.b == null : this.b.equals(other.b));")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(2, "return (this.a != null ? this.a.equals(other.a) : other.a == null) " + + "&& (this.b == null ? other.b == null : this.b.equals(other.b));"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor.java index 4a664a014..de16f4203 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor.java @@ -2,13 +2,8 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTernaryOneBranchInConstructor extends IntegrationTest { @@ -23,12 +18,11 @@ public class TestTernaryOneBranchInConstructor extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("this(str == null ? 0 : i);")); - assertThat(code, not(containsString("//"))); - assertThat(code, not(containsString("call moved to the top of the method"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("this(str == null ? 0 : i);") + .doesNotContain("//") + .doesNotContain("call moved to the top of the method"); } public static class TestCls2 { @@ -43,10 +37,9 @@ public class TestTernaryOneBranchInConstructor extends IntegrationTest { @Test public void test2() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("this(i == 1 ? str : \"\", i == 0 ? \"\" : str);")); - assertThat(code, not(containsString("//"))); + JadxAssertions.assertThat(getClassNode(TestCls2.class)) + .code() + .containsOne("this(i == 1 ? str : \"\", i == 0 ? \"\" : str);") + .doesNotContain("//"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor2.java index 55523cd7d..db2fbae1e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestTernaryOneBranchInConstructor2.java @@ -2,13 +2,9 @@ package jadx.tests.integration.conditions; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTernaryOneBranchInConstructor2 extends SmaliTest { @@ -26,12 +22,9 @@ public class TestTernaryOneBranchInConstructor2 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("this(str, (i & 2) != 0 ? \"\" : str2," - + " (i & 4) != 0 ? \"\" : str3," - + " (i & 8) != 0 ? false : z);")); - assertThat(code, not(containsString("//"))); + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("this(str, (i & 2) != 0 ? \"\" : str2, (i & 4) != 0 ? \"\" : str3, (i & 8) != 0 ? false : z);") + .doesNotContain("//"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers.java b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers.java index 5d0be4724..bf47154c3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers.java +++ b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers.java @@ -9,9 +9,7 @@ import jadx.core.dex.nodes.FieldNode; import jadx.core.dex.nodes.MethodNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestLineNumbers extends IntegrationTest { @@ -55,11 +53,11 @@ public class TestLineNumbers extends IntegrationTest { FieldNode innerField = inner.searchFieldByName("innerField"); // check source lines (available only for instructions and methods) - int testClassLine = 18; - assertEquals(testClassLine + 3, func.getSourceLine()); - assertEquals(testClassLine + 9, innerFunc.getSourceLine()); - assertEquals(testClassLine + 12, innerFunc2.getSourceLine()); - assertEquals(testClassLine + 20, innerFunc3.getSourceLine()); + int testClassLine = 16; + assertThat(testClassLine + 3).isEqualTo(func.getSourceLine()); + assertThat(testClassLine + 9).isEqualTo(innerFunc.getSourceLine()); + assertThat(testClassLine + 12).isEqualTo(innerFunc2.getSourceLine()); + assertThat(testClassLine + 20).isEqualTo(innerFunc3.getSourceLine()); // check decompiled lines checkLine(code, field, "int field;"); @@ -73,6 +71,6 @@ public class TestLineNumbers extends IntegrationTest { private static void checkLine(String code, LineAttrNode node, String str) { String line = CodeUtils.getLineForPos(code, node.getDefPosition()); - assertThat(line, containsString(str)); + assertThat(line).contains(str); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers2.java b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers2.java index a7bac3430..f8c690846 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestLineNumbers2.java @@ -7,7 +7,7 @@ import jadx.tests.api.IntegrationTest; import jadx.tests.api.extensions.profiles.TestProfile; import jadx.tests.api.extensions.profiles.TestWithProfiles; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestLineNumbers2 extends IntegrationTest { @@ -39,9 +39,9 @@ public class TestLineNumbers2 extends IntegrationTest { ClassNode cls = getClassNode(TestCls.class); String linesMapStr = cls.getCode().getCodeMetadata().getLineMapping().toString(); if (isJavaInput()) { - assertEquals("{6=16, 9=17, 12=21, 13=22, 14=23, 15=24, 16=25, 18=27, 21=30, 22=31}", linesMapStr); + assertThat(linesMapStr).isEqualTo("{6=16, 9=17, 12=21, 13=22, 14=23, 15=24, 16=25, 18=27, 21=30, 22=31}"); } else { - assertEquals("{6=16, 9=17, 12=21, 13=22, 14=23, 15=24, 16=25, 17=27, 19=27, 22=30, 23=31}", linesMapStr); + assertThat(linesMapStr).isEqualTo("{6=16, 9=17, 12=21, 13=22, 14=23, 15=24, 16=25, 17=27, 19=27, 22=30, 23=31}"); } } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestReturnSourceLine.java b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestReturnSourceLine.java index 5cec03476..32437e827 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestReturnSourceLine.java +++ b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestReturnSourceLine.java @@ -9,10 +9,8 @@ import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.MethodNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestReturnSourceLine extends IntegrationTest { @@ -73,9 +71,9 @@ public class TestReturnSourceLine extends IntegrationTest { private static void checkLine(String[] lines, ICodeInfo cw, LineAttrNode node, int offset, String str) { int nodeDefLine = CodeUtils.getLineNumForPos(cw.getCodeStr(), node.getDefPosition(), "\n"); int decompiledLine = nodeDefLine + offset; - assertThat(lines[decompiledLine - 1], containsOne(str)); + assertThat(lines[decompiledLine - 1]).containsOne(str); Integer sourceLine = cw.getCodeMetadata().getLineMapping().get(decompiledLine); - assertNotNull(sourceLine); - assertEquals(node.getSourceLine() + offset, (int) sourceLine); + assertThat(sourceLine).isNotNull(); + assertThat((int) sourceLine).isEqualTo(node.getSourceLine() + offset); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestVariablesNames.java b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestVariablesNames.java index 92994adad..b85722b48 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestVariablesNames.java +++ b/jadx-core/src/test/java/jadx/tests/integration/debuginfo/TestVariablesNames.java @@ -2,11 +2,9 @@ package jadx.tests.integration.debuginfo; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestVariablesNames extends SmaliTest { // @formatter:off @@ -41,12 +39,11 @@ public class TestVariablesNames extends SmaliTest { */ @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPath("debuginfo", "TestVariablesNames"); - String code = cls.getCode().toString(); - - // TODO: don't use current variables naming in tests - assertThat(code, containsOne("f1(str);")); - assertThat(code, containsOne("f2(i2, \"i\" + i2);")); - assertThat(code, containsOne("f3(d, \"d\" + d);")); + assertThat(getClassNodeFromSmaliWithPath("debuginfo", "TestVariablesNames")) + .code() + // TODO: don't use current variables naming in tests + .containsOne("f1(str);") + .containsOne("f2(i2, \"i\" + i2);") + .containsOne("f3(d, \"d\" + d);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/deobf/TestMthRename.java b/jadx-core/src/test/java/jadx/tests/integration/deobf/TestMthRename.java index 55c84a034..7904e2216 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/deobf/TestMthRename.java +++ b/jadx-core/src/test/java/jadx/tests/integration/deobf/TestMthRename.java @@ -2,12 +2,9 @@ package jadx.tests.integration.deobf; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestMthRename extends IntegrationTest { @@ -26,11 +23,8 @@ public class TestMthRename extends IntegrationTest { public void test() { noDebugInfo(); enableDeobfuscation(); - - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("public abstract void a();"))); - assertThat(code, not(containsString(".a();"))); + assertThat(getClassNode(TestCls.class)).code() + .doesNotContain("public abstract void a();") + .doesNotContain(".a();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithConstInlining.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithConstInlining.java index 4ac6b61dd..7f8ab29cc 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithConstInlining.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithConstInlining.java @@ -2,11 +2,8 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestEnumWithConstInlining extends SmaliTest { enum TestCls { @@ -120,9 +117,8 @@ public class TestEnumWithConstInlining extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("E42,")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("E42,"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithFields.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithFields.java index 0daf1cb5b..48a4b4d6a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithFields.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumWithFields.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestEnumWithFields extends SmaliTest { @@ -25,10 +25,10 @@ public class TestEnumWithFields extends SmaliTest { } public void check() { - assertEquals(0, SearchTimeout.DISABLED.sec); - assertEquals(0, SearchTimeout.DEFAULT.sec); - assertEquals(2, SearchTimeout.TWO_SECONDS.sec); - assertEquals(5, SearchTimeout.MAX.sec); + assertThat(SearchTimeout.DISABLED.sec).isEqualTo(0); + assertThat(SearchTimeout.DEFAULT.sec).isEqualTo(0); + assertThat(SearchTimeout.TWO_SECONDS.sec).isEqualTo(2); + assertThat(SearchTimeout.MAX.sec).isEqualTo(5); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums.java index 1f64482bb..9c7cc4998 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums.java @@ -2,11 +2,9 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestEnums extends IntegrationTest { @@ -41,31 +39,28 @@ public class TestEnums extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(1, "public enum EmptyEnum {", "}")); - assertThat(code, containsLines(1, - "public enum EmptyEnum2 {", - indent(1) + ';', - "", - indent(1) + "public static void mth() {", - indent(1) + '}', - "}")); - - assertThat(code, containsLines(1, "public enum Direction {", - indent(1) + "NORTH,", - indent(1) + "SOUTH,", - indent(1) + "EAST,", - indent(1) + "WEST", - "}")); - - assertThat(code, containsLines(1, "public enum Singleton {", - indent(1) + "INSTANCE;", - "", - indent(1) + "public String test() {", - indent(2) + "return \"\";", - indent(1) + '}', - "}")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(1, "public enum EmptyEnum {", "}") + .containsLines(1, + "public enum EmptyEnum2 {", + indent(1) + ';', + "", + indent(1) + "public static void mth() {", + indent(1) + '}', + "}") + .containsLines(1, "public enum Direction {", + indent(1) + "NORTH,", + indent(1) + "SOUTH,", + indent(1) + "EAST,", + indent(1) + "WEST", + "}") + .containsLines(1, "public enum Singleton {", + indent(1) + "INSTANCE;", + "", + indent(1) + "public String test() {", + indent(2) + "return \"\";", + indent(1) + '}', + "}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums3.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums3.java index 963f03fcc..e78d366d5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums3.java @@ -2,12 +2,10 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestEnums3 extends IntegrationTest { @@ -30,20 +28,19 @@ public class TestEnums3 extends IntegrationTest { } public void check() { - assertEquals(1, Numbers.ONE.getNum()); - assertEquals(3, Numbers.THREE.getNum()); - assertEquals(4, Numbers.FOUR.getNum()); + assertThat(Numbers.ONE.getNum()).isEqualTo(1); + assertThat(Numbers.THREE.getNum()).isEqualTo(3); + assertThat(Numbers.FOUR.getNum()).isEqualTo(4); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("ONE(1)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("ONE(1)") + .containsOne("Numbers(int n) {"); // assertThat(code, containsOne("THREE(three)")); // assertThat(code, containsOne("assertTrue(Numbers.ONE.getNum() == 1);")); - assertThat(code, containsOne("Numbers(int n) {")); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums4.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums4.java index 8318c05aa..c4ef516cf 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums4.java @@ -2,12 +2,10 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestEnums4 extends IntegrationTest { @@ -34,17 +32,16 @@ public class TestEnums4 extends IntegrationTest { } public void check() { - assertThat(ResType.CODE.getExts(), is(new String[] { ".dex", ".class" })); + assertThat(ResType.CODE.getExts()).containsExactly(new String[] { ".dex", ".class" }); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("CODE(\".dex\", \".class\"),")); - assertThat(code, containsOne("ResType(String... extensions) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("CODE(\".dex\", \".class\"),") + .containsOne("ResType(String... extensions) {"); // assertThat(code, not(containsString("private ResType"))); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums6.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums6.java index bc88c0437..bedc73526 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums6.java @@ -1,11 +1,11 @@ package jadx.tests.integration.enums; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestEnums6 extends IntegrationTest { @@ -30,8 +30,8 @@ public class TestEnums6 extends IntegrationTest { } public void check() { - Assertions.assertThat(TestCls.Numbers.ZERO.getN()).isEqualTo(0); - Assertions.assertThat(TestCls.Numbers.ONE.getN()).isEqualTo(1); + assertThat(TestCls.Numbers.ZERO.getN()).isEqualTo(0); + assertThat(TestCls.Numbers.ONE.getN()).isEqualTo(1); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumsWithConsts.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumsWithConsts.java index 6734bc8b4..2f63be57a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumsWithConsts.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestEnumsWithConsts.java @@ -2,11 +2,9 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestEnumsWithConsts extends IntegrationTest { @@ -28,14 +26,13 @@ public class TestEnumsWithConsts extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(1, "public enum Direction {", - indent(1) + "NORTH,", - indent(1) + "SOUTH,", - indent(1) + "EAST,", - indent(1) + "WEST", - "}")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(1, "public enum Direction {", + indent(1) + "NORTH,", + indent(1) + "SOUTH,", + indent(1) + "EAST,", + indent(1) + "WEST", + "}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestInnerEnums.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestInnerEnums.java index 3b59766f7..3ca404625 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestInnerEnums.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestInnerEnums.java @@ -2,12 +2,10 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestInnerEnums extends IntegrationTest { @@ -52,18 +50,17 @@ public class TestInnerEnums extends IntegrationTest { } public void check() { - assertEquals(1, Numbers.ONE.getNum()); - assertEquals(Numbers.NumString.ONE, Numbers.ONE.getNumStr()); - assertEquals("one", Numbers.ONE.getName()); + assertThat(Numbers.ONE.getNum()).isEqualTo(1); + assertThat(Numbers.ONE.getNumStr()).isEqualTo(Numbers.NumString.ONE); + assertThat(Numbers.ONE.getName()).isEqualTo("one"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("ONE((byte) 1, NumString.ONE)")); - assertThat(code, containsOne("ONE(\"one\")")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("ONE((byte) 1, NumString.ONE)") + .containsOne("ONE(\"one\")"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/enums/TestSwitchOverEnum2.java b/jadx-core/src/test/java/jadx/tests/integration/enums/TestSwitchOverEnum2.java index 7115a3f77..c453779c6 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/enums/TestSwitchOverEnum2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/enums/TestSwitchOverEnum2.java @@ -2,12 +2,10 @@ package jadx.tests.integration.enums; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestSwitchOverEnum2 extends IntegrationTest { @@ -41,17 +39,16 @@ public class TestSwitchOverEnum2 extends IntegrationTest { } public void check() { - assertEquals(21, testEnum(Count.ONE, Animal.DOG)); + assertThat(testEnum(Count.ONE, Animal.DOG)).isEqualTo(21); } @Test public void test() { - ClassNode cls = getClassNode(TestSwitchOverEnum2.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(1, "synthetic")); - assertThat(code, countString(2, "switch (c) {")); - assertThat(code, countString(2, "case ONE:")); - assertThat(code, countString(2, "case DOG:")); + assertThat(getClassNode(TestSwitchOverEnum2.class)) + .code() + .countString(1, "synthetic") + .countString(2, "switch (c) {") + .countString(2, "case ONE:") + .countString(2, "case DOG:"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackManyNops.java b/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackManyNops.java index 54d72a3be..67255aec2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackManyNops.java +++ b/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackManyNops.java @@ -2,13 +2,9 @@ package jadx.tests.integration.fallback; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestFallbackManyNops extends SmaliTest { @@ -16,12 +12,10 @@ public class TestFallbackManyNops extends SmaliTest { public void test() { setFallback(); disableCompilation(); - - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public static void test() {")); - assertThat(code, containsOne("return")); - assertThat(code, not(containsString("Method dump skipped"))); + assertThat(getClassNodeFromSmali()) + .code() + .contains("public static void test() {") + .containsOne("return") + .doesNotContain("Method dump skipped"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackMode.java b/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackMode.java index ca050599d..0980639b8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackMode.java +++ b/jadx-core/src/test/java/jadx/tests/integration/fallback/TestFallbackMode.java @@ -2,13 +2,8 @@ package jadx.tests.integration.fallback; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFallbackMode extends IntegrationTest { @@ -28,14 +23,13 @@ public class TestFallbackMode extends IntegrationTest { setFallback(); disableCompilation(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public int test(int r2) {")); - assertThat(code, containsOne("r1 = this;")); - assertThat(code, containsOne("L0:")); - assertThat(code, containsOne("L7:")); - assertThat(code, containsOne("int r2 = r2 + 1")); - assertThat(code, not(containsString("throw new UnsupportedOperationException"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("public int test(int r2) {") + .containsOne("r1 = this;") + .containsOne("L0:") + .containsOne("L7:") + .containsOne("int r2 = r2 + 1") + .doesNotContain("throw new UnsupportedOperationException"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/MissingGenericsTypesTest.java b/jadx-core/src/test/java/jadx/tests/integration/generics/MissingGenericsTypesTest.java index 8e4215e3f..0c2c7ffd7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/MissingGenericsTypesTest.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/MissingGenericsTypesTest.java @@ -3,11 +3,9 @@ package jadx.tests.integration.generics; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class MissingGenericsTypesTest extends SmaliTest { // @formatter:off @@ -27,9 +25,8 @@ public class MissingGenericsTypesTest extends SmaliTest { @Test @NotYetImplemented public void test() { - ClassNode cls = getClassNodeFromSmaliWithPath("generics", "MissingGenericsTypesTest"); - String code = cls.getCode().toString(); - - assertThat(code, containsString("Map list)")); - assertThat(code, containsString("mthExtends(List list)")); - assertThat(code, containsString("mthSuper(List list)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("mthWildcard(List list)") + .contains("mthExtends(List list)") + .contains("mthSuper(List list)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics3.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics3.java index 225d86350..70adcbddb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics3.java @@ -4,11 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics3 extends IntegrationTest { @@ -29,12 +26,11 @@ public class TestGenerics3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("mthExtendsArray(List list)")); - assertThat(code, containsString("mthSuperArray(List list)")); - assertThat(code, containsString("mthSuperInteger(List list)")); - assertThat(code, containsString("mthExtendsString(List list)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("mthExtendsArray(List list)") + .contains("mthSuperArray(List list)") + .contains("mthSuperInteger(List list)") + .contains("mthExtendsString(List list)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics4.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics4.java index 7b8bc66ba..fd9c742e4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics4.java @@ -2,12 +2,8 @@ package jadx.tests.integration.generics; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics4 extends IntegrationTest { @@ -21,10 +17,9 @@ public class TestGenerics4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("Class[] a =")); - assertThat(code, not(containsString("Class[] a ="))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("Class[] a =") + .doesNotContain("Class[] a ="); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics6.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics6.java index 51d09927b..8ef6d081e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics6.java @@ -4,11 +4,8 @@ import java.util.Collection; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics6 extends IntegrationTest { @@ -37,10 +34,9 @@ public class TestGenerics6 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (A a : as) {")); - assertThat(code, containsOne("for (I i : is) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (A a : as) {") + .containsOne("for (I i : is) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics7.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics7.java index b1691e173..76bd00838 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenerics7.java @@ -2,11 +2,8 @@ package jadx.tests.integration.generics; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics7 extends IntegrationTest { @@ -26,9 +23,8 @@ public class TestGenerics7 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("declare(String.class);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("declare(String.class);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsInArgs.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsInArgs.java index 8fdfdeec0..b729fb147 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsInArgs.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsInArgs.java @@ -5,11 +5,8 @@ import java.util.Set; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenericsInArgs extends IntegrationTest { @@ -32,20 +29,18 @@ public class TestGenericsInArgs extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public static void test(List genericList, Set set) {")); - assertThat(code, containsString("if (genericList == null) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("public static void test(List genericList, Set set) {") + .contains("if (genericList == null) {"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public static void test(List list, Set set) {")); - assertThat(code, containsString("if (list == null) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("public static void test(List list, Set set) {") + .contains("if (list == null) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsMthOverride.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsMthOverride.java index 47b2c5797..04845c2f3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsMthOverride.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestGenericsMthOverride.java @@ -2,12 +2,8 @@ package jadx.tests.integration.generics; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenericsMthOverride extends IntegrationTest { @@ -48,14 +44,12 @@ public class TestGenericsMthOverride extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public Y method(X x) {")); - assertThat(code, containsOne("public Y method(Object x) {")); - assertThat(code, containsOne("public Y method(Exception x) {")); - assertThat(code, containsOne("public Object method(Object x) {")); - - assertThat(code, countString(4, "@Override")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public Y method(X x) {") + .containsOne("public Y method(Object x) {") + .containsOne("public Y method(Exception x) {") + .containsOne("public Object method(Object x) {") + .countString(4, "@Override"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestImportGenericMap.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestImportGenericMap.java index 5f0cc280b..2342b08b7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestImportGenericMap.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestImportGenericMap.java @@ -2,12 +2,11 @@ package jadx.tests.integration.generics; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.integration.generics.TestImportGenericMap.SuperClass.NotToImport; +import static jadx.tests.integration.generics.TestImportGenericMap.SuperClass.ToImport; public class TestImportGenericMap extends IntegrationTest { @@ -28,12 +27,9 @@ public class TestImportGenericMap extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(SuperClass.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString( - "import " + SuperClass.ToImport.class.getName().replace("$ToImport", ".ToImport") + ';')); - assertThat(code, not(containsString( - "import " + SuperClass.NotToImport.class.getName().replace("NotToImport", ".NotToImport") + ';'))); + JadxAssertions.assertThat(getClassNode(SuperClass.class)) + .code() + .contains("import " + ToImport.class.getName().replace("$ToImport", ".ToImport") + ';') + .doesNotContain("import " + NotToImport.class.getName().replace("NotToImport", ".NotToImport") + ';'); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/generics/TestOuterGeneric.java b/jadx-core/src/test/java/jadx/tests/integration/generics/TestOuterGeneric.java index 70c97e5a5..1160ea4ee 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/generics/TestOuterGeneric.java +++ b/jadx-core/src/test/java/jadx/tests/integration/generics/TestOuterGeneric.java @@ -5,11 +5,8 @@ import java.util.Set; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestOuterGeneric extends IntegrationTest { @@ -60,13 +57,12 @@ public class TestOuterGeneric extends IntegrationTest { @NotYetImplemented("Instance constructor for inner classes") @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("A a = new A<>();")); - assertThat(code, containsOne("A.B b = a.new B();")); - assertThat(code, containsOne("A.C c = a.new C();")); - assertThat(code, containsOne("use(new A>().new C());")); - assertThat(code, containsOne("D.E e = d.new E();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("A a = new A<>();") + .containsOne("A.B b = a.new B();") + .containsOne("A.C c = a.new C();") + .containsOne("use(new A>().new C());") + .containsOne("D.E e = d.new E();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestConstInline.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestConstInline.java index 0948f2a3d..d10fb3560 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestConstInline.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestConstInline.java @@ -2,13 +2,8 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestConstInline extends IntegrationTest { @@ -28,11 +23,10 @@ public class TestConstInline extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return f(0);")); - assertThat(code, containsOne("return false;")); - assertThat(code, not(containsString(" = "))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return f(0);") + .containsOne("return false;") + .doesNotContain(" = "); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestGetterInlineNegative.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestGetterInlineNegative.java index 7ce971fe0..849f0b9ff 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestGetterInlineNegative.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestGetterInlineNegative.java @@ -2,13 +2,9 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestGetterInlineNegative extends SmaliTest { @@ -34,10 +30,9 @@ public class TestGetterInlineNegative extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString(indent() + "field;"))); - assertThat(code, containsOne("return field;")); + assertThat(getClassNodeFromSmali()) + .code() + .doesNotContain(indent() + "field;") + .containsOne("return field;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline.java index 66abf389b..e329b226c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline.java @@ -2,11 +2,8 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInline extends IntegrationTest { @@ -22,9 +19,8 @@ public class TestInline extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("System.out.println(\"Test: \" + new TestInline$TestCls().testRun());")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("System.out.println(\"Test: \" + new TestInline$TestCls().testRun());"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline2.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline2.java index be42bd6d8..f4275bc72 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline2.java @@ -2,11 +2,8 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInline2 extends IntegrationTest { @@ -26,11 +23,10 @@ public class TestInline2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("int[] a = {1, 2, 4, 6, 8};")); - assertThat(code, containsOne("for (int i = 0; i < a.length; i += 2) {")); - assertThat(code, containsOne("for (long i2 = b; i2 > 0; i2--) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("int[] a = {1, 2, 4, 6, 8};") + .containsOne("for (int i = 0; i < a.length; i += 2) {") + .containsOne("for (long i2 = b; i2 > 0; i2--) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline3.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline3.java index 33ce72b91..35a9ab850 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline3.java @@ -2,12 +2,8 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInline3 extends IntegrationTest { @@ -28,13 +24,11 @@ public class TestInline3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("this(b1, b2, 0, 0, 0);")); - assertThat(code, containsString("super(a, a);")); - assertThat(code, not(containsString("super(a, a).this$0"))); - - assertThat(code, containsString("public class A extends TestInline3$TestCls {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("this(b1, b2, 0, 0, 0);") + .contains("super(a, a);") + .doesNotContain("super(a, a).this$0") + .contains("public class A extends TestInline3$TestCls {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline6.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline6.java index f6778691a..33d5b5f45 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline6.java @@ -2,12 +2,8 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInline6 extends IntegrationTest { @@ -24,10 +20,9 @@ public class TestInline6 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("System.out.println(System.nanoTime() - start);")); - assertThat(code, not(containsString("System.out.println(System.nanoTime() - System.nanoTime());"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("System.out.println(System.nanoTime() - start);") + .doesNotContain("System.out.println(System.nanoTime() - System.nanoTime());"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline7.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline7.java index 9a6258c80..702478616 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestInline7.java @@ -2,13 +2,9 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInline7 extends SmaliTest { @@ -31,11 +27,10 @@ public class TestInline7 extends SmaliTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNodeFromSmaliWithPkg("inline", "TestInline7"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("Bundle arguments;"))); - assertThat(code, containsOne("Bundle arguments = getArguments();")); - assertThat(code, containsOne("@Nullable Bundle bundle")); + assertThat(getClassNodeFromSmaliWithPkg("inline", "TestInline7")) + .code() + .doesNotContain("Bundle arguments;") + .containsOne("Bundle arguments = getArguments();") + .containsOne("@Nullable Bundle bundle"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java index 060a5c7bc..82dbea398 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestIssue86.java @@ -5,11 +5,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; @SuppressWarnings("checkstyle:printstacktrace") public class TestIssue86 extends IntegrationTest { @@ -109,9 +106,8 @@ public class TestIssue86 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("response.startsWith(NOT_FOUND)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("response.startsWith(NOT_FOUND)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline.java index 140e78a4f..b6acfadb3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline.java @@ -2,12 +2,9 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSyntheticInline extends IntegrationTest { @@ -35,18 +32,17 @@ public class TestSyntheticInline extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("synthetic") + .doesNotContain("access$") + .doesNotContain("x0") + .contains("f = v;") + .contains("return TestSyntheticInline$TestCls.this.f;") - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("access$"))); - assertThat(code, not(containsString("x0"))); - assertThat(code, containsString("f = v;")); - - // assertThat(code, containsString("return f;")); - // assertThat(code, containsString("return func();")); - // Temporary solution - assertThat(code, containsString("return TestSyntheticInline$TestCls.this.f;")); - assertThat(code, containsString("return TestSyntheticInline$TestCls.this.func();")); + // .contains("return f;"); + // .contains("return func();"); + // Temporary solution + .contains("return TestSyntheticInline$TestCls.this.func();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline2.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline2.java index aa7312c92..3f1ab1af0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestSyntheticInline2.java @@ -2,12 +2,10 @@ package jadx.tests.integration.inline; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSyntheticInline2 extends IntegrationTest { @@ -43,20 +41,17 @@ public class TestSyntheticInline2 extends IntegrationTest { @Test public void test() { disableCompilation(); // strange java compiler bug - ClassNode cls = getClassNode(TestCls.class); // Base class in unknown - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("access$"))); - assertThat(code, containsString("TestSyntheticInline2$TestCls.this.call();")); - assertThat(code, containsString("TestSyntheticInline2$TestCls.super.call();")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("synthetic") + .doesNotContain("access$").contains("TestSyntheticInline2$TestCls.this.call();") + .contains("TestSyntheticInline2$TestCls.super.call();"); } @Test public void testTopClass() { - ClassNode cls = getClassNode(TestSyntheticInline2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString(indent(1) + "TestCls.super.call();")); + JadxAssertions.assertThat(getClassNode(TestSyntheticInline2.class)) + .code() + .contains(indent(1) + "TestCls.super.call();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inline/TestTernaryCast.java b/jadx-core/src/test/java/jadx/tests/integration/inline/TestTernaryCast.java index 6b078b020..babbcfbb5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inline/TestTernaryCast.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inline/TestTernaryCast.java @@ -1,13 +1,11 @@ package jadx.tests.integration.inline; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTernaryCast extends IntegrationTest { @@ -17,17 +15,16 @@ public class TestTernaryCast extends IntegrationTest { } public void check() { - assertThat(test(true, "a", "b"), Matchers.is("a")); - assertThat(test(false, "a", "b"), Matchers.is("b")); + assertThat(test(true, "a", "b")).isEqualTo("a"); + assertThat(test(false, "a", "b")).isEqualTo("b"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return (String) (b ? obj : cs);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return (String) (b ? obj : cs);"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass.java index ef2f05d00..b466f88d0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass.java @@ -5,13 +5,9 @@ import java.io.FilenameFilter; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnonymousClass extends IntegrationTest { @@ -30,25 +26,22 @@ public class TestAnonymousClass extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("new File(\"a\").list(new FilenameFilter()")); - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("this"))); - assertThat(code, not(containsString("null"))); - assertThat(code, not(containsString("AnonymousClass_"))); - assertThat(code, not(containsString("class AnonymousClass"))); + assertThat(getClassNode(TestCls.class)) + .code() + .contains("new File(\"a\").list(new FilenameFilter()") + .doesNotContain("synthetic") + .doesNotContain("this") + .doesNotContain("null") + .doesNotContain("AnonymousClass_") + .doesNotContain("class AnonymousClass"); } @Test public void testNoInline() { getArgs().setInlineAnonymousClasses(false); - - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("class AnonymousClass1 implements FilenameFilter {")); - assertThat(code, containsOne("new AnonymousClass1()")); + assertThat(getClassNode(TestCls.class)) + .code() + .contains("class AnonymousClass1 implements FilenameFilter {") + .containsOne("new AnonymousClass1()"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass10.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass10.java index 4d9791048..f65d0539d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass10.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass10.java @@ -4,13 +4,8 @@ import java.util.Random; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass10 extends IntegrationTest { @@ -37,10 +32,9 @@ public class TestAnonymousClass10 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return new A(this, a2, a2 + 3, 4, 5, random.nextDouble()) {")); - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return new A(this, a2, a2 + 3, 4, 5, random.nextDouble()) {") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass11.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass11.java index 70cafc6ec..dfc429fcf 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass11.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass11.java @@ -4,13 +4,8 @@ import java.util.Random; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass11 extends IntegrationTest { @@ -53,11 +48,10 @@ public class TestAnonymousClass11 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("System.out.println(\"a\" + a);")); - assertThat(code, containsOne("print(a);")); - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("System.out.println(\"a\" + a);") + .containsOne("print(a);") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass12.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass12.java index f5dc380e7..89cc398d6 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass12.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass12.java @@ -2,11 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass12 extends IntegrationTest { @@ -36,11 +33,10 @@ public class TestAnonymousClass12 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("outer = new BasicAbstract() {")); - assertThat(code, containsOne("inner = new BasicAbstract() {")); - assertThat(code, containsOne("inner = null;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("outer = new BasicAbstract() {") + .containsOne("inner = new BasicAbstract() {") + .containsOne("inner = null;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass15.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass15.java index a31e964ed..e8c7baa2b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass15.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass15.java @@ -2,12 +2,9 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnonymousClass15 extends IntegrationTest { @@ -38,10 +35,9 @@ public class TestAnonymousClass15 extends IntegrationTest { @Test public void test() { - ClassNode classNode = getClassNode(TestCls.class); - String code = classNode.getCode().toString(); - - assertThat(code, countString(2, "return new Thread(run) {")); - assertThat(code, containsOne("setName(\"run\");")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(2, "return new Thread(run) {") + .containsOne("setName(\"run\");"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass2.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass2.java index ee816efd0..596e5376f 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass2.java @@ -2,12 +2,9 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnonymousClass2 extends IntegrationTest { @@ -48,14 +45,13 @@ public class TestAnonymousClass2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("AnonymousClass_"))); - assertThat(code, containsString("f = 1;")); - assertThat(code, containsString("f = i;")); - assertThat(code, not(containsString("Inner obj = ;"))); - assertThat(code, containsString("Inner.this;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("synthetic") + .doesNotContain("AnonymousClass_") + .contains("f = 1;") + .contains("f = i;") + .doesNotContain("Inner obj = ;") + .contains("Inner.this;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass3.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass3.java index 109f6925c..2d6cb1b07 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass3.java @@ -3,12 +3,10 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnonymousClass3 extends IntegrationTest { @@ -43,23 +41,20 @@ public class TestAnonymousClass3 extends IntegrationTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString(indent(4) + "public void run() {")); - assertThat(code, containsString(indent(3) + "}.start();")); - - assertThat(code, not(containsString("AnonymousClass_"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains(indent(4) + "public void run() {") + .contains(indent(3) + "}.start();") + .doesNotContain("AnonymousClass_"); } @Test @NotYetImplemented public void test2() { disableCompilation(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("synthetic"))); - assertThat(code, containsString("a = f--;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("synthetic") + .contains("a = f--;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass4.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass4.java index 10dcba57b..077acdbbb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass4.java @@ -2,12 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass4 extends IntegrationTest { @@ -34,15 +30,14 @@ public class TestAnonymousClass4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne(indent(3) + "new Thread() {")); - assertThat(code, containsOne(indent(4) + '{')); - assertThat(code, containsOne("f = 1;")); - assertThat(code, countString(2, indent(4) + '}')); - assertThat(code, containsOne(indent(4) + "public void run() {")); - assertThat(code, containsOne("d = 7.5")); - assertThat(code, containsOne(indent(3) + "}.start();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne(indent(3) + "new Thread() {") + .containsOne(indent(4) + '{') + .containsOne("f = 1;") + .countString(2, indent(4) + '}') + .containsOne(indent(4) + "public void run() {") + .containsOne("d = 7.5") + .containsOne(indent(3) + "}.start();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass5.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass5.java index c239f5e00..42dee0465 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass5.java @@ -7,15 +7,10 @@ import java.util.Map; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.sameInstance; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAnonymousClass5 extends IntegrationTest { @@ -67,20 +62,18 @@ public class TestAnonymousClass5 extends IntegrationTest { map.put("a", v); Iterable it = test("a"); TestCls next = it.iterator().next(); - assertThat(next, sameInstance(v)); - assertThat(next.a, is(4)); + assertThat(next).isSameAs(v); + assertThat(next.a).isEqualTo(4); } } @Test @NotYetImplemented public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("map.get(name);")); - assertThat(code, not(containsString("access$008"))); - - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("map.get(name);") + .doesNotContain("access$008") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass6.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass6.java index 30441b1dd..795fb6ccd 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass6.java @@ -2,13 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass6 extends IntegrationTest { @@ -24,13 +19,12 @@ public class TestAnonymousClass6 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public Runnable test(final double d) {")); - assertThat(code, containsOne("return new Runnable() {")); - assertThat(code, containsOne("public void run() {")); - assertThat(code, containsOne("System.out.println(d);")); - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public Runnable test(final double d) {") + .containsOne("return new Runnable() {") + .containsOne("public void run() {") + .containsOne("System.out.println(d);") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass7.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass7.java index b5e40a82f..06e1347bc 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass7.java @@ -2,13 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass7 extends IntegrationTest { @@ -24,13 +19,12 @@ public class TestAnonymousClass7 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public static Runnable test(final double d) {")); - assertThat(code, containsOne("return new Runnable() {")); - assertThat(code, containsOne("public void run() {")); - assertThat(code, containsOne("System.out.println(d);")); - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public static Runnable test(final double d) {") + .containsOne("return new Runnable() {") + .containsOne("public void run() {") + .containsOne("System.out.println(d);") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass8.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass8.java index 1dbf88d47..dabebbb25 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass8.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass8.java @@ -2,13 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass8 extends IntegrationTest { @@ -27,13 +22,12 @@ public class TestAnonymousClass8 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public Runnable test() {")); - assertThat(code, containsOne("return new Runnable() {")); - assertThat(code, containsOne("public void run() {")); - assertThat(code, containsOne("this.d);")); - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public Runnable test() {") + .containsOne("return new Runnable() {") + .containsOne("public void run() {") + .containsOne("this.d);") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass9.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass9.java index 5733292e2..0878b6af5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass9.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestAnonymousClass9.java @@ -5,13 +5,8 @@ import java.util.concurrent.FutureTask; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestAnonymousClass9 extends IntegrationTest { @@ -35,11 +30,10 @@ public class TestAnonymousClass9 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("c = new Callable() {")); - assertThat(code, containsOne("return new FutureTask(this.c) {")); - assertThat(code, not(containsString("synthetic"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("c = new Callable() {") + .containsOne("return new FutureTask(this.c) {") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestIncorrectAnonymousClass.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestIncorrectAnonymousClass.java index 881b59528..46dc7e244 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestIncorrectAnonymousClass.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestIncorrectAnonymousClass.java @@ -2,12 +2,9 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIncorrectAnonymousClass extends SmaliTest { @@ -29,10 +26,9 @@ public class TestIncorrectAnonymousClass extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliFiles("TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public final class AnonymousClass1 {")); - assertThat(code, countString(2, "new AnonymousClass1();")); + assertThat(getClassNodeFromSmaliFiles("TestCls")) + .code() + .containsOne("public final class AnonymousClass1 {") + .countString(2, "new AnonymousClass1();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInner2Samples.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInner2Samples.java index 0ffa58520..fdfaf0eb8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInner2Samples.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInner2Samples.java @@ -2,13 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInner2Samples extends IntegrationTest { @@ -66,11 +61,10 @@ public class TestInner2Samples extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestInner2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("setD(\"d\");")); - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("access$"))); + JadxAssertions.assertThat(getClassNode(TestInner2.class)) + .code() + .containsOne("setD(\"d\");") + .doesNotContain("synthetic") + .doesNotContain("access$"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass.java index ec89ff6a1..455bce292 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass.java @@ -2,12 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInnerClass extends IntegrationTest { @@ -20,13 +16,12 @@ public class TestInnerClass extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("Inner {")); - assertThat(code, containsString("Inner2 extends Thread {")); - assertThat(code, not(containsString("super();"))); - assertThat(code, not(containsString("this$"))); - assertThat(code, not(containsString("/* synthetic */"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("Inner {") + .contains("Inner2 extends Thread {") + .doesNotContain("super();") + .doesNotContain("this$") + .doesNotContain("/* synthetic */"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass2.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass2.java index 889d0eb06..cb5bdf1fe 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass2.java @@ -5,12 +5,8 @@ import java.util.TimerTask; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInnerClass2 extends IntegrationTest { @@ -29,13 +25,12 @@ public class TestInnerClass2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("new Timer().schedule(new TerminateTask(), 1000L);")); - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("this"))); - assertThat(code, not(containsString("null"))); - assertThat(code, not(containsString("AnonymousClass"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("new Timer().schedule(new TerminateTask(), 1000L);") + .doesNotContain("synthetic") + .doesNotContain("this") + .doesNotContain("null") + .doesNotContain("AnonymousClass"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass3.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass3.java index 0e40e7246..8b27dc079 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass3.java @@ -2,12 +2,9 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInnerClass3 extends IntegrationTest { @@ -28,12 +25,11 @@ public class TestInnerClass3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("synthetic"))); - assertThat(code, not(containsString("access$"))); - assertThat(code, not(containsString("x0"))); - assertThat(code, containsString("setC(\"c\");")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("synthetic") + .doesNotContain("access$") + .doesNotContain("x0") + .contains("setC(\"c\");"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass4.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass4.java index f026a45b1..43d36db78 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass4.java @@ -2,11 +2,8 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInnerClass4 extends IntegrationTest { @@ -26,9 +23,8 @@ public class TestInnerClass4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return new C().c;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return new C().c;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass5.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass5.java index 625c6165d..a20b52a2e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClass5.java @@ -2,12 +2,10 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestInnerClass5 extends IntegrationTest { @@ -83,17 +81,16 @@ public class TestInnerClass5 extends IntegrationTest { } public void check() throws Exception { - assertEquals("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a", new I0().i()); - assertEquals("i1", i0); + assertThat(new I0().i()).isEqualTo("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a"); + assertThat(i0).isEqualTo("i1"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public class I0 {")); - assertThat(code, containsOne("public class I1 {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public class I0 {") + .containsOne("public class I1 {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassFakeSyntheticConstructor.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassFakeSyntheticConstructor.java index f4634caf3..711b2af63 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassFakeSyntheticConstructor.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassFakeSyntheticConstructor.java @@ -2,11 +2,9 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInnerClassFakeSyntheticConstructor extends SmaliTest { @@ -29,10 +27,9 @@ public class TestInnerClassFakeSyntheticConstructor extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali("inner/TestInnerClassFakeSyntheticConstructor", "jadx.tests.inner.TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("TestCls(String a) {")); + assertThat(getClassNodeFromSmali("inner/TestInnerClassFakeSyntheticConstructor", "jadx.tests.inner.TestCls")) + .code() + .containsOne("TestCls(String a) {"); // and must compile } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticRename.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticRename.java index 888a14784..b4a33b917 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticRename.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestInnerClassSyntheticRename.java @@ -2,21 +2,18 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; /** - * Issue: https://github.com/skylot/jadx/issues/336 + * Issue: #336 */ +@SuppressWarnings("CommentedOutCode") public class TestInnerClassSyntheticRename extends SmaliTest { // @formatter:off /* - private class MyAsync extends AsyncTask> { + private class TestCls extends AsyncTask> { @Override protected List doInBackground(Uri... uris) { Log.i("MyAsync", "doInBackground"); @@ -34,11 +31,10 @@ public class TestInnerClassSyntheticRename extends SmaliTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNodeFromSmali("inner/TestInnerClassSyntheticRename", "com.github.skylot.testasync.MyAsync"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("List doInBackground(Uri... uriArr) {")); - assertThat(code, containsOne("void onPostExecute(List list) {")); - assertThat(code, not(containsString("synthetic"))); + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("List doInBackground(Uri... uriArr) {") + .containsOne("void onPostExecute(List list) {") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/inner/TestSyntheticMthRename.java b/jadx-core/src/test/java/jadx/tests/integration/inner/TestSyntheticMthRename.java index 99e36fb4e..666625ffb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/inner/TestSyntheticMthRename.java +++ b/jadx-core/src/test/java/jadx/tests/integration/inner/TestSyntheticMthRename.java @@ -2,13 +2,9 @@ package jadx.tests.integration.inner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; /** * Issue: https://github.com/skylot/jadx/issues/397 @@ -37,10 +33,9 @@ public class TestSyntheticMthRename extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliFiles("inner", "TestSyntheticMthRename", "TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public String call(Runnable... p) {")); - assertThat(code, not(containsString("synthetic"))); + assertThat(getClassNodeFromSmaliFiles("inner", "TestSyntheticMthRename", "TestCls")) + .code() + .containsOne("public String call(Runnable... p) {") + .doesNotContain("synthetic"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedAccessor.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedAccessor.java index d2ef48a9e..bdb569c64 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedAccessor.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedAccessor.java @@ -4,8 +4,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestCastInOverloadedAccessor extends SmaliTest { static class X { @@ -34,8 +33,9 @@ public class TestCastInOverloadedAccessor extends SmaliTest { @Test public void test() { - String code = getClassNode(X.class).getCode().getCodeStr(); - assertThat(code, containsOne("outerMethod(\"\")")); - assertThat(code, containsOne("outerMethod(\"\", \"\")")); + assertThat(getClassNode(X.class)) + .code() + .containsOne("outerMethod(\"\")") + .containsOne("outerMethod(\"\", \"\")"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke.java index ab693011c..893597406 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke.java @@ -6,12 +6,11 @@ import java.util.List; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestCastInOverloadedInvoke extends IntegrationTest { @@ -50,33 +49,30 @@ public class TestCastInOverloadedInvoke extends IntegrationTest { public void check() { test(); - assertThat(c, is(10 + 100)); + assertThat(c).isEqualTo(10 + 100); c = 0; test2("str"); - assertThat(c, is(1)); + assertThat(c).isEqualTo(1); c = 0; test3(); - assertThat(c, is(111)); + assertThat(c).isEqualTo(111); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("call(new ArrayList<>());")); - assertThat(code, containsOne("call((List) new ArrayList());")); - - assertThat(code, containsOne("call((String) obj);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("call(new ArrayList<>());") + .containsOne("call((List) new ArrayList());") + .containsOne("call((String) obj);"); } @NotYetImplemented @Test public void testNYI() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("call((List) new ArrayList());")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("call((List) new ArrayList());"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke2.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke2.java index 30fa5fc00..b26e7de09 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestCastInOverloadedInvoke2.java @@ -2,21 +2,17 @@ package jadx.tests.integration.invoke; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestCastInOverloadedInvoke2 extends SmaliTest { @Test public void test() { disableCompilation(); - - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("new Intent().putExtra(\"param\", (Parcelable) null);")); + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("new Intent().putExtra(\"param\", (Parcelable) null);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestHierarchyOverloadedInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestHierarchyOverloadedInvoke.java index 3f2d114cb..073c5f38d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestHierarchyOverloadedInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestHierarchyOverloadedInvoke.java @@ -5,12 +5,11 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestHierarchyOverloadedInvoke extends IntegrationTest { @@ -62,30 +61,28 @@ public class TestHierarchyOverloadedInvoke extends IntegrationTest { public void check() { test(); - assertThat(c, is(10 + 100)); + assertThat(c).isEqualTo(10 + 100); c = 0; test2("str"); - assertThat(c, is(1)); + assertThat(c).isEqualTo(1); c = 0; test3(); - assertThat(c, is(111)); + assertThat(c).isEqualTo(111); c = 0; test4(); - assertThat(c, is(12)); + assertThat(c).isEqualTo(12); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("b.call(new ArrayList<>());")); - assertThat(code, containsOne("b.call((List) new ArrayList());")); - - assertThat(code, containsOne("b.call((String) obj);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("b.call(new ArrayList<>());") + .containsOne("b.call((List) new ArrayList());") + .containsOne("b.call((String) obj);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInheritedStaticInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInheritedStaticInvoke.java index 308457db9..26ecdb63b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInheritedStaticInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInheritedStaticInvoke.java @@ -2,11 +2,8 @@ package jadx.tests.integration.invoke; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInheritedStaticInvoke extends IntegrationTest { @@ -28,9 +25,8 @@ public class TestInheritedStaticInvoke extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return B.a();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return B.a();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvoke1.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvoke1.java index 88a0b8555..b52f01f7e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvoke1.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvoke1.java @@ -4,11 +4,8 @@ import java.io.IOException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInvoke1 extends IntegrationTest { @@ -61,9 +58,8 @@ public class TestInvoke1 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("C pkg = new C(id, name, types, keys);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("C pkg = new C(id, name, types, keys);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvokeInCatch.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvokeInCatch.java index 2856eb79e..67cdaea89 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvokeInCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestInvokeInCatch.java @@ -4,13 +4,9 @@ import java.io.IOException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInvokeInCatch extends IntegrationTest { @@ -37,14 +33,13 @@ public class TestInvokeInCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("exc();")); - assertThat(code, not(containsString("return;"))); - assertThat(code, containsOne("} catch (IOException e) {")); - assertThat(code, containsOne("if (b == 1) {")); - assertThat(code, containsOne("log(TAG, \"Error: {}\", e.getMessage());")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {") + .containsOne("exc();") + .doesNotContain("return;") + .containsOne("} catch (IOException e) {") + .containsOne("if (b == 1) {") + .containsOne("log(TAG, \"Error: {}\", e.getMessage());"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestOverloadedMethodInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestOverloadedMethodInvoke.java index fbabf3b55..531a9f4d9 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestOverloadedMethodInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestOverloadedMethodInvoke.java @@ -2,14 +2,10 @@ package jadx.tests.integration.invoke; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestOverloadedMethodInvoke extends IntegrationTest { @@ -41,20 +37,19 @@ public class TestOverloadedMethodInvoke extends IntegrationTest { public void check() { test(null, new Exception()); - assertEquals(23212, c); + assertThat(c).isEqualTo(23212); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public void test(Throwable th, Exception e) {")); - assertThat(code, containsOne("method(e, 10);")); - assertThat(code, containsOne("method(th, 100);")); - assertThat(code, containsOne("method((Throwable) e, 1000);")); - assertThat(code, containsOne("method((Exception) th, 10000);")); - assertThat(code, not(containsString("(Exception) e"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public void test(Throwable th, Exception e) {") + .containsOne("method(e, 10);") + .containsOne("method(th, 100);") + .containsOne("method((Throwable) e, 1000);") + .containsOne("method((Exception) th, 10000);") + .doesNotContain("(Exception) e"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicInvoke.java index 86033c628..b638411ff 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicInvoke.java @@ -12,7 +12,7 @@ import jadx.tests.api.extensions.profiles.TestProfile; import jadx.tests.api.extensions.profiles.TestWithProfiles; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class TestPolymorphicInvoke extends SmaliTest { @@ -27,7 +27,7 @@ public class TestPolymorphicInvoke extends SmaliTest { MethodHandle methodHandle = MethodHandles.lookup().findVirtual(TestCls.class, "func", methodType); return (String) methodHandle.invoke(this, 1, 2); } catch (Throwable e) { - fail(e); + fail("", e); return null; } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicRangeInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicRangeInvoke.java index b25776755..98c040611 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicRangeInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestPolymorphicRangeInvoke.java @@ -10,7 +10,7 @@ import jadx.tests.api.extensions.profiles.TestProfile; import jadx.tests.api.extensions.profiles.TestWithProfiles; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class TestPolymorphicRangeInvoke extends IntegrationTest { @@ -27,7 +27,7 @@ public class TestPolymorphicRangeInvoke extends IntegrationTest { MethodHandle methodHandle = lookup.findVirtual(TestCls.class, "func2", methodType); return (String) methodHandle.invoke(this, 10, 20, 30, 40, 50, 60); } catch (Throwable e) { - fail(e); + fail("", e); return null; } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestRawCustomInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestRawCustomInvoke.java index bbc76c5aa..786183e4b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestRawCustomInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestRawCustomInvoke.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; public class TestRawCustomInvoke extends SmaliTest { @@ -34,7 +34,7 @@ public class TestRawCustomInvoke extends SmaliTest { MethodType.methodType(String.class, Integer.TYPE, Double.TYPE)) .dynamicInvoker().invoke(1, 2.0d); } catch (Throwable e) { - fail(e); + fail("", e); return null; } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvoke.java index 70b464efb..c026434fc 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvoke.java @@ -2,12 +2,10 @@ package jadx.tests.integration.invoke; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestSuperInvoke extends IntegrationTest { @@ -29,15 +27,14 @@ public class TestSuperInvoke extends IntegrationTest { } public void check() { - assertEquals(3, new B().test()); + assertThat(new B().test()).isEqualTo(3); } @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestSuperInvoke.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(2, "return super.a() + 2;")); + assertThat(getClassNode(TestSuperInvoke.class)) + .code() + .countString(2, "return super.a() + 2;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvokeWithGenerics.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvokeWithGenerics.java index dd6f96e58..68e13f02d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvokeWithGenerics.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestSuperInvokeWithGenerics.java @@ -2,11 +2,8 @@ package jadx.tests.integration.invoke; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSuperInvokeWithGenerics extends IntegrationTest { @@ -35,10 +32,9 @@ public class TestSuperInvokeWithGenerics extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("super(e);")); - assertThat(code, containsOne("super(s);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("super(e);") + .containsOne("super(s);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestVarArg.java b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestVarArg.java index 2636fc12e..d6743faf2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/invoke/TestVarArg.java +++ b/jadx-core/src/test/java/jadx/tests/integration/invoke/TestVarArg.java @@ -2,11 +2,8 @@ package jadx.tests.integration.invoke; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestVarArg extends IntegrationTest { @@ -30,17 +27,14 @@ public class TestVarArg extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("void test1(int... a) {")); - assertThat(code, containsString("void test2(int i, Object... a) {")); - - assertThat(code, containsString("test1(1, 2);")); - assertThat(code, containsString("test2(3, \"1\", 7);")); - - // negative case - assertThat(code, containsString("void test3(int[] a) {")); - assertThat(code, containsString("test3(new int[]{5, 8});")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("void test1(int... a) {") + .contains("void test2(int i, Object... a) {") + .contains("test1(1, 2);") + .contains("test2(3, \"1\", 7);") + // negative case + .contains("void test3(int[] a) {") + .contains("test3(new int[]{5, 8});"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach.java index ce3647819..8f0509bf3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach.java @@ -2,11 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArrayForEach extends IntegrationTest { @@ -23,14 +21,13 @@ public class TestArrayForEach extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, - "int sum = 0;", - "for (int n : a) {", - indent() + "sum += n;", - "}", - "return sum;")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(2, + "int sum = 0;", + "for (int n : a) {", + indent() + "sum += n;", + "}", + "return sum;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach2.java index 172446bc7..14f692c8c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEach2.java @@ -2,13 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArrayForEach2 extends IntegrationTest { @@ -25,17 +21,15 @@ public class TestArrayForEach2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("int "))); - - assertThat(code, containsLines(2, - "for (String s : str.split(\"\\n\")) {", - indent(1) + "String t = s.trim();", - indent(1) + "if (t.length() > 0) {", - indent(2) + "System.out.println(t);", - indent(1) + '}', - "}")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("int ") + .containsLines(2, + "for (String s : str.split(\"\\n\")) {", + indent(1) + "String t = s.trim();", + indent(1) + "if (t.length() > 0) {", + indent(2) + "System.out.println(t);", + indent(1) + '}', + "}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEachNegative.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEachNegative.java index a7f5f1ade..ab4917119 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEachNegative.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestArrayForEachNegative.java @@ -2,12 +2,10 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; +import jadx.api.CommentsLevel; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestArrayForEachNegative extends IntegrationTest { @@ -47,13 +45,11 @@ public class TestArrayForEachNegative extends IntegrationTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - // Remove all comments - as the comment created by CodeGenUtils.addInputFileInfo - // always contains a colon - code = code.replaceAll("/\\*.*?\\*/", ""); - - assertThat(code, not(containsString(":"))); + // Remove all comments - as the comment created by CodeGenUtils.addInputFileInfo always contains a + // colon + getArgs().setCommentsLevel(CommentsLevel.NONE); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain(":"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf.java index 23c8cab19..c188f86da 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf.java @@ -5,12 +5,10 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestBreakInComplexIf extends IntegrationTest { @@ -42,30 +40,29 @@ public class TestBreakInComplexIf extends IntegrationTest { Map first = new HashMap<>(); first.put("3", new Point(100, 100)); first.put("4", new Point(60, 100)); - assertThat(test(first, 2), is(3)); + assertThat(test(first, 2)).isEqualTo(3); Map second = new HashMap<>(); second.put("3", new Point(100, 100)); second.put("4", new Point(60, 0)); // check break second.put("5", new Point(60, 100)); - assertThat(test(second, 2), is(2)); + assertThat(test(second, 2)).isEqualTo(2); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (tile == null || tile.y != 100) {")); - assertThat(code, containsOne("break;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (tile == null || tile.y != 100) {") + .containsOne("break;"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - assertThat(code, containsOne("break;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("break;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf2.java index dc6d3fe8c..6b20cfacb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInComplexIf2.java @@ -5,12 +5,9 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestBreakInComplexIf2 extends IntegrationTest { @@ -34,26 +31,24 @@ public class TestBreakInComplexIf2 extends IntegrationTest { } public void check() { - assertThat(test(Arrays.asList("x", "y", "skip", "z", "a")), is(3)); - assertThat(test(Arrays.asList("x", "skip", "")), is(1)); - assertThat(test(Arrays.asList("skip", "y", "12345")), is(1)); + assertThat(test(Arrays.asList("x", "y", "skip", "z", "a"))).isEqualTo(3); + assertThat(test(Arrays.asList("x", "skip", ""))).isEqualTo(1); + assertThat(test(Arrays.asList("skip", "y", "12345"))).isEqualTo(1); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(2, "break;")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(2, "break;"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(2, "break;")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(2, "break;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop.java index d15ce5153..114295c41 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop.java @@ -2,12 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestBreakInLoop extends IntegrationTest { @@ -27,15 +23,13 @@ public class TestBreakInLoop extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (int i = 0; i < a.length; i++) {")); - // assertThat(code, containsOne("a[i]++;")); - assertThat(code, containsOne("if (i < b) {")); - assertThat(code, containsOne("break;")); - assertThat(code, containsOne("this.f++;")); - - assertThat(code, countString(0, "else")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (int i = 0; i < a.length; i++) {") + .containsOne("if (i < b) {") + .containsOne("break;") + .containsOne("this.f++;") + // .containsOne("a[i]++;") + .countString(0, "else"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop2.java index bafe022cb..1e1c708d2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop2.java @@ -4,12 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestBreakInLoop2 extends IntegrationTest { @@ -41,13 +37,12 @@ public class TestBreakInLoop2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while (true) {")); - assertThat(code, anyOf(containsOne("break;"), containsOne("return;"))); - assertThat(code, containsOne("throw ex;")); - assertThat(code, containsOne("data.clear();")); - assertThat(code, containsOne("Thread.sleep(100L);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while (true) {") + .containsOneOf("break;", "return;") + .containsOne("throw ex;") + .containsOne("data.clear();") + .containsOne("Thread.sleep(100L);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop3.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop3.java index 01d8b6b37..9a9f8a149 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakInLoop3.java @@ -6,7 +6,7 @@ import java.io.FileOutputStream; import jadx.NotYetImplemented; import jadx.tests.api.IntegrationTest; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestBreakInLoop3 extends IntegrationTest { @@ -47,7 +47,7 @@ public class TestBreakInLoop3 extends IntegrationTest { public void check() { writeMore(""); - assertEquals("12135678", builder.toString()); + assertThat(builder).hasToString("12135678"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakWithLabel.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakWithLabel.java index dc46f0f59..58fa4254c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakWithLabel.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestBreakWithLabel.java @@ -2,13 +2,10 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestBreakWithLabel extends IntegrationTest { @@ -30,17 +27,16 @@ public class TestBreakWithLabel extends IntegrationTest { public void check() { int[][] testArray = { { 1, 2 }, { 3, 4 } }; - assertTrue(test(testArray, 3)); - assertFalse(test(testArray, 5)); + assertThat(test(testArray, 3)).isTrue(); + assertThat(test(testArray, 5)).isFalse(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("loop0:")); - assertThat(code, containsOne("break loop0;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("loop0:") + .containsOne("break loop0;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestComplexWhileLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestComplexWhileLoop.java index 6f5613bb6..73083d112 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestComplexWhileLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestComplexWhileLoop.java @@ -2,12 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestComplexWhileLoop extends IntegrationTest { @@ -31,9 +28,8 @@ public class TestComplexWhileLoop extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for (int at = 0; at < len; at = endAt) {"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (int at = 0; at < len; at = endAt) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestContinueInLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestContinueInLoop.java index 6bfcec8f1..36281e307 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestContinueInLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestContinueInLoop.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestContinueInLoop extends IntegrationTest { @@ -33,13 +30,12 @@ public class TestContinueInLoop extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (int i = 0; i < a.length; i++) {")); - assertThat(code, containsOne("if (i < b) {")); - assertThat(code, containsOne("continue;")); - assertThat(code, containsOne("break;")); - assertThat(code, containsOne("this.f++;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (int i = 0; i < a.length; i++) {") + .containsOne("if (i < b) {") + .containsOne("continue;") + .containsOne("break;") + .containsOne("this.f++;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestDoWhileBreak.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestDoWhileBreak.java index abc33c361..f481548d8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestDoWhileBreak.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestDoWhileBreak.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestDoWhileBreak extends IntegrationTest { @@ -28,9 +25,8 @@ public class TestDoWhileBreak extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while (")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while ("); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestEndlessLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestEndlessLoop.java index 68b62d92e..fc8283acf 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestEndlessLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestEndlessLoop.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestEndlessLoop extends IntegrationTest { @@ -33,9 +30,8 @@ public class TestEndlessLoop extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("while (this == this)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("while (this == this)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop2.java index 62cf976ac..e002d14fa 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop2.java @@ -2,12 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIfInLoop2 extends IntegrationTest { @@ -34,9 +31,8 @@ public class TestIfInLoop2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for (int at = 0; at < len; at = endAt) {"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (int at = 0; at < len; at = endAt) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop3.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop3.java index 63e2af1ea..74df3fb75 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIfInLoop3.java @@ -2,12 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIfInLoop3 extends IntegrationTest { @@ -42,16 +39,15 @@ public class TestIfInLoop3 extends IntegrationTest { } public void check() { - assertTrue(test(14, 2)); + assertThat(test(14, 2)).isTrue(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (int i = 0; i < extraArray.length; i += 2) {")); - assertThat(code, containsOne("if (extraArray != null && placingStone) {")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (int i = 0; i < extraArray.length; i += 2) {") + .containsOne("if (extraArray != null && placingStone) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexForLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexForLoop.java index 72b1ecf73..f3b1ce713 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexForLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexForLoop.java @@ -2,12 +2,10 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestIndexForLoop extends IntegrationTest { @@ -23,22 +21,21 @@ public class TestIndexForLoop extends IntegrationTest { public void check() { int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - assertEquals(0, test(array, 0)); - assertEquals(6, test(array, 3)); - assertEquals(36, test(array, 8)); + assertThat(test(array, 0)).isEqualTo(0); + assertThat(test(array, 3)).isEqualTo(6); + assertThat(test(array, 8)).isEqualTo(36); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, - "int sum = 0;", - "for (int i = 0; i < b; i++) {", - indent(1) + "sum += a[i];", - "}", - "return sum;")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(2, + "int sum = 0;", + "for (int i = 0; i < b; i++) {", + indent(1) + "sum += a[i];", + "}", + "return sum;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexedLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexedLoop.java index e936be8c8..5fc004edd 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexedLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIndexedLoop.java @@ -4,15 +4,10 @@ import java.io.File; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIndexedLoop extends IntegrationTest { @@ -42,30 +37,28 @@ public class TestIndexedLoop extends IntegrationTest { } public void check() { - assertThat(test(null), nullValue()); - assertThat(test(new File[] {}), nullValue()); + assertThat(test(null)).isNull(); + assertThat(test(new File[] {})).isNull(); File file = new File("f"); - assertThat(test(new File[] { new File("a"), file }), is(file)); + assertThat(test(new File[] { new File("a"), file })).isEqualTo(file); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for (File file :"))); - assertThat(code, containsOne("for (int i = 0; i < length; i++) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (File file :") + .containsOne("for (int i = 0; i < length; i++) {"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for (File file :"))); - assertThat(code, containsOne("for (int i = 0; i < length; i++) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (File file :") + .containsOne("for (int i = 0; i < length; i++) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach.java index 879aa4e9d..a4da67cf1 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach.java @@ -2,11 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIterableForEach extends IntegrationTest { @@ -22,14 +20,13 @@ public class TestIterableForEach extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, - "StringBuilder sb = new StringBuilder();", - "for (String s : a) {", - indent(1) + "sb.append(s);", - "}", - "return sb.toString();")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(2, + "StringBuilder sb = new StringBuilder();", + "for (String s : a) {", + indent(1) + "sb.append(s);", + "}", + "return sb.toString();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach2.java index 0b973b85d..e98692622 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach2.java @@ -5,11 +5,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestIterableForEach2 extends IntegrationTest { @@ -42,11 +39,10 @@ public class TestIterableForEach2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (Authorization auth : service.getAuthorizations()) {")); - assertThat(code, containsOne("if (isValid(auth)) {")); - assertThat(code, containsOne("return auth.getToken();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (Authorization auth : service.getAuthorizations()) {") + .containsOne("if (isValid(auth)) {") + .containsOne("return auth.getToken();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach3.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach3.java index f609f6111..f22b8affa 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestIterableForEach3.java @@ -4,11 +4,8 @@ import java.util.Set; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestIterableForEach3 extends IntegrationTest { @@ -33,11 +30,10 @@ public class TestIterableForEach3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (T s : set) {")); - assertThat(code, containsOne("if (str.length() == 0) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (T s : set) {") + .containsOne("if (str.length() == 0) {"); // TODO move return outside 'if' } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition.java index 1c21cfaeb..9d53cf4b7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition.java @@ -4,11 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopCondition extends IntegrationTest { @@ -26,10 +23,9 @@ public class TestLoopCondition extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("list.set(i, \"ABC\")")); - assertThat(code, containsOne("list.set(i, \"DEF\")")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("list.set(i, \"ABC\")") + .containsOne("list.set(i, \"DEF\")"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition2.java index 01cab1e8e..495b711b7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition2.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopCondition2 extends IntegrationTest { @@ -23,12 +20,11 @@ public class TestLoopCondition2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("int i = 0;")); - assertThat(code, containsOne("while (a && i < 10) {")); - assertThat(code, containsOne("i++;")); - assertThat(code, containsOne("return i;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("int i = 0;") + .containsOne("while (a && i < 10) {") + .containsOne("i++;") + .containsOne("return i;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition3.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition3.java index 0efaf1fa0..8662c5dd6 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition3.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopCondition3 extends IntegrationTest { @@ -31,11 +28,10 @@ public class TestLoopCondition3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while (a < 12) {")); - assertThat(code, containsOne("if (b + a < 9 && b < 8) {")); - assertThat(code, containsOne("if (b >= 2 && a > -1 && b < 6) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while (a < 12) {") + .containsOne("if (b + a < 9 && b < 8) {") + .containsOne("if (b >= 2 && a > -1 && b < 6) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition4.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition4.java index 0eadd2295..09f700f50 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition4.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopCondition4 extends IntegrationTest { @@ -25,14 +22,13 @@ public class TestLoopCondition4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("int n = -1;")); - assertThat(code, containsOne("while (n < 0) {")); - assertThat(code, containsOne("n += 12;")); - assertThat(code, containsOne("while (n > 11) {")); - assertThat(code, containsOne("n -= 12;")); - assertThat(code, containsOne("System.out.println(n);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("int n = -1;") + .containsOne("while (n < 0) {") + .containsOne("n += 12;") + .containsOne("while (n > 11) {") + .containsOne("n -= 12;") + .containsOne("System.out.println(n);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition5.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition5.java index b63661a0f..851d4282e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopCondition5.java @@ -2,13 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestLoopCondition5 extends SmaliTest { @@ -25,24 +21,19 @@ public class TestLoopCondition5 extends SmaliTest { @Test public void test0() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (")); - assertThat(code, containsOne("return -1;")); - assertThat(code, countString(2, "return ")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (") + .containsOne("return -1;") + .countString(2, "return "); } @Test public void test1() { - ClassNode cls = getClassNodeFromSmaliWithPath("loops", "TestLoopCondition5"); - String code = cls.getCode().toString(); - - assertThat(code, anyOf( - containsOne("for ("), - containsOne("while (true) {"), - containsOne("} while (iArr[i3] != i);"))); - assertThat(code, containsOne("return -1;")); - assertThat(code, countString(2, "return ")); + assertThat(getClassNodeFromSmaliWithPath("loops", "TestLoopCondition5")) + .code() + .containsOneOf("for (", "while (true) {", "} while (iArr[i3] != i);") + .containsOne("return -1;") + .countString(2, "return "); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopConditionInvoke.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopConditionInvoke.java index b73b64969..1f49c1776 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopConditionInvoke.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopConditionInvoke.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopConditionInvoke extends IntegrationTest { @@ -33,14 +30,13 @@ public class TestLoopConditionInvoke extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("do {")); - assertThat(code, containsOne("if (ch == 0) {")); - assertThat(code, containsOne("this.pos = startPos;")); - assertThat(code, containsOne("return false;")); - assertThat(code, containsOne("} while (ch != lastChar);")); - assertThat(code, containsOne("return true;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("do {") + .containsOne("if (ch == 0) {") + .containsOne("this.pos = startPos;") + .containsOne("return false;") + .containsOne("} while (ch != lastChar);") + .containsOne("return true;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection.java index 1d7fc5461..7becb4082 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection.java @@ -2,13 +2,10 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestLoopDetection extends IntegrationTest { @@ -29,20 +26,18 @@ public class TestLoopDetection extends IntegrationTest { public void check() { int[] a = { 1, 1, 1, 1, 1 }; test(a, 3); - assertThat(a, is(new int[] { 2, 2, 2, 0, 0 })); + assertThat(a).containsExactly(new int[] { 2, 2, 2, 0, 0 }); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("while (i < a.length && i < b) {")); - assertThat(code, containsString("while (i < a.length) {")); - - assertThat(code, containsString("int i = 0;")); - assertThat(code, not(containsString("i_2"))); - assertThat(code, containsString("i++;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("while (i < a.length && i < b) {") + .contains("while (i < a.length) {") + .contains("int i = 0;") + .doesNotContain("i_2") + .contains("i++;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection2.java index 7048eef8b..1511dfd5f 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection2.java @@ -2,13 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopDetection2 extends IntegrationTest { @@ -30,11 +25,10 @@ public class TestLoopDetection2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("int c = a + b;")); - assertThat(code, containsOne("for (int i = a; i < b; i++) {")); - assertThat(code, not(containsString("c_2"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("int c = a + b;") + .containsOne("for (int i = a; i < b; i++) {") + .doesNotContain("c_2"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection3.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection3.java index 8c63b1694..cca0a3d59 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection3.java @@ -3,11 +3,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopDetection3 extends IntegrationTest { @@ -34,18 +31,16 @@ public class TestLoopDetection3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("while")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("while"); } @Test @NotYetImplemented public void test2() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("while (--pos >= 0) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("while (--pos >= 0) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection4.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection4.java index cc1f1817c..137af6336 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection4.java @@ -4,11 +4,8 @@ import java.util.Iterator; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopDetection4 extends IntegrationTest { @@ -36,12 +33,11 @@ public class TestLoopDetection4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("while (this.iterator.hasNext()) {")); - assertThat(code, containsOne("if (filtered != null) {")); - assertThat(code, containsOne("return filtered;")); - assertThat(code, containsOne("return null;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("while (this.iterator.hasNext()) {") + .containsOne("if (filtered != null) {") + .containsOne("return filtered;") + .containsOne("return null;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection5.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection5.java index 4329d9af7..2aebd652c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestLoopDetection5.java @@ -6,14 +6,10 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestLoopDetection5 extends IntegrationTest { @@ -36,17 +32,16 @@ public class TestLoopDetection5 extends IntegrationTest { } public void check() { - assertThat(test("OTHERSTR"), is("otherStr")); + assertThat(test("OTHERSTR")).isEqualTo("otherStr"); } } @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for ("))); - assertThat(code, containsOne("it.next();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (") + .containsOne("it.next();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops.java index a194dbbea..809ca1116 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops.java @@ -4,11 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestNestedLoops extends IntegrationTest { @@ -34,13 +31,12 @@ public class TestNestedLoops extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (String s1 : l1) {")); - assertThat(code, containsOne("for (String s2 : l2) {")); - assertThat(code, containsOne("if (s1.equals(s2)) {")); - assertThat(code, containsOne("l2.add(s1);")); - assertThat(code, containsOne("l1.remove(s2);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (String s1 : l1) {") + .containsOne("for (String s2 : l2) {") + .containsOne("if (s1.equals(s2)) {") + .containsOne("l2.add(s1);") + .containsOne("l1.remove(s2);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops2.java index c8236a0fa..843059408 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops2.java @@ -4,11 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestNestedLoops2 extends IntegrationTest { @@ -28,10 +25,9 @@ public class TestNestedLoops2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (int i = 0; i < list.size(); i++) {")); - assertThat(code, containsOne("while (j < s.length()) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (int i = 0; i < list.size(); i++) {") + .containsOne("while (j < s.length()) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops3.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops3.java index 5fa931711..89959fab9 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops3.java @@ -2,12 +2,10 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestNestedLoops3 extends IntegrationTest { @@ -55,15 +53,14 @@ public class TestNestedLoops3 extends IntegrationTest { public void check() { test(1); - assertEquals(302, c); + assertThat(c).isEqualTo(302); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("} catch (Exception e) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} catch (Exception e) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops5.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops5.java index 18162671b..94bde5728 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNestedLoops5.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestNestedLoops5 extends IntegrationTest { @@ -27,7 +27,7 @@ public class TestNestedLoops5 extends IntegrationTest { } public void check() { - assertEquals(7, testFor()); + assertThat(testFor()).isEqualTo(7); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNotIndexedLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNotIndexedLoop.java index dfa48c674..b24a0c2f8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestNotIndexedLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestNotIndexedLoop.java @@ -4,15 +4,10 @@ import java.io.File; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestNotIndexedLoop extends IntegrationTest { @@ -48,30 +43,28 @@ public class TestNotIndexedLoop extends IntegrationTest { } public void check() { - assertThat(test(null), nullValue()); - assertThat(test(new File[] {}), nullValue()); + assertThat(test(null)).isNull(); + assertThat(test(new File[] {})).isNull(); File file = new File("f"); - assertThat(test(new File[] { new File("a"), file }), is(file)); + assertThat(test(new File[] { new File("a"), file })).isEqualTo(file); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for ("))); - assertThat(code, containsOne("while (true) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (") + .containsOne("while (true) {"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("for ("))); - assertThat(code, containsOne("while (true) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("for (") + .containsOne("while (true) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestSequentialLoops2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestSequentialLoops2.java index 49b5283df..94a5c135a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestSequentialLoops2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestSequentialLoops2.java @@ -2,13 +2,9 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSequentialLoops2 extends IntegrationTest { @@ -41,23 +37,21 @@ public class TestSequentialLoops2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(2, "while (")); - assertThat(code, containsString("break;")); - assertThat(code, containsOne("return c")); - assertThat(code, countString(2, "<= 127")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(2, "while (") + .contains("break;") + .containsOne("return c") + .countString(2, "<= 127"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(2, "while (")); - assertThat(code, containsString("break;")); - assertThat(code, countString(2, "<= 127")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(2, "while (") + .contains("break;") + .countString(2, "<= 127"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestSynchronizedInEndlessLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestSynchronizedInEndlessLoop.java index 631d8d71f..67f80f1a2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestSynchronizedInEndlessLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestSynchronizedInEndlessLoop.java @@ -2,11 +2,8 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSynchronizedInEndlessLoop extends IntegrationTest { @@ -36,13 +33,12 @@ public class TestSynchronizedInEndlessLoop extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("synchronized (this) {")); - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("f++;")); - assertThat(code, containsOne("Thread.sleep(100L);")); - assertThat(code, containsOne("} catch (Exception e) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("synchronized (this) {") + .containsOne("try {") + .containsOne("f++;") + .containsOne("Thread.sleep(100L);") + .containsOne("} catch (Exception e) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop.java index 7d318e347..dae761bf8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop.java @@ -2,12 +2,10 @@ package jadx.tests.integration.loops; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestTryCatchInLoop extends IntegrationTest { @@ -38,16 +36,15 @@ public class TestTryCatchInLoop extends IntegrationTest { public void check() { test(); - assertEquals(3, c); + assertThat(c).isEqualTo(3); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("} catch (Exception e) {")); - assertThat(code, containsOne("break;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} catch (Exception e) {") + .containsOne("break;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop2.java b/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop2.java index 8533c5bc8..c32bd8f3d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/loops/TestTryCatchInLoop2.java @@ -5,11 +5,8 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatchInLoop2 extends IntegrationTest { @@ -37,10 +34,9 @@ public class TestTryCatchInLoop2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("synchronized (this.mCache) {")); - assertThat(code, containsOne("for (int i = 0; i < items.length; i++) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("synchronized (this.mCache) {") + .containsOne("for (int i = 0; i < items.length; i++) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestCaseSensitiveChecks.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestCaseSensitiveChecks.java index 5b05e3c48..815a4f160 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestCaseSensitiveChecks.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestCaseSensitiveChecks.java @@ -3,17 +3,13 @@ package jadx.tests.integration.names; import java.util.List; import java.util.stream.Collectors; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import jadx.core.Consts; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.emptyString; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestCaseSensitiveChecks extends SmaliTest { /* @@ -27,10 +23,10 @@ public class TestCaseSensitiveChecks extends SmaliTest { List classes = loadFromSmaliFiles(); for (ClassNode cls : classes) { - assertThat(cls.getPackage(), is(Consts.DEFAULT_PACKAGE_NAME)); + assertThat(cls.getPackage()).isEqualTo(Consts.DEFAULT_PACKAGE_NAME); } long namesCount = classes.stream().map(cls -> cls.getAlias().toLowerCase()).distinct().count(); - assertThat(namesCount, is(2L)); + assertThat(namesCount).isEqualTo(2L); } @Test @@ -39,10 +35,10 @@ public class TestCaseSensitiveChecks extends SmaliTest { List classes = loadFromSmaliFiles(); for (ClassNode cls : classes) { - assertThat(cls.getPackage(), is(Consts.DEFAULT_PACKAGE_NAME)); + assertThat(cls.getPackage()).isEqualTo(Consts.DEFAULT_PACKAGE_NAME); } List names = classes.stream().map(ClassNode::getAlias).collect(Collectors.toList()); - assertThat(names, Matchers.containsInAnyOrder("A", "a")); + assertThat(names).containsExactlyInAnyOrder("A", "a"); } @Test @@ -51,10 +47,10 @@ public class TestCaseSensitiveChecks extends SmaliTest { List classes = loadFromSmaliFiles(); for (ClassNode cls : classes) { - assertThat(cls.getPackage(), not(emptyString())); - assertThat(cls.getPackage(), not(Consts.DEFAULT_PACKAGE_NAME)); + assertThat(cls.getPackage()).isNotEmpty(); + assertThat(cls.getPackage()).isNotEqualTo(Consts.DEFAULT_PACKAGE_NAME); } long namesCount = classes.stream().map(cls -> cls.getAlias().toLowerCase()).distinct().count(); - assertThat(namesCount, is(2L)); + assertThat(namesCount).isEqualTo(2L); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestDuplicatedNames.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestDuplicatedNames.java index 34321c145..7aa5a7b92 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestDuplicatedNames.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestDuplicatedNames.java @@ -2,11 +2,9 @@ package jadx.tests.integration.names; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestDuplicatedNames extends SmaliTest { @@ -40,16 +38,13 @@ public class TestDuplicatedNames extends SmaliTest { } private void commonChecks() { - ClassNode cls = getClassNodeFromSmaliWithPath("names", "TestDuplicatedNames"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("Object fieldName;")); - assertThat(code, containsOne("String f0fieldName")); - - assertThat(code, containsOne("this.fieldName")); - assertThat(code, containsOne("this.f0fieldName")); - - assertThat(code, containsOne("public Object run() {")); - assertThat(code, containsOne("public String m0run() {")); + assertThat(getClassNodeFromSmaliWithPath("names", "TestDuplicatedNames")) + .code() + .containsOne("Object fieldName;") + .containsOne("String f0fieldName") + .containsOne("this.fieldName") + .containsOne("this.f0fieldName") + .containsOne("public Object run() {") + .containsOne("public String m0run() {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestFieldCollideWithPackage.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestFieldCollideWithPackage.java index 7b8dc7168..adff31aa7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestFieldCollideWithPackage.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestFieldCollideWithPackage.java @@ -7,9 +7,7 @@ import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestFieldCollideWithPackage extends SmaliTest { //@formatter:off @@ -43,9 +41,10 @@ public class TestFieldCollideWithPackage extends SmaliTest { ClassNode firstA = searchCls(clsList, "first.A"); String code = firstA.getCode().toString(); - assertThat(code, containsString("second.A")); + assertThat(code) + .contains("second.A") + .doesNotContain("public second.A second;"); // expect field to be renamed - assertThat(code, not(containsString("public second.A second;"))); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestLocalVarCollideWithPackage.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestLocalVarCollideWithPackage.java index 8528e62d6..2a7e659d4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestLocalVarCollideWithPackage.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestLocalVarCollideWithPackage.java @@ -7,9 +7,7 @@ import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestLocalVarCollideWithPackage extends SmaliTest { //@formatter:off @@ -47,8 +45,9 @@ public class TestLocalVarCollideWithPackage extends SmaliTest { ClassNode firstA = searchCls(clsList, "first.A"); String code = firstA.getCode().toString(); - assertThat(code, containsString("second.A.call();")); - assertThat(code, not(containsString("Second second = new Second();"))); + assertThat(code) + .contains("second.A.call();") + .doesNotContain("Second second = new Second();"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestNameAssign2.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestNameAssign2.java index 2074b4b50..01b6b8660 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestNameAssign2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestNameAssign2.java @@ -8,14 +8,11 @@ import java.util.List; import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.BlockNode; -import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.visitors.ssa.LiveVarAnalysis; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestNameAssign2 extends IntegrationTest { @@ -56,9 +53,8 @@ public class TestNameAssign2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("int id;"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("int id;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedClassNames.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedClassNames.java index f98ce3bad..9eed089da 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedClassNames.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedClassNames.java @@ -4,12 +4,9 @@ import java.io.File; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestReservedClassNames extends SmaliTest { /* @@ -19,9 +16,8 @@ public class TestReservedClassNames extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali("names" + File.separatorChar + "TestReservedClassNames", "do"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("public class do"))); + assertThat(getClassNodeFromSmali("names" + File.separatorChar + "TestReservedClassNames", "do")) + .code() + .doesNotContain("public class do"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedNames.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedNames.java index ac8362d46..e1d7e2683 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedNames.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedNames.java @@ -2,12 +2,9 @@ package jadx.tests.integration.names; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestReservedNames extends SmaliTest { @@ -27,9 +24,8 @@ public class TestReservedNames extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPath("names", "TestReservedNames"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("public String do;"))); + assertThat(getClassNodeFromSmali()) + .code() + .doesNotContain("public String do;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedPackageNames.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedPackageNames.java index 7659ff949..02dc245c2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedPackageNames.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestReservedPackageNames.java @@ -8,9 +8,7 @@ import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestReservedPackageNames extends SmaliTest { @@ -26,8 +24,7 @@ public class TestReservedPackageNames extends SmaliTest { public void test() { List clsList = loadFromSmaliFiles(); for (ClassNode cls : clsList) { - String code = cls.getCode().toString(); - assertThat(code, not(containsString("package do.if;"))); + assertThat(cls).code().doesNotContain("package do.if;"); } } @@ -36,8 +33,7 @@ public class TestReservedPackageNames extends SmaliTest { enableDeobfuscation(); List clsList = loadFromSmaliFiles(); for (ClassNode cls : clsList) { - String code = cls.getCode().toString(); - assertThat(code, not(containsString("package do.if;"))); + assertThat(cls).code().doesNotContain("package do.if;"); } } @@ -46,9 +42,8 @@ public class TestReservedPackageNames extends SmaliTest { disableCompilation(); args.setRenameFlags(Collections.emptySet()); for (ClassNode cls : loadFromSmaliFiles()) { - String code = cls.getCode().toString(); if (cls.getAlias().equals("A")) { - assertThat(code, containsString("package do.if;")); + assertThat(cls).code().contains("package do.if;"); } } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/names/TestSameMethodsNames.java b/jadx-core/src/test/java/jadx/tests/integration/names/TestSameMethodsNames.java index 43d207004..6152ea75d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/names/TestSameMethodsNames.java +++ b/jadx-core/src/test/java/jadx/tests/integration/names/TestSameMethodsNames.java @@ -2,11 +2,8 @@ package jadx.tests.integration.names; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSameMethodsNames extends IntegrationTest { @@ -30,9 +27,8 @@ public class TestSameMethodsNames extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("new Bug().Bug();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("new Bug().Bug();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestAllNops.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestAllNops.java index e7f10e165..b5f1fd3a9 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestAllNops.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestAllNops.java @@ -2,21 +2,18 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestAllNops extends SmaliTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(1, "private boolean test() {", "}")); - assertThat(code, containsLines(1, "private boolean testWithTryCatch() {", "}")); + assertThat(getClassNodeFromSmali()) + .code() + .containsLines(1, "private boolean test() {", "}") + .containsLines(1, "private boolean testWithTryCatch() {", "}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestArgInline.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestArgInline.java index 29a205131..35fb0976d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestArgInline.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestArgInline.java @@ -2,12 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArgInline extends IntegrationTest { @@ -24,10 +20,9 @@ public class TestArgInline extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("i++;")); - assertThat(code, not(containsString("i = i + 1;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("i++;") + .doesNotContain("i = i + 1;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestBadMethodAccessModifiers.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestBadMethodAccessModifiers.java index a61292c54..c5a14303d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestBadMethodAccessModifiers.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestBadMethodAccessModifiers.java @@ -2,13 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestBadMethodAccessModifiers extends SmaliTest { // @formatter:off @@ -29,10 +25,9 @@ public class TestBadMethodAccessModifiers extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliFiles("others", "TestBadMethodAccessModifiers", "TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("protected void test() {"))); - assertThat(code, containsOne("public void test() {")); + assertThat(getClassNodeFromSmaliFiles("others", "TestBadMethodAccessModifiers", "TestCls")) + .code() + .doesNotContain("protected void test() {") + .containsOne("public void test() {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestClassGen.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestClassGen.java index 954cd3c87..2881a20d0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestClassGen.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestClassGen.java @@ -2,12 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestClassGen extends IntegrationTest { @@ -25,15 +21,13 @@ public class TestClassGen extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("public interface I {")); - assertThat(code, containsString(indent(2) + "int test();")); - assertThat(code, not(containsString("public int test();"))); - assertThat(code, containsString(indent(2) + "int test3();")); - - assertThat(code, containsString("public static abstract class A {")); - assertThat(code, containsString(indent(2) + "public abstract int test2();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("public interface I {") + .contains(indent(2) + "int test();") + .doesNotContain("public int test();") + .contains(indent(2) + "int test3();") + .contains("public static abstract class A {") + .contains(indent(2) + "public abstract int test2();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched2.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched2.java index 462d0dcd7..6de892dae 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched2.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestConstructorBranched2 extends SmaliTest { diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched3.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched3.java index 7ebd1731d..a88cb6b72 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestConstructorBranched3.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestConstructorBranched3 extends SmaliTest { diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeadBlockReferencesStart.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeadBlockReferencesStart.java index 891dbd3e9..add9ff4ef 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeadBlockReferencesStart.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeadBlockReferencesStart.java @@ -4,13 +4,13 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestDeadBlockReferencesStart extends SmaliTest { @Test public void test() { - String code = getClassNodeFromSmali().getCode().getCodeStr(); - assertThat(code, countString(0, "throw")); + assertThat(getClassNodeFromSmali()) + .code() + .countString(0, "throw"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing.java index 0423441f0..8099d52b6 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing.java @@ -2,13 +2,10 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestDeboxing extends IntegrationTest { @@ -50,12 +47,12 @@ public class TestDeboxing extends IntegrationTest { // don't mind weird comparisons // need to get primitive without using boxing or literal // otherwise will get same result after decompilation - assertThat(testInt(), is(Integer.sum(0, 1))); - assertThat(testBoolean(), is(Boolean.TRUE)); - assertThat(testByte(), is(Byte.parseByte("2"))); - assertThat(testShort(), is(Short.parseShort("3"))); - assertThat(testChar(), is("c".charAt(0))); - assertThat(testLong(), is(Long.valueOf("4"))); + assertThat(testInt()).isEqualTo(Integer.sum(0, 1)); + assertThat(testBoolean()).isEqualTo(Boolean.TRUE); + assertThat(testByte()).isEqualTo(Byte.parseByte("2")); + assertThat(testShort()).isEqualTo(Short.parseShort("3")); + assertThat(testChar()).isEqualTo("c".charAt(0)); + assertThat(testLong()).isEqualTo(Long.valueOf("4")); testConstInline(); } } @@ -63,15 +60,14 @@ public class TestDeboxing extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return 1;")); - assertThat(code, containsOne("return true;")); - assertThat(code, containsOne("return (byte) 2;")); - assertThat(code, containsOne("return (short) 3;")); - assertThat(code, containsOne("return 'c';")); - assertThat(code, containsOne("return 4L;")); - assertThat(code, countString(2, "use(true);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return 1;") + .containsOne("return true;") + .containsOne("return (byte) 2;") + .containsOne("return (short) 3;") + .containsOne("return 'c';") + .containsOne("return 4L;") + .countString(2, "use(true);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java index 91066c011..62117ead7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java @@ -2,13 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestDeboxing2 extends IntegrationTest { @@ -21,28 +17,25 @@ public class TestDeboxing2 extends IntegrationTest { } public void check() { - assertThat(test(null), is(0L)); - assertThat(test(0L), is(0L)); - assertThat(test(7L), is(7L)); + assertThat(test(null)).isEqualTo(0L); + assertThat(test(0L)).isEqualTo(0L); + assertThat(test(7L)).isEqualTo(7L); } } @Test public void test() { noDebugInfo(); - - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("long test(Long l)")); - assertThat(code, containsOne("if (l == null) {")); - assertThat(code, containsOne("l = 0L;")); - - // checks for 'check' method - assertThat(code, containsOne("test(null)")); - assertThat(code, containsOne("test(0L)")); - assertThat(code, countString(2, "is(0L)")); - assertThat(code, containsOne("test(7L)")); - assertThat(code, containsOne("is(7L)")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("long test(Long l)") + .containsOne("if (l == null) {") + .containsOne("l = 0L;") + .containsOne("test(null)") + .containsOne("test(0L)") + // checks for 'check' method + .countString(2, "isEqualTo(0L)") + .containsOne("test(7L)") + .containsOne("isEqualTo(7L)"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java index dd7a57b56..f45b44704 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java @@ -6,11 +6,8 @@ import java.util.Map; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestDeboxing3 extends IntegrationTest { @@ -39,10 +36,9 @@ public class TestDeboxing3 extends IntegrationTest { public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("l = 900000L;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("l = 900000L;"); } @Test @@ -50,10 +46,9 @@ public class TestDeboxing3 extends IntegrationTest { public void testFull() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("Pair pair = this.cache.get(id);")); - assertThat(code, containsOne("return pair.first + l > System.currentTimeMillis();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("Pair pair = this.cache.get(id);") + .containsOne("return pair.first + l > System.currentTimeMillis();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java index 07ed3efaf..117bd12c9 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java @@ -1,16 +1,12 @@ package jadx.tests.integration.others; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestDeboxing4 extends IntegrationTest { @@ -21,9 +17,9 @@ public class TestDeboxing4 extends IntegrationTest { } public void check() { - assertThat(test(null), Matchers.is(false)); - assertThat(test(0), Matchers.is(false)); - assertThat(test(1), Matchers.is(true)); + assertThat(test(null)).isFalse(); + assertThat(test(0)).isFalse(); + assertThat(test(1)).isTrue(); } } @@ -31,10 +27,9 @@ public class TestDeboxing4 extends IntegrationTest { public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("return 1.equals(num);"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("return 1.equals(num);"); } @Test @@ -42,9 +37,8 @@ public class TestDeboxing4 extends IntegrationTest { public void testInline() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return ((Integer) 1).equals(i);")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return ((Integer) 1).equals(i);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDefConstructorNotRemoved.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDefConstructorNotRemoved.java index 4871b55a9..c59175743 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDefConstructorNotRemoved.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDefConstructorNotRemoved.java @@ -2,13 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestDefConstructorNotRemoved extends IntegrationTest { @@ -50,11 +46,10 @@ public class TestDefConstructorNotRemoved extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("super();"))); - assertThat(code, not(containsString("static {"))); - assertThat(code, containsOne("public B() {")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("super();") + .doesNotContain("static {") + .containsOne("public B() {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDuplicateCast.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDuplicateCast.java index cf3459b4c..b69c07cb9 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDuplicateCast.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDuplicateCast.java @@ -4,20 +4,16 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.instructions.InsnType; import jadx.core.dex.instructions.args.InsnWrapArg; import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.MethodNode; -import jadx.core.utils.BlockUtils; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.core.dex.instructions.InsnType.CHECK_CAST; +import static jadx.core.dex.instructions.InsnType.RETURN; +import static jadx.core.utils.BlockUtils.collectAllInsns; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; /** * Test duplicate 'check-cast' instruction produced because of bug in javac: @@ -36,16 +32,17 @@ public class TestDuplicateCast extends IntegrationTest { ClassNode cls = getClassNode(TestCls.class); MethodNode mth = getMethod(cls, "method"); - String code = cls.getCode().toString(); - assertThat(code, containsString("return (int[]) o;")); + assertThat(cls) + .code() + .contains("return (int[]) o;"); - List insns = BlockUtils.collectAllInsns(mth.getBasicBlocks()); - assertThat(insns, hasSize(1)); + List insns = collectAllInsns(mth.getBasicBlocks()); + assertThat(insns).hasSize(1); InsnNode insnNode = insns.get(0); - assertThat(insnNode.getType(), is(InsnType.RETURN)); - assertTrue(insnNode.getArg(0).isInsnWrap()); + assertThat(insnNode.getType()).isEqualTo(RETURN); + assertThat(insnNode.getArg(0).isInsnWrap()).isTrue(); InsnNode wrapInsn = ((InsnWrapArg) insnNode.getArg(0)).getWrapInsn(); - assertThat(wrapInsn.getType(), is(InsnType.CHECK_CAST)); - assertFalse(wrapInsn.getArg(0).isInsnWrap()); + assertThat(wrapInsn.getType()).isEqualTo(CHECK_CAST); + assertThat(wrapInsn.getArg(0).isInsnWrap()).isFalse(); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestExplicitOverride.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestExplicitOverride.java index 696b52200..e5914b8bb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestExplicitOverride.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestExplicitOverride.java @@ -4,13 +4,13 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestExplicitOverride extends SmaliTest { @Test public void test() { - String code = getClassNodeFromSmali().getCode().getCodeStr(); - assertThat(code, countString(1, "@Override")); + assertThat(getClassNodeFromSmali()) + .code() + .countString(1, "@Override"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldAccessReorder.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldAccessReorder.java index 1b8f41c99..256e9fc99 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldAccessReorder.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldAccessReorder.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.IntegrationTest; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestFieldAccessReorder extends IntegrationTest { public static class TestCls { @@ -22,7 +22,7 @@ public class TestFieldAccessReorder extends IntegrationTest { } public void check() { - assertTrue(test()); + assertThat(test()).isTrue(); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit2.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit2.java index 18823f282..f293e5b1f 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit2.java @@ -2,12 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFieldInit2 extends IntegrationTest { @@ -34,11 +30,10 @@ public class TestFieldInit2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("x = new BasicAbstract() {")); - assertThat(code, containsOne("y = 0;")); - assertThat(code, containsLines(1, "public TestFieldInit2$TestCls(int z) {", "}")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("x = new BasicAbstract() {") + .containsOne("y = 0;") + .containsLines(1, "public TestFieldInit2$TestCls(int z) {", "}"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit3.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit3.java index bbb58a20f..a7f0141cf 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInit3.java @@ -2,12 +2,10 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestFieldInit3 extends IntegrationTest { @@ -37,21 +35,20 @@ public class TestFieldInit3 extends IntegrationTest { } public void check() { - assertThat(new B().field, is(7)); - assertThat(new C().field, is(9)); - assertThat(new C().other, is(11)); - assertThat(new D().field, is(4)); + assertThat(new B().field).isEqualTo(7); + assertThat(new C().field).isEqualTo(9); + assertThat(new C().other).isEqualTo(11); + assertThat(new D().field).isEqualTo(4); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public int field = 4;")); - assertThat(code, containsOne("field = 7;")); - assertThat(code, containsOne("field = 9;")); - assertThat(code, containsOne("public int other = 11;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public int field = 4;") + .containsOne("field = 7;") + .containsOne("field = 9;") + .containsOne("public int other = 11;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInitInTryCatch.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInitInTryCatch.java index 6b109064d..6c81008ab 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInitInTryCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestFieldInitInTryCatch.java @@ -5,12 +5,9 @@ import java.net.URL; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestFieldInitInTryCatch extends IntegrationTest { @@ -55,35 +52,32 @@ public class TestFieldInitInTryCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public static final URL A;")); - assertThat(code, containsOne("A = new URL(\"http://www.example.com/\");")); - assertThat(code, containsLines(2, - "try {", - indent(1) + "A = new URL(\"http://www.example.com/\");", - "} catch (MalformedURLException e) {")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public static final URL A;") + .containsOne("A = new URL(\"http://www.example.com/\");") + .containsLines(2, + "try {", + indent(1) + "A = new URL(\"http://www.example.com/\");", + "} catch (MalformedURLException e) {"); } @Test public void test2() { - ClassNode cls = getClassNode(TestCls2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, - "try {", - indent(1) + "A = new URL[]{new URL(\"http://www.example.com/\")};", - "} catch (MalformedURLException e) {")); + assertThat(getClassNode(TestCls2.class)) + .code() + .containsLines(2, + "try {", + indent(1) + "A = new URL[]{new URL(\"http://www.example.com/\")};", + "} catch (MalformedURLException e) {"); } @Test public void test3() { - ClassNode cls = getClassNode(TestCls3.class); - String code = cls.getCode().toString(); - - // don't move code from try/catch - assertThat(code, containsOne("public static final String[] A;")); - assertThat(code, containsOne("A = new String[]{\"a\"};")); + assertThat(getClassNode(TestCls3.class)) + .code() + // don't move code from try/catch + .containsOne("public static final String[] A;") + .containsOne("A = new String[]{\"a\"};"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestFloatValue.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestFloatValue.java index 6c747f657..0f555c032 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestFloatValue.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestFloatValue.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.within; public class TestFloatValue extends IntegrationTest { @@ -17,7 +17,7 @@ public class TestFloatValue extends IntegrationTest { } public void check() { - assertEquals(0.275f, test()[0], 0.0001f); + assertThat(test()[0]).isCloseTo(0.275f, within(0.0001f)); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestIfInTry.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestIfInTry.java index 0deffd195..dafd481ff 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestIfInTry.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestIfInTry.java @@ -5,12 +5,8 @@ import java.io.IOException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestIfInTry extends IntegrationTest { @@ -41,15 +37,14 @@ public class TestIfInTry extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (a != 0) {")); - assertThat(code, containsOne("} catch (Exception e) {")); - assertThat(code, countString(2, "try {")); - assertThat(code, countString(3, "f()")); - assertThat(code, containsOne("return 1;")); - assertThat(code, containsOne("} catch (IOException e")); - assertThat(code, containsOne("return -1;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (a != 0) {") + .containsOne("} catch (Exception e) {") + .countString(2, "try {") + .countString(3, "f()") + .containsOne("return 1;") + .containsOne("} catch (IOException e") + .containsOne("return -1;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestIfTryInCatch.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestIfTryInCatch.java index 58515232b..d09e42e43 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestIfTryInCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestIfTryInCatch.java @@ -2,12 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIfTryInCatch extends IntegrationTest { @@ -48,11 +45,10 @@ public class TestIfTryInCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(2, "try {")); - assertThat(code, containsOne("if (")); - assertThat(code, countString(2, "return f();")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(2, "try {") + .containsOne("if (") + .countString(2, "return f();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeSuper.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeSuper.java index f8fd01e1e..be8300c97 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeSuper.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeSuper.java @@ -2,11 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInsnsBeforeSuper extends SmaliTest { // @formatter:off @@ -34,9 +32,8 @@ public class TestInsnsBeforeSuper extends SmaliTest { @Test public void test() { allowWarnInCode(); - ClassNode cls = getClassNodeFromSmaliFiles("B"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("checkNull(str);")); + assertThat(getClassNodeFromSmaliFiles("B")) + .code() + .containsOne("checkNull(str);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeThis.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeThis.java index c425766e3..ae1435c65 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeThis.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestInsnsBeforeThis.java @@ -2,11 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInsnsBeforeThis extends SmaliTest { // @formatter:off @@ -32,9 +30,8 @@ public class TestInsnsBeforeThis extends SmaliTest { @Test public void test() { allowWarnInCode(); - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("checkNull(str);")); + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("checkNull(str);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13a.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13a.java index c070f75dd..f85987e4b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13a.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13a.java @@ -9,10 +9,7 @@ import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIssue13a extends IntegrationTest { @@ -94,10 +91,10 @@ public class TestIssue13a extends IntegrationTest { String code = cls.getCode().toString(); for (int i = 1; i <= 7; i++) { - assertThat(code, containsOne("'" + i + '\'')); + assertThat(code).containsOne("'" + i + '\''); } // TODO: add additional checks - assertThat(code, not(containsString("Throwable"))); + assertThat(code).doesNotContain("Throwable"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13b.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13b.java index 0c7446367..15d1b7bfa 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13b.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestIssue13b.java @@ -8,17 +8,13 @@ import java.util.concurrent.CountDownLatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestIssue13b extends IntegrationTest { public static class TestCls { - private static final String PROPERTIES_FILE = ""; private static final String TAG = ""; private final CountDownLatch mInitializedLatch = new CountDownLatch(1); @@ -78,12 +74,10 @@ public class TestIssue13b extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(4, "} catch (")); - assertThat(code, countString(3, "Log.e(")); - - assertThat(code, containsOne("Thread.currentThread().interrupt();")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(4, "} catch (") + .countString(3, "Log.e(") + .containsOne("Thread.currentThread().interrupt();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestJsonOutput.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestJsonOutput.java index f4e0eaadc..cbabec890 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestJsonOutput.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestJsonOutput.java @@ -4,13 +4,10 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.api.JadxArgs; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import static jadx.api.JadxArgs.OutputFormatEnum.JSON; public class TestJsonOutput extends IntegrationTest { @@ -38,25 +35,23 @@ public class TestJsonOutput extends IntegrationTest { @Test public void test() { disableCompilation(); - args.setOutputFormat(JadxArgs.OutputFormatEnum.JSON); + args.setOutputFormat(JSON); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("\"offset\": \"0x")); - assertThat(code, containsOne("public static class Inner implements Runnable")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("\"offset\": \"0x") + .containsOne("public static class Inner implements Runnable"); } @Test public void testFallback() { disableCompilation(); setFallback(); - args.setOutputFormat(JadxArgs.OutputFormatEnum.JSON); + args.setOutputFormat(JSON); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("\"offset\": \"0x")); - assertThat(code, containsOne("public static class Inner implements java.lang.Runnable")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("\"offset\": \"0x") + .containsOne("public static class Inner implements java.lang.Runnable"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestLoopInTry.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestLoopInTry.java index 03b2aaefb..b414d537f 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestLoopInTry.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestLoopInTry.java @@ -2,11 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestLoopInTry extends IntegrationTest { @@ -38,16 +35,15 @@ public class TestLoopInTry extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("if (b) {")); - assertThat(code, containsOne("throw new Exception();")); - assertThat(code, containsOne("while (f()) {")); - assertThat(code, containsOne("s();")); - assertThat(code, containsOne("} catch (Exception e) {")); - assertThat(code, containsOne("return 1;")); - assertThat(code, containsOne("return 0;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {") + .containsOne("if (b) {") + .containsOne("throw new Exception();") + .containsOne("while (f()) {") + .containsOne("s();") + .containsOne("} catch (Exception e) {") + .containsOne("return 1;") + .containsOne("return 0;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantBrackets.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantBrackets.java index 3c1f35daf..d1eac17d4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantBrackets.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantBrackets.java @@ -2,12 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestRedundantBrackets extends IntegrationTest { @@ -47,24 +44,20 @@ public class TestRedundantBrackets extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("(-1)"))); - assertThat(code, not(containsString("return;"))); - - assertThat(code, containsString("if (obj instanceof String) {")); - assertThat(code, containsString("return ((String) obj).length();")); - assertThat(code, containsString("a + b < 10")); - assertThat(code, containsString("(a & b) != 0")); - assertThat(code, containsString("if (num == 4 || num == 6 || num == 8 || num == 10)")); - - assertThat(code, containsString("a[1] = n * 2;")); - assertThat(code, containsString("a[n - 1] = 1;")); - - // argument type not changed to String - assertThat(code, containsString("public int method2(Object obj) {")); - // cast not eliminated - assertThat(code, containsString("((String) obj).length()")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("(-1)") + .doesNotContain("return;") + .contains("if (obj instanceof String) {") + .contains("return ((String) obj).length();") + .contains("a + b < 10") + .contains("(a & b) != 0") + .contains("if (num == 4 || num == 6 || num == 8 || num == 10)") + .contains("a[1] = n * 2;") + .contains("a[n - 1] = 1;") + .contains("public int method2(Object obj) {") + // argument type isn't changed to String + // cast not eliminated + .contains("((String) obj).length()"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantReturn.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantReturn.java index 4f4ac6abb..5b2a3bd9e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantReturn.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestRedundantReturn.java @@ -2,29 +2,25 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class TestRedundantReturn extends IntegrationTest { public static class TestCls { public void test(int num) { if (num == 4) { - fail(); + fail(""); } } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("return;"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("return;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestReturnWrapping.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestReturnWrapping.java index 222de3078..257cf2957 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestReturnWrapping.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestReturnWrapping.java @@ -2,11 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestReturnWrapping extends IntegrationTest { public static class TestCls { @@ -48,13 +45,11 @@ public class TestReturnWrapping extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return 255;")); - assertThat(code, containsString("return arg0 + 1;")); - assertThat(code, containsString("return i > 128 ? arg0.toString() + ret.toString() : Integer.valueOf(i);")); - assertThat(code, containsString("return arg0 + 2;")); - assertThat(code, containsString("arg0 -= 951;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return 255;") + .contains("return arg0 + 1;").contains("return i > 128 ? arg0.toString() + ret.toString() : Integer.valueOf(i);") + .contains("return arg0 + 2;") + .contains("arg0 -= 951;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticFieldsInit.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticFieldsInit.java index 2406a25bf..dbd1653fe 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticFieldsInit.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticFieldsInit.java @@ -2,12 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestStaticFieldsInit extends IntegrationTest { @@ -30,10 +27,9 @@ public class TestStaticFieldsInit extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("public static final String S2 = null;"))); - assertThat(code, containsString("public static final String S3 = null;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("public static final String S2 = null;") + .contains("public static final String S3 = null;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticMethod.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticMethod.java index 29330cd96..46f87ff1c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticMethod.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStaticMethod.java @@ -2,11 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestStaticMethod extends IntegrationTest { @@ -21,10 +18,9 @@ public class TestStaticMethod extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("static {")); - assertThat(code, containsString("private static void f() {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("static {") + .contains("private static void f() {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination.java index 81a19aea9..6cdd78e8a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination.java @@ -2,12 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestStringBuilderElimination extends IntegrationTest { @@ -25,13 +22,11 @@ public class TestStringBuilderElimination extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(MyException.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("MyException(String str, Exception e) {")); - assertThat(code, containsString("super(\"msg:\" + str, e);")); - - assertThat(code, not(containsString("new StringBuilder"))); - assertThat(code, containsString("System.out.println(\"k=\" + k);")); + assertThat(getClassNode(MyException.class)) + .code() + .contains("MyException(String str, Exception e) {") + .contains("super(\"msg:\" + str, e);") + .doesNotContain("new StringBuilder") + .contains("System.out.println(\"k=\" + k);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination2.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination2.java index 96d8e49ab..7d708dce5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination2.java @@ -2,12 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.visitors.SimplifyVisitor; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; /** * Test the StringBuilder simplification part of {@link SimplifyVisitor} @@ -26,9 +23,9 @@ public class TestStringBuilderElimination2 extends IntegrationTest { @Test public void test1() { - ClassNode cls = getClassNode(TestStringBuilderElimination2.TestCls1.class); - String code = cls.getCode().toString(); - assertThat(code, containsString("return \"[init]a1c201.02.0true\";")); + JadxAssertions.assertThat(getClassNode(TestCls1.class)) + .code() + .contains("return \"[init]a1c201.02.0true\";"); } public static class TestCls2 { @@ -48,9 +45,9 @@ public class TestStringBuilderElimination2 extends IntegrationTest { @Test public void test2() { - ClassNode cls = getClassNode(TestStringBuilderElimination2.TestCls2.class); - String code = cls.getCode().toString(); - assertThat(code, containsString("return \"[init]a1c121.02.0true\";")); + JadxAssertions.assertThat(getClassNode(TestCls2.class)) + .code() + .contains("return \"[init]a1c121.02.0true\";"); } public static class TestClsStringUtilsReverse { @@ -65,9 +62,9 @@ public class TestStringBuilderElimination2 extends IntegrationTest { @Test public void test3() { - ClassNode cls = getClassNode(TestClsStringUtilsReverse.class); - String code = cls.getCode().toString(); - assertThat(code, containsString("return new StringBuilder(str).reverse().toString();")); + JadxAssertions.assertThat(getClassNode(TestClsStringUtilsReverse.class)) + .code() + .contains("return new StringBuilder(str).reverse().toString();"); } public static class TestClsChainWithDelete { @@ -79,8 +76,8 @@ public class TestStringBuilderElimination2 extends IntegrationTest { @Test public void testChainWithDelete() { - ClassNode cls = getClassNode(TestClsChainWithDelete.class); - String code = cls.getCode().toString(); - assertThat(code, containsString("return new StringBuilder(\"[init]\").append(\"a1\").delete(1, 2).toString();")); + JadxAssertions.assertThat(getClassNode(TestClsChainWithDelete.class)) + .code() + .contains("return new StringBuilder(\"[init]\").append(\"a1\").delete(1, 2).toString();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination3.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination3.java index 85b437e26..5968ade6d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination3.java @@ -2,13 +2,10 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestStringBuilderElimination3 extends IntegrationTest { @@ -23,11 +20,10 @@ public class TestStringBuilderElimination3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return \"result = \" + a;")); - assertThat(code, not(containsString("new StringBuilder()"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return \"result = \" + a;") + .doesNotContain("new StringBuilder()"); } public static class TestClsNegative { @@ -48,16 +44,15 @@ public class TestStringBuilderElimination3 extends IntegrationTest { } public void check() { - assertThat(test(), is("before = first, after = second")); + assertThat(test()).isEqualTo("before = first, after = second"); } } @Test public void testNegative() { - ClassNode cls = getClassNode(TestClsNegative.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return sb.toString();")); - assertThat(code, containsString("new StringBuilder()")); + JadxAssertions.assertThat(getClassNode(TestClsNegative.class)) + .code() + .contains("return sb.toString();") + .contains("new StringBuilder()"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination4Neg.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination4Neg.java index 5fe85a9d5..6bb404f26 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination4Neg.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringBuilderElimination4Neg.java @@ -2,11 +2,8 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestStringBuilderElimination4Neg extends IntegrationTest { @@ -25,9 +22,8 @@ public class TestStringBuilderElimination4Neg extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("sb.append('=');")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("sb.append('=');"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java index 884ed14dc..9a9a64141 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java @@ -4,11 +4,8 @@ import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestStringConstructor extends IntegrationTest { @@ -18,10 +15,9 @@ public class TestStringConstructor extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("abc")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("abc"); } public static class TestCls2 { @@ -30,10 +26,9 @@ public class TestStringConstructor extends IntegrationTest { @Test public void test2() { - ClassNode cls = getClassNode(TestCls2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("new String(\"abc\".getBytes(), StandardCharsets.UTF_8)")); + JadxAssertions.assertThat(getClassNode(TestCls2.class)) + .code() + .containsOne("new String(\"abc\".getBytes(), StandardCharsets.UTF_8)"); } public static class TestCls3 { @@ -42,10 +37,9 @@ public class TestStringConstructor extends IntegrationTest { @Test public void test3() { - ClassNode cls = getClassNode(TestCls3.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("\\u0001\\u0002\\u0003abc")); + JadxAssertions.assertThat(getClassNode(TestCls3.class)) + .code() + .containsOne("\\u0001\\u0002\\u0003abc"); } public static class TestCls4 { @@ -54,10 +48,9 @@ public class TestStringConstructor extends IntegrationTest { @Test public void test4() { - ClassNode cls = getClassNode(TestCls4.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("\\u0001\\u0002\\u0003abc")); + JadxAssertions.assertThat(getClassNode(TestCls4.class)) + .code() + .containsOne("\\u0001\\u0002\\u0003abc"); } public static class TestCls5 { @@ -66,10 +59,9 @@ public class TestStringConstructor extends IntegrationTest { @Test public void test5() { - ClassNode cls = getClassNode(TestCls5.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("{1, 2, 3, 'a', 'b'}")); + JadxAssertions.assertThat(getClassNode(TestCls5.class)) + .code() + .containsOne("{1, 2, 3, 'a', 'b'}"); } public static class TestClsNegative { @@ -78,10 +70,9 @@ public class TestStringConstructor extends IntegrationTest { @Test public void testNegative() { - ClassNode cls = getClassNode(TestClsNegative.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("tag = new String();")); + JadxAssertions.assertThat(getClassNode(TestClsNegative.class)) + .code() + .containsOne("tag = new String();"); } public static class TestClsNegative2 { @@ -91,9 +82,8 @@ public class TestStringConstructor extends IntegrationTest { @Test public void testNegative2() { - ClassNode cls = getClassNode(TestClsNegative2.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("tag = new String(new byte[]{31, this.b});")); + JadxAssertions.assertThat(getClassNode(TestClsNegative2.class)) + .code() + .containsOne("tag = new String(new byte[]{31, this.b});"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestUsageApacheHttpClient.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestUsageApacheHttpClient.java index d16c5c07b..fb494cd0e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestUsageApacheHttpClient.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestUsageApacheHttpClient.java @@ -1,11 +1,12 @@ package jadx.tests.integration.others; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; + public class TestUsageApacheHttpClient extends SmaliTest { // @formatter:off @@ -23,6 +24,6 @@ public class TestUsageApacheHttpClient extends SmaliTest { public void test() { disableCompilation(); ClassNode cls = getClassNodeFromSmali(); - Assertions.assertTrue(cls.root().getGradleInfoStorage().isUseApacheHttpLegacy()); + assertThat(cls.root().getGradleInfoStorage().isUseApacheHttpLegacy()).isTrue(); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestWrongCode.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestWrongCode.java index 35b30a8ce..815d73aa7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestWrongCode.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestWrongCode.java @@ -2,14 +2,9 @@ package jadx.tests.integration.others; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestWrongCode extends IntegrationTest { @@ -29,17 +24,15 @@ public class TestWrongCode extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("return false.length;"))); - assertThat(code, containsOne("int[] a = null;")); - assertThat(code, containsOne("return a.length;")); - - assertThat(code, containsLines(2, - "if (a == 0) {", - "}", - "return a;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("return false.length;") + .containsOne("int[] a = null;") + .containsOne("return a.length;") + .containsLines(2, + "if (a == 0) {", + "}", + "return a;"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch.java index 03f28b10b..d8823bd64 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch.java @@ -2,12 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitch extends IntegrationTest { public static class TestCls { @@ -40,14 +37,12 @@ public class TestSwitch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("case '/':")); - assertThat(code, containsString(indent(5) + "break;")); - assertThat(code, containsString(indent(4) + "default:")); - - assertEquals(1, count(code, "i++")); - assertEquals(4, count(code, "break;")); + assertThat(getClassNode(TestCls.class)) + .code() + .contains("case '/':") + .contains(indent(5) + "break;") + .contains(indent(4) + "default:") + .containsOne("i++") + .countString(4, "break;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch2.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch2.java index 38e33eb33..23ac0d6f2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch2.java @@ -2,11 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitch2 extends IntegrationTest { public static class TestCls { @@ -57,14 +55,12 @@ public class TestSwitch2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - // assertThat(code, countString(4, "break;")); - // assertThat(code, countString(2, "return;")); - - // TODO: remove redundant break and returns - assertThat(code, countString(5, "break;")); - assertThat(code, countString(4, "return;")); + assertThat(getClassNode(TestCls.class)) + .code() + // .countString(4, "break;" + // .countString(2, "return;") + // TODO: remove redundant reak and returns + .countString(5, "break;") + .countString(4, "return;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch3.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch3.java index 6935b97aa..7ec100cd4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitch3.java @@ -2,12 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitch3 extends IntegrationTest { @@ -32,24 +29,23 @@ public class TestSwitch3 extends IntegrationTest { public void check() { test(1); - assertThat(i, is(1)); + assertThat(i).isEqualTo(1); test(2); - assertThat(i, is(2)); + assertThat(i).isEqualTo(2); test(3); - assertThat(i, is(2)); + assertThat(i).isEqualTo(2); test(4); - assertThat(i, is(5)); + assertThat(i).isEqualTo(5); test(10); - assertThat(i, is(5)); + assertThat(i).isEqualTo(5); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, countString(0, "break;")); - assertThat(code, countString(3, "return;")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(0, "break;") + .countString(3, "return;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchBreak.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchBreak.java index 96e5cc2dc..ea44f4c5e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchBreak.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchBreak.java @@ -2,15 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitchBreak extends IntegrationTest { @@ -37,21 +31,19 @@ public class TestSwitchBreak extends IntegrationTest { } public void check() { - assertThat(test(9), is("1--4--1--4--1-")); + assertThat(test(9)).isEqualTo("1--4--1--4--1-"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("switch (a % 4) {")); - assertEquals(4, count(code, "case ")); - assertEquals(2, count(code, "break;")); - assertThat(code, not(containsString("default:"))); - - // TODO finish break with label from switch - assertThat(code, containsOne("return s + \"+\";")); + assertThat(getClassNode(TestCls.class)) + .code() + .contains("switch (a % 4) {") + .countString(4, "case ") + .countString(2, "break;") + .doesNotContain("default:") + // TODO finish break with label from switch + .containsOne("return s + \"+\";"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchContinue.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchContinue.java index c2d29b114..cb4859d36 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchContinue.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchContinue.java @@ -2,13 +2,8 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSwitchContinue extends IntegrationTest { @@ -37,14 +32,12 @@ public class TestSwitchContinue extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("switch (a % 4) {")); - assertEquals(4, count(code, "case ")); - assertEquals(2, count(code, "break;")); - - assertThat(code, containsOne("a -= 2;")); - assertThat(code, containsOne("continue;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("switch (a % 4) {") + .countString(4, "case ") + .countString(2, "break;") + .containsOne("a -= 2;") + .containsOne("continue;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchInLoop.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchInLoop.java index d09b39eb0..f69b8e897 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchInLoop.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchInLoop.java @@ -2,12 +2,10 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestSwitchInLoop extends IntegrationTest { public static class TestCls { @@ -25,20 +23,19 @@ public class TestSwitchInLoop extends IntegrationTest { } public void check() { - assertEquals(1, test(1)); + assertThat(test(1)).isEqualTo(1); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("switch (k) {")); - assertThat(code, containsOne("case 0:")); - assertThat(code, containsOne("return a;")); - assertThat(code, containsOne("default:")); - assertThat(code, containsOne("a++;")); - assertThat(code, containsOne("k >>= 1;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("switch (k) {") + .containsOne("case 0:") + .containsOne("return a;") + .containsOne("default:") + .containsOne("a++;") + .containsOne("k >>= 1;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchLabels.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchLabels.java index d2d9148b2..ef5f586b7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchLabels.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchLabels.java @@ -2,12 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitchLabels extends IntegrationTest { public static class TestCls { @@ -37,29 +34,24 @@ public class TestSwitchLabels extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - assertThat(code, containsString("case CONST_ABC")); - assertThat(code, containsString("return CONST_CDE;")); - - cls.addInnerClass(getClassNode(TestCls.Inner.class)); - assertThat(code, not(containsString("case CONST_CDE_PRIVATE"))); - assertThat(code, containsString(".CONST_ABC;")); + assertThat(getClassNode(TestCls.class)) + .code() + .contains("case CONST_ABC") + .contains("return CONST_CDE;") + .doesNotContain("case CONST_CDE_PRIVATE") + .contains(".CONST_ABC;"); } @Test public void testWithDisabledConstReplace() { getArgs().setReplaceConsts(false); - - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - assertThat(code, not(containsString("case CONST_ABC"))); - assertThat(code, containsString("case 2748")); - assertThat(code, not(containsString("return CONST_CDE;"))); - assertThat(code, containsString("return 3294;")); - - cls.addInnerClass(getClassNode(TestCls.Inner.class)); - assertThat(code, not(containsString("case CONST_CDE_PRIVATE"))); - assertThat(code, not(containsString(".CONST_ABC;"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("case CONST_ABC") + .contains("case 2748") + .doesNotContain("return CONST_CDE;") + .contains("return 3294;") + .doesNotContain("case CONST_CDE_PRIVATE") + .doesNotContain(".CONST_ABC;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchNoDefault.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchNoDefault.java index 44a9838af..8a5f65108 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchNoDefault.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchNoDefault.java @@ -2,10 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitchNoDefault extends IntegrationTest { @@ -32,10 +31,9 @@ public class TestSwitchNoDefault extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertEquals(4, count(code, "break;")); - assertEquals(1, count(code, "System.out.println(s);")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(4, "break;") + .containsOne("System.out.println(s);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase.java index 2fec12709..85f293b12 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase.java @@ -2,13 +2,8 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSwitchReturnFromCase extends IntegrationTest { @@ -43,18 +38,15 @@ public class TestSwitchReturnFromCase extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("switch (a % 10) {")); - - // case 5: removed - assertEquals(5, count(code, "case ")); - assertEquals(3, count(code, "break;")); - - assertThat(code, containsOne("s = \"1\";")); - assertThat(code, containsOne("s = \"2\";")); - assertThat(code, containsOne("s = \"4\";")); - assertThat(code, containsOne("s = \"5\";")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("switch (a % 10) {") + // case 5: removed + .countString(5, "case ") + .countString(3, "break;") + .containsOne("s = \"1\";") + .containsOne("s = \"2\";") + .containsOne("s = \"4\";") + .containsOne("s = \"5\";"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase2.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase2.java index bad3cc7b2..8461dee73 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchReturnFromCase2.java @@ -2,13 +2,10 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class TestSwitchReturnFromCase2 extends IntegrationTest { @@ -26,18 +23,17 @@ public class TestSwitchReturnFromCase2 extends IntegrationTest { } public void check() { - assertTrue(test(2)); - assertTrue(test(3)); - assertTrue(test(15)); - assertFalse(test(1)); + assertThat(test(2)).isTrue(); + assertThat(test(3)).isTrue(); + assertThat(test(15)).isTrue(); + assertThat(test(1)).isFalse(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("switch (a % 4) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("switch (a % 4) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchSimple.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchSimple.java index dafb59e46..7f7ef5050 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchSimple.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchSimple.java @@ -2,13 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSwitchSimple extends IntegrationTest { @@ -38,14 +34,12 @@ public class TestSwitchSimple extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertEquals(5, count(code, "break;")); - assertEquals(1, count(code, "System.out.println(s);")); - assertEquals(1, count(code, "System.out.println(\"Not Reach\");")); - - assertThat(code, not(containsString("switch ((a % 4)) {"))); - assertThat(code, containsString("switch (a % 4) {")); + assertThat(getClassNode(TestCls.class)) + .code() + .countString(5, "break;") + .containsOne("System.out.println(s);") + .containsOne("System.out.println(\"Not Reach\");") + .doesNotContain("switch ((a % 4)) {") + .contains("switch (a % 4) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase.java index e3ccad501..f05de2c3d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase.java @@ -2,12 +2,10 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestSwitchWithFallThroughCase extends IntegrationTest { @@ -43,20 +41,19 @@ public class TestSwitchWithFallThroughCase extends IntegrationTest { } public void check() { - assertEquals(">1;", test(5, true, true)); - assertEquals(">2;", test(1, true, true)); - assertEquals(";", test(3, true, true)); - assertEquals("default;", test(0, true, true)); + assertThat(test(5, true, true)).isEqualTo(">1;"); + assertThat(test(1, true, true)).isEqualTo(">2;"); + assertThat(test(3, true, true)).isEqualTo(";"); + assertThat(test(0, true, true)).isEqualTo("default;"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("switch (a % 4) {")); - assertThat(code, containsOne("if (a == 5 && b) {")); - assertThat(code, containsOne("if (b) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("switch (a % 4) {") + .containsOne("if (a == 5 && b) {") + .containsOne("if (b) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase2.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase2.java index fe90991c3..c142e9de4 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithFallThroughCase2.java @@ -2,12 +2,10 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestSwitchWithFallThroughCase2 extends IntegrationTest { @@ -47,21 +45,20 @@ public class TestSwitchWithFallThroughCase2 extends IntegrationTest { } public void check() { - assertEquals(">1+-", test(5, true, true)); - assertEquals(">2+-", test(1, true, true)); - assertEquals("+-", test(3, true, true)); - assertEquals("default+-", test(16, true, true)); - assertEquals("-", test(-1, true, true)); + assertThat(test(5, true, true)).isEqualTo(">1+-"); + assertThat(test(1, true, true)).isEqualTo(">2+-"); + assertThat(test(3, true, true)).isEqualTo("+-"); + assertThat(test(16, true, true)).isEqualTo("default+-"); + assertThat(test(-1, true, true)).isEqualTo("-"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("switch (a % 4) {")); - assertThat(code, containsOne("if (a == 5 && b) {")); - assertThat(code, containsOne("if (b) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("switch (a % 4) {") + .containsOne("if (a == 5 && b) {") + .containsOne("if (b) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java index dba88fd67..308d150d2 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/switches/TestSwitchWithTryCatch.java @@ -2,11 +2,9 @@ package jadx.tests.integration.switches; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.countString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; @SuppressWarnings("checkstyle:printstacktrace") public class TestSwitchWithTryCatch extends IntegrationTest { @@ -60,13 +58,11 @@ public class TestSwitchWithTryCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - // assertThat(code, countString(3, "break;")); - assertThat(code, countString(4, "return;")); - - // TODO: remove redundant break - assertThat(code, countString(4, "break;")); + assertThat(getClassNode(TestCls.class)) + .code() + // .countString(3, "break;") + .countString(4, "return;") + // TODO: remove redundant break + .countString(4, "break;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized.java b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized.java index 6260dd953..21921f845 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized.java +++ b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized.java @@ -2,13 +2,8 @@ package jadx.tests.integration.synchronize; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSynchronized extends IntegrationTest { @@ -30,17 +25,15 @@ public class TestSynchronized extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("synchronized (this) {"))); - assertThat(code, containsOne("public synchronized boolean test1() {")); - assertThat(code, containsOne("return this.f")); - assertThat(code, containsOne("synchronized (this.o) {")); - - assertThat(code, not(containsString(indent(3) + ';'))); - assertThat(code, not(containsString("try {"))); - assertThat(code, not(containsString("} catch (Throwable th) {"))); - assertThat(code, not(containsString("throw th;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("synchronized (this) {") + .containsOne("public synchronized boolean test1() {") + .containsOne("return this.f") + .containsOne("synchronized (this.o) {") + .doesNotContain(indent(3) + ';') + .doesNotContain("try {") + .doesNotContain("} catch (Throwable th) {") + .doesNotContain("throw th;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized2.java b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized2.java index 8691e769b..36feb0a6c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized2.java @@ -3,12 +3,8 @@ package jadx.tests.integration.synchronize; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestSynchronized2 extends IntegrationTest { @@ -21,11 +17,10 @@ public class TestSynchronized2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("private static synchronized boolean test(Object obj) {")); - assertThat(code, containsString("obj.toString() != null;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("private static synchronized boolean test(Object obj) {") + .contains("obj.toString() != null;"); } @Test @@ -33,10 +28,9 @@ public class TestSynchronized2 extends IntegrationTest { public void test2() { useDexInput(); // java bytecode don't add exception handlers - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("return obj.toString() != null;")); - assertThat(code, not(containsString("synchronized ("))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("return obj.toString() != null;") + .doesNotContain("synchronized ("); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized3.java b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized3.java index 0ad776d76..210cbed61 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized3.java @@ -2,11 +2,9 @@ package jadx.tests.integration.synchronize; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSynchronized3 extends IntegrationTest { @@ -35,9 +33,8 @@ public class TestSynchronized3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(3, "}", "this.x++;", "f();")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(3, "}", "this.x++;", "f();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized5.java b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized5.java index 2a918bcb7..f2b8b1025 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/synchronize/TestSynchronized5.java @@ -2,19 +2,16 @@ package jadx.tests.integration.synchronize; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestSynchronized5 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsString("1 != 0")); - assertThat(code, containsString("System.gc();")); + assertThat(getClassNodeFromSmali()) + .code() + .contains("1 != 0") + .contains("System.gc();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally.java index 53b07bea6..bd6552b07 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally.java @@ -2,12 +2,8 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFinally extends IntegrationTest { @@ -54,11 +50,10 @@ public class TestFinally extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("} finally {")); - assertThat(code, containsOne("cursor.getString(columnIndex);")); - assertThat(code, not(containsOne("String str = true;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} finally {") + .containsOne("cursor.getString(columnIndex);") + .doesNotContain("String str = true;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java index b7d1d288e..30b2ba159 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java @@ -6,12 +6,8 @@ import java.io.InputStream; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestFinally2 extends IntegrationTest { @@ -54,11 +50,10 @@ public class TestFinally2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("decode(inputStream);")); - assertThat(code, containsOne("return new Result(400);")); - assertThat(code, not(containsOne("result ="))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("decode(inputStream);") + .containsOne("return new Result(400);") + .doesNotContain("result ="); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinallyExtract.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinallyExtract.java index 3fd7ed837..588ca32b0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinallyExtract.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinallyExtract.java @@ -2,14 +2,10 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class TestFinallyExtract extends IntegrationTest { @@ -36,30 +32,33 @@ public class TestFinallyExtract extends IntegrationTest { public void check() { test(); - assertEquals(1, result); + assertThat(result).isEqualTo(1); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} finally {") + .doesNotContain("if (0 == 0) {") - assertThat(code, containsOne("} finally {")); - assertThat(code, not(containsString("if (0 == 0) {"))); - - assertThat(code, containsOne("boolean success = false;")); - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("success = true;")); - assertThat(code, containsOne("return value;")); - assertThat(code, containsOne("if (!success) {")); + .containsOne("boolean success = false;") + .containsOne("try {") + .containsOne("success = true;") + .containsOne("return value;") + .containsOne("if (!success) {"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("this.result++;") + .containsOne("} catch (Throwable th) {") + .containsOne("this.result -= 2;") + .containsOne("throw th;"); // java compiler optimization: 'success' variable completely removed and no code duplication: // @formatter:off @@ -76,10 +75,5 @@ public class TestFinallyExtract extends IntegrationTest { } */ // @formatter:on - - assertThat(code, containsOne("this.result++;")); - assertThat(code, containsOne("} catch (Throwable th) {")); - assertThat(code, containsOne("this.result -= 2;")); - assertThat(code, containsOne("throw th;")); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestInlineInCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestInlineInCatch.java index e692227b4..2ddfa2146 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestInlineInCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestInlineInCatch.java @@ -4,11 +4,8 @@ import java.io.File; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInlineInCatch extends IntegrationTest { @@ -34,15 +31,14 @@ public class TestInlineInCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("File output = null;")); - assertThat(code, containsOne("output = File.createTempFile(\"f\", \"a\", ")); - assertThat(code, containsOne("return 0;")); - assertThat(code, containsOne("} catch (Exception e) {")); - assertThat(code, containsOne("if (output != null) {")); - assertThat(code, containsOne("output.delete();")); - assertThat(code, containsOne("return 2;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("File output = null;") + .containsOne("output = File.createTempFile(\"f\", \"a\", ") + .containsOne("return 0;") + .containsOne("} catch (Exception e) {") + .containsOne("if (output != null) {") + .containsOne("output.delete();") + .containsOne("return 2;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch.java index 94e3d0d26..071f1c607 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch.java @@ -5,13 +5,8 @@ import java.time.DateTimeException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestMultiExceptionCatch extends IntegrationTest { @@ -27,12 +22,11 @@ public class TestMultiExceptionCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("} catch (ProviderException | DateTimeException e) {")); - assertThat(code, containsOne("throw new RuntimeException(e);")); - assertThat(code, not(containsString("RuntimeException e;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {") + .containsOne("} catch (ProviderException | DateTimeException e) {") + .containsOne("throw new RuntimeException(e);") + .doesNotContain("RuntimeException e;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java index 4361a1199..b579f62ed 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatch2.java @@ -5,11 +5,8 @@ import java.lang.reflect.InvocationTargetException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; @SuppressWarnings("checkstyle:printstacktrace") public class TestMultiExceptionCatch2 extends IntegrationTest { @@ -36,12 +33,11 @@ public class TestMultiExceptionCatch2 extends IntegrationTest { } private void commonChecks() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {")); - assertThat(code, containsOne("e.printStackTrace();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {") + .containsOne("} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {") + .containsOne("e.printStackTrace();"); // TODO: store vararg attribute for methods from classpath // assertThat(code, containsOne("constructor.newInstance();")); diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatchSameJump.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatchSameJump.java index aae2c06ac..bfa968234 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatchSameJump.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestMultiExceptionCatchSameJump.java @@ -2,14 +2,11 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +@SuppressWarnings("CommentedOutCode") public class TestMultiExceptionCatchSameJump extends SmaliTest { // @formatter:off /* @@ -24,14 +21,14 @@ public class TestMultiExceptionCatchSameJump extends SmaliTest { } */ // @formatter:on + @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPkg("trycatch", "TestMultiExceptionCatchSameJump"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("} catch (ProviderException | DateTimeException e) {")); - assertThat(code, containsOne("throw new RuntimeException(e);")); - assertThat(code, not(containsString("RuntimeException e;"))); + assertThat(getClassNodeFromSmaliWithPkg("trycatch", "TestMultiExceptionCatchSameJump")) + .code() + .containsOne("try {") + .containsOne("} catch (ProviderException | DateTimeException e) {") + .containsOne("throw new RuntimeException(e);") + .doesNotContain("RuntimeException e;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestNestedTryCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestNestedTryCatch.java index 3345498b2..86fe9edf3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestNestedTryCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestNestedTryCatch.java @@ -2,12 +2,8 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestNestedTryCatch extends IntegrationTest { @@ -28,14 +24,13 @@ public class TestNestedTryCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("try {")); - assertThat(code, containsString("Thread.sleep(1L);")); - assertThat(code, containsString("Thread.sleep(2L);")); - assertThat(code, containsString("} catch (InterruptedException e) {")); - assertThat(code, containsString("} catch (Exception e2) {")); - assertThat(code, not(containsString("return"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("try {") + .contains("Thread.sleep(1L);") + .contains("Thread.sleep(2L);") + .contains("} catch (InterruptedException e) {") + .contains("} catch (Exception e2) {") + .doesNotContain("return"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryAfterDeclaration.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryAfterDeclaration.java index 27ade5902..5481d8017 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryAfterDeclaration.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryAfterDeclaration.java @@ -7,11 +7,8 @@ import java.io.InputStream; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryAfterDeclaration extends IntegrationTest { @@ -34,9 +31,8 @@ public class TestTryAfterDeclaration extends IntegrationTest { @Test @NotYetImplemented public void test62() { - ClassNode cls = getClassNode(TestClass.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); + JadxAssertions.assertThat(getClassNode(TestClass.class)) + .code() + .containsOne("try {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch.java index 5a765c017..e91683d97 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch.java @@ -2,12 +2,8 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatch extends IntegrationTest { @@ -23,12 +19,11 @@ public class TestTryCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("try {")); - assertThat(code, containsString("Thread.sleep(50L);")); - assertThat(code, containsString("} catch (InterruptedException e) {")); - assertThat(code, not(containsString("return"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("try {") + .contains("Thread.sleep(50L);") + .contains("} catch (InterruptedException e) {") + .doesNotContain("return"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch2.java index 9f00fd482..e20a9cfdb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch2.java @@ -2,11 +2,8 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatch2 extends IntegrationTest { @@ -27,14 +24,13 @@ public class TestTryCatch2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("try {")); - assertThat(code, containsString("synchronized (OBJ) {")); - assertThat(code, containsString("OBJ.wait(5L);")); - assertThat(code, containsString("return true;")); - assertThat(code, containsString("} catch (InterruptedException e) {")); - assertThat(code, containsString("return false;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("try {") + .contains("synchronized (OBJ) {") + .contains("OBJ.wait(5L);") + .contains("return true;") + .contains("} catch (InterruptedException e) {") + .contains("return false;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch6.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch6.java index ae1e98ca8..1c7bdab6d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch6.java @@ -4,12 +4,9 @@ import java.io.IOException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTryCatch6 extends IntegrationTest { @@ -38,24 +35,22 @@ public class TestTryCatch6 extends IntegrationTest { } public void check() { - assertTrue(test(new Object())); + assertThat(test(new Object())).isTrue(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java index 0bca0f1a0..a23acf0a1 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch7.java @@ -5,8 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; @SuppressWarnings("checkstyle:printstacktrace") public class TestTryCatch7 extends IntegrationTest { @@ -28,7 +27,6 @@ public class TestTryCatch7 extends IntegrationTest { public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); - check(code, "e", "ex"); } @@ -37,15 +35,14 @@ public class TestTryCatch7 extends IntegrationTest { noDebugInfo(); ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); - check(code, "e", "e2"); } private void check(String code, String excVarName, String catchExcVarName) { - assertThat(code, containsOne("Exception " + excVarName + " = new Exception();")); - assertThat(code, containsOne("} catch (Exception " + catchExcVarName + ") {")); - assertThat(code, containsOne(excVarName + " = " + catchExcVarName + ';')); - assertThat(code, containsOne(excVarName + ".printStackTrace();")); - assertThat(code, containsOne("return " + excVarName + ';')); + assertThat(code).containsOne("Exception " + excVarName + " = new Exception();") + .containsOne("} catch (Exception " + catchExcVarName + ") {") + .containsOne(excVarName + " = " + catchExcVarName + ';') + .containsOne(excVarName + ".printStackTrace();") + .containsOne("return " + excVarName + ';'); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch8.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch8.java index fa8d878b5..ab9c567a8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch8.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatch8.java @@ -2,14 +2,9 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.isA; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTryCatch8 extends IntegrationTest { @@ -41,32 +36,29 @@ public class TestTryCatch8 extends IntegrationTest { public void check() { test(); - assertThat(e, notNullValue()); - assertThat(e, isA(MyException.class)); - assertThat(e.getMessage(), nullValue()); + assertThat(e).isInstanceOf(MyException.class); + assertThat(e.getMessage()).isNull(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("synchronized (this) {")); - assertThat(code, containsOne("throw new MyException();")); - assertThat(code, containsOne("} catch (MyException myExc) {")); - assertThat(code, containsOne("this.e = myExc;")); - assertThat(code, containsOne("} catch (Exception ex) {")); - assertThat(code, containsOne("this.e = new MyException(\"MyExc\", ex);")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("synchronized (this) {") + .containsOne("throw new MyException();") + .containsOne("} catch (MyException myExc) {") + .containsOne("this.e = myExc;") + .containsOne("} catch (Exception ex) {") + .containsOne("this.e = new MyException(\"MyExc\", ex);"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("synchronized (this) {")); - assertThat(code, containsOne("throw new MyException();")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("synchronized (this) {") + .containsOne("throw new MyException();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java index 2906594d2..d4119703b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("checkstyle:printstacktrace") public class TestTryCatchFinally extends IntegrationTest { @@ -34,8 +33,8 @@ public class TestTryCatchFinally extends IntegrationTest { } public void check() { - assertTrue(test("a")); - assertTrue(test(null)); + assertThat(test("a")).isTrue(); + assertThat(test(null)).isTrue(); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally2.java index 7a2966302..40d5e9bc8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally2.java @@ -8,11 +8,8 @@ import org.junit.jupiter.api.Test; import jadx.core.clsp.ClspClass; import jadx.core.dex.instructions.args.ArgType; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatchFinally2 extends IntegrationTest { @@ -45,15 +42,12 @@ public class TestTryCatchFinally2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("} finally {")); - assertThat(code, containsOne("out.close();")); - - assertThat(code, containsOne("for (ArgType parent : parents) {")); - - assertThat(code, containsOne("for (ClspClass cls : this.classes) {")); - assertThat(code, containsOne("for (ClspClass cls2 : this.classes) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} finally {") + .containsOne("out.close();") + .containsOne("for (ArgType parent : parents) {") + .containsOne("for (ClspClass cls : this.classes) {") + .containsOne("for (ClspClass cls2 : this.classes) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally3.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally3.java index 9fa7e5969..10df9b42d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally3.java @@ -10,9 +10,7 @@ import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.visitors.DepthTraversal; import jadx.core.dex.visitors.IDexTreeVisitor; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatchFinally3 extends IntegrationTest { @@ -35,15 +33,12 @@ public class TestTryCatchFinally3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (IDexTreeVisitor visitor : passes) {")); - - assertThat(code, containsOne("} catch (Exception e) {")); - assertThat(code, containsOne("LOG.error(\"Class process exception: {}\", cls, e);")); - - assertThat(code, containsOne("} finally {")); - assertThat(code, containsOne("cls.unload();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("for (IDexTreeVisitor visitor : passes) {") + .containsOne("} catch (Exception e) {") + .containsOne("LOG.error(\"Class process exception: {}\", cls, e);") + .containsOne("} finally {") + .containsOne("cls.unload();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally4.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally4.java index 1c629f88f..468ee2fae 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally4.java @@ -7,11 +7,8 @@ import java.io.OutputStream; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatchFinally4 extends IntegrationTest { @@ -33,14 +30,13 @@ public class TestTryCatchFinally4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("File file = File.createTempFile(\"test\", \"txt\");")); - assertThat(code, containsOne("OutputStream outputStream = new FileOutputStream(file);")); - assertThat(code, containsOne("outputStream.write(1);")); - assertThat(code, containsOne("} finally {")); - assertThat(code, containsOne("outputStream.close();")); - assertThat(code, containsOne("} catch (IOException e) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("File file = File.createTempFile(\"test\", \"txt\");") + .containsOne("OutputStream outputStream = new FileOutputStream(file);") + .containsOne("outputStream.write(1);") + .containsOne("} finally {") + .containsOne("outputStream.close();") + .containsOne("} catch (IOException e) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally6.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally6.java index 8f3e127e5..3cd931c57 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally6.java @@ -6,12 +6,9 @@ import java.io.InputStream; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTryCatchFinally6 extends IntegrationTest { @@ -34,28 +31,27 @@ public class TestTryCatchFinally6 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsLines(2, - "InputStream is = null;", - "try {", - indent(1) + "call();", - indent(1) + "is = new FileInputStream(\"1.txt\");", - "} finally {", - indent(1) + "if (is != null) {", - indent(2) + "is.close();", - indent(1) + '}', - "}")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsLines(2, + "InputStream is = null;", + "try {", + indent(1) + "call();", + indent(1) + "is = new FileInputStream(\"1.txt\");", + "} finally {", + indent(1) + "if (is != null) {", + indent(2) + "is.close();", + indent(1) + '}', + "}"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (0 != 0) {"); - // impossible to proof that variables should be merged, so can't restore finally block here - assertThat(code, containsOne("if (0 != 0) {")); + // impossible to prove that variables should be merged, so can't restore finally block here } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally7.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally7.java index d49af08a8..afd6b4e93 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally7.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally7.java @@ -2,14 +2,11 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestTryCatchFinally7 extends IntegrationTest { @@ -37,8 +34,8 @@ public class TestTryCatchFinally7 extends IntegrationTest { public void check() { f = 0; - assertTrue(test(null)); - assertEquals(1, f); + assertThat(test(null)).isTrue(); + assertThat(f).isEqualTo(1); f = 0; try { @@ -46,28 +43,25 @@ public class TestTryCatchFinally7 extends IntegrationTest { } catch (AssertionError e) { // pass } - assertEquals(1, f); + assertThat(f).isEqualTo(1); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("try {")); - assertThat(code, containsString("exc(obj);")); - assertThat(code, containsString("} catch (Exception e) {")); - - assertThat(code, not(containsString("throw th;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("try {") + .contains("exc(obj);") + .contains("} catch (Exception e) {") + .doesNotContain("throw th;"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("throw th;"))); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("throw th;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally8.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally8.java index 3424583eb..f578ff163 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally8.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally8.java @@ -7,11 +7,8 @@ import java.io.IOException; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatchFinally8 extends IntegrationTest { @@ -45,22 +42,20 @@ public class TestTryCatchFinally8 extends IntegrationTest { @Test @NotYetImplemented("Fix merged catch blocks (shared code between catches)") public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("try {")); - assertThat(code, containsString("} catch (IOException e) {")); - assertThat(code, containsString("} finally {")); - assertThat(code, containsString("file.delete();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("try {") + .contains("} catch (IOException e) {") + .contains("} finally {") + .contains("file.delete();"); } @Test public void test2() { disableCompilation(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("output = new FileOutputStream(file);")); - assertThat(code, containsString("} catch (IOException e) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("output = new FileOutputStream(file);") + .contains("} catch (IOException e) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally9.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally9.java index 4e63a8e47..2d0699684 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally9.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchFinally9.java @@ -6,13 +6,8 @@ import java.util.Scanner; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryCatchFinally9 extends IntegrationTest { @@ -33,13 +28,12 @@ public class TestTryCatchFinally9 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("JADX INFO: finally extract failed"))); - assertThat(code, not(containsString(indent() + "throw "))); - assertThat(code, containsOne("} finally {")); - assertThat(code, containsOne("if (input != null) {")); - assertThat(code, containsOne("input.close();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("JADX INFO: finally extract failed") + .doesNotContain(indent() + "throw ") + .containsOne("} finally {") + .containsOne("if (input != null) {") + .containsOne("input.close();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchInIf.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchInIf.java index cb256b042..7bc1c046d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchInIf.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchInIf.java @@ -2,13 +2,10 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.assertj.core.api.Assertions.assertThat; public class TestTryCatchInIf extends IntegrationTest { @@ -34,20 +31,19 @@ public class TestTryCatchInIf extends IntegrationTest { } public void check() { - assertNull(test("n", null)); - assertEquals("n=7", test("n", "7")); - assertEquals("n=77", test("n", "0x" + Integer.toHexString(77))); - assertEquals("Failed to parse number", test("n", "abc")); - assertEquals("Failed to parse number", test("n", "0xabX")); + assertThat(test("n", null)).isNull(); + assertThat(test("n", "7")).isEqualTo("n=7"); + assertThat(test("n", "0x" + Integer.toHexString(77))).isEqualTo("n=77"); + assertThat(test("n", "abc")).isEqualTo("Failed to parse number"); + assertThat(test("n", "0xabX")).isEqualTo("Failed to parse number"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("} catch (NumberFormatException e) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {") + .containsOne("} catch (NumberFormatException e) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchMultiException.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchMultiException.java index 57febf7aa..e4da467c3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchMultiException.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchMultiException.java @@ -5,11 +5,9 @@ import java.time.DateTimeException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTryCatchMultiException extends IntegrationTest { @@ -26,11 +24,10 @@ public class TestTryCatchMultiException extends IntegrationTest { @Test public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - String catchExcVarName = "e"; - assertThat(code, containsOne("} catch (ProviderException | DateTimeException " + catchExcVarName + ") {")); - assertThat(code, containsOne("throw new RuntimeException(" + catchExcVarName + ");")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("} catch (ProviderException | DateTimeException " + catchExcVarName + ") {") + .containsOne("throw new RuntimeException(" + catchExcVarName + ");"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc.java index f1514c275..31c0611ef 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc.java @@ -2,11 +2,9 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTryCatchNoMoveExc extends SmaliTest { // @formatter:off @@ -24,11 +22,10 @@ public class TestTryCatchNoMoveExc extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPkg("trycatch", "TestTryCatchNoMoveExc"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (autoCloseable != null) {")); - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("autoCloseable.close();")); + assertThat(getClassNodeFromSmaliWithPkg("trycatch", "TestTryCatchNoMoveExc")) + .code() + .containsOne("if (autoCloseable != null) {") + .containsOne("try {") + .containsOne("autoCloseable.close();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc2.java index b6bb873d6..fb89995fe 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchNoMoveExc2.java @@ -2,12 +2,9 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsLines; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; /** * Issue: https://github.com/skylot/jadx/issues/395 @@ -29,13 +26,12 @@ public class TestTryCatchNoMoveExc2 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPkg("trycatch", "TestTryCatchNoMoveExc2"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsLines(2, - "} catch (Exception unused) {", - "}", - "System.nanoTime();")); + assertThat(getClassNodeFromSmaliWithPkg("trycatch", "TestTryCatchNoMoveExc2")) + .code() + .containsOne("try {") + .containsLines(2, + "} catch (Exception unused) {", + "}", + "System.nanoTime();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchStartOnMove.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchStartOnMove.java index 8fc5f953f..234eef74e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchStartOnMove.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryCatchStartOnMove.java @@ -2,11 +2,9 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTryCatchStartOnMove extends SmaliTest { // @formatter:off @@ -25,11 +23,10 @@ public class TestTryCatchStartOnMove extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPkg("trycatch", "TestTryCatchStartOnMove"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("} catch (Exception e) {")); - assertThat(code, containsOne("System.out.println(\"Failed call for \" + str")); + assertThat(getClassNodeFromSmaliWithPkg("trycatch", "TestTryCatchStartOnMove")) + .code() + .containsOne("try {") + .containsOne("} catch (Exception e) {") + .containsOne("System.out.println(\"Failed call for \" + str"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithEmptyCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithEmptyCatch.java index 59973cfaa..e429b1da5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithEmptyCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithEmptyCatch.java @@ -4,11 +4,8 @@ import java.util.Properties; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryWithEmptyCatch extends IntegrationTest { @@ -32,10 +29,9 @@ public class TestTryWithEmptyCatch extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try {")); - assertThat(code, containsOne("if (")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try {") + .containsOne("if ("); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithResources.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithResources.java index a259d8cc5..4931a4390 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithResources.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestTryWithResources.java @@ -8,13 +8,8 @@ import java.io.OutputStream; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTryWithResources extends SmaliTest { @@ -30,10 +25,9 @@ public class TestTryWithResources extends SmaliTest { @Test @NotYetImplemented public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("try (")); - assertThat(code, not(containsString("close()"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("try (") + .doesNotContain("close()"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch.java index 41c905982..95467821a 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch.java @@ -2,12 +2,9 @@ package jadx.tests.integration.trycatch; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; @SuppressWarnings("CommentedOutCode") public class TestUnreachableCatch extends SmaliTest { @@ -60,11 +57,9 @@ public class TestUnreachableCatch extends SmaliTest { public void test() { disableCompilation(); allowWarnInCode(); - - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsString("IOException")); - assertThat(code, containsString("Collections.unmodifiableMap")); + assertThat(getClassNodeFromSmali()) + .code() + .contains("IOException") + .contains("Collections.unmodifiableMap"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java index b6d7ae06d..f99ec9de3 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestUnreachableCatch2.java @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.hamcrest.MatcherAssert.assertThat; public class TestUnreachableCatch2 extends SmaliTest { diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestArrayTypes.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestArrayTypes.java index bf070ad79..ac69cddeb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestArrayTypes.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestArrayTypes.java @@ -2,11 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestArrayTypes extends IntegrationTest { @@ -28,18 +25,16 @@ public class TestArrayTypes extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("use(new Object[]{e});")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("use(new Object[]{e});"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("use(new Object[]{exc});")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("use(new Object[]{exc});"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestConstInline.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestConstInline.java index 9c09a9db9..0d7de64eb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestConstInline.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestConstInline.java @@ -2,11 +2,9 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestConstInline extends SmaliTest { // @formatter:off @@ -32,10 +30,9 @@ public class TestConstInline extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmaliWithPkg("types", "TestConstInline"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("list = null;")); - assertThat(code, containsOne("str = null;")); + assertThat(getClassNodeFromSmaliWithPkg("types", "TestConstInline")) + .code() + .containsOne("list = null;") + .containsOne("str = null;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestConstTypeInference.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestConstTypeInference.java index e146a9fe9..c47b373c5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestConstTypeInference.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestConstTypeInference.java @@ -2,14 +2,10 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anyOf; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class TestConstTypeInference extends IntegrationTest { @@ -40,21 +36,20 @@ public class TestConstTypeInference extends IntegrationTest { public void check() { TestCls seven = new TestCls(7); - assertEquals(seven, seven); - assertNotEquals(seven, null); + assertThat(seven).isEqualTo(seven); + assertThat(seven).isNotEqualTo(null); TestCls six = new TestCls(6); - assertNotEquals(seven, six); + assertThat(six).isNotEqualTo(seven); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("obj == this")); - assertThat(code, anyOf(containsOne("obj == null"), containsOne("obj != null"))); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("obj == this") + .containsOneOf("obj == null", "obj != null"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestFieldCast.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestFieldCast.java index 33c93fdcd..af3240859 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestFieldCast.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestFieldCast.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Issue #962 diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics.java index fe8a9f04b..960855daa 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics.java @@ -2,11 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics extends IntegrationTest { @@ -21,18 +18,16 @@ public class TestGenerics extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("TestCls data(T t) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("TestCls data(T t) {"); } @Test public void test2() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("TestCls data(T t) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("TestCls data(T t) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics2.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics2.java index f38168d15..599ea96b5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics2.java @@ -2,11 +2,9 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestGenerics2 extends SmaliTest { @@ -25,11 +23,10 @@ public class TestGenerics2 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("for (Map.Entry entry : map.entrySet()) {")); - assertThat(code, containsOne("useInt(entry.getKey().intValue());")); // no Integer cast - assertThat(code, containsOne("entry.getValue().trim();")); // no String cast + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("for (Map.Entry entry : map.entrySet()) {") + .containsOne("useInt(entry.getKey().intValue());") // no Integer cast + .containsOne("entry.getValue().trim();"); // no String cast } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics3.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics3.java index ea5be769e..8eb1a6c7b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics3.java @@ -6,11 +6,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics3 extends IntegrationTest { @@ -39,19 +36,17 @@ public class TestGenerics3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("List classes")); - assertThat(code, containsOne("for (String cls : classes) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("List classes") + .containsOne("for (String cls : classes) {"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("List classes")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("List classes"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics4.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics4.java index 35d5dd4fb..cd8ce9f02 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestGenerics4.java @@ -3,11 +3,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestGenerics4 extends IntegrationTest { @@ -40,21 +37,18 @@ public class TestGenerics4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("public static class ObjIList implements IList {")); - - assertThat(code, containsOne("Inner inner = new Inner<>();")); - assertThat(code, containsOne("inner.overload((IList) new ObjIList());")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("public static class ObjIList implements IList {") + .containsOne("Inner inner = new Inner<>();") + .containsOne("inner.overload((IList) new ObjIList());"); } @NotYetImplemented @Test public void testOmitCast() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("inner.overload(new ObjIList());")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("inner.overload(new ObjIList());"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestPrimitivesInIf.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestPrimitivesInIf.java index 20c86d1eb..4e61e9c1c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestPrimitivesInIf.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestPrimitivesInIf.java @@ -2,12 +2,9 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestPrimitivesInIf extends IntegrationTest { @@ -21,26 +18,24 @@ public class TestPrimitivesInIf extends IntegrationTest { } public void check() { - assertTrue(test("1")); + assertThat(test("1")).isTrue(); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("short sh = Short.parseShort(str);")); - assertThat(code, containsOne("int i = Integer.parseInt(str);")); - assertThat(code, containsOne("return sh == i;")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("short sh = Short.parseShort(str);") + .containsOne("int i = Integer.parseInt(str);") + .containsOne("return sh == i;"); } @Test public void test2() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("short parseShort = Short.parseShort(str);")); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("short parseShort = Short.parseShort(str);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeInheritance.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeInheritance.java index d1e6ffc76..a44594402 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeInheritance.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeInheritance.java @@ -2,11 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTypeInheritance extends IntegrationTest { @@ -48,13 +45,12 @@ public class TestTypeInheritance extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("IBase impl;")); - assertThat(code, containsOne("impl = new A();")); - assertThat(code, containsOne("B b = new B();")); - assertThat(code, containsOne("impl = b;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("IBase impl;") + .containsOne("impl = new A();") + .containsOne("B b = new B();") + .containsOne("impl = b;"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver.java index 39f0f0ae7..08f41d2e7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver.java @@ -2,12 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTypeResolver extends IntegrationTest { @@ -23,10 +19,9 @@ public class TestTypeResolver extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("this(b1, b2, 0, 0, 0);")); - assertThat(code, not(containsString("= this;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("this(b1, b2, 0, 0, 0);") + .doesNotContain("= this;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver10.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver10.java index 7a4510d20..4fb975063 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver10.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver10.java @@ -2,13 +2,9 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTypeResolver10 extends SmaliTest { @@ -18,10 +14,8 @@ public class TestTypeResolver10 extends SmaliTest { @Test public void test() { - ClassNode cls = getClassNodeFromSmali(); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("Object test(String str, String str2)")); - assertThat(code, not(containsString("Object obj2 = 0;"))); + assertThat(getClassNodeFromSmali()) + .code().containsOne("Object test(String str, String str2)") + .doesNotContain("Object obj2 = 0;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver2.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver2.java index 67716117d..62242e2e5 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver2.java @@ -4,11 +4,8 @@ import java.io.IOException; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTypeResolver2 extends IntegrationTest { @@ -26,9 +23,8 @@ public class TestTypeResolver2 extends IntegrationTest { public void test() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("if (obj != null) {")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("if (obj != null) {"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver4.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver4.java index feea8592d..17006428d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver4.java @@ -4,12 +4,10 @@ import java.util.Arrays; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTypeResolver4 extends IntegrationTest { @@ -32,16 +30,15 @@ public class TestTypeResolver4 extends IntegrationTest { public void check() { String test = test(("1234" + "utfstr\0\0" + "4567").getBytes(), 4); - assertThat(test, is("utfstr")); + assertThat(test).isEqualTo("utfstr"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("(strArray[end] != 0 || strArray[end + 1] != 0)")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("(strArray[end] != 0 || strArray[end + 1] != 0)"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver5.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver5.java index 12665a8fc..d4dede13f 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver5.java @@ -2,23 +2,18 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTypeResolver5 extends SmaliTest { @Test public void test() { disableCompilation(); - - ClassNode cls = getClassNodeFromSmaliWithPath("types", "TestTypeResolver5"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("Object string2"))); - assertThat(code, not(containsString("r1v2"))); + assertThat(getClassNodeFromSmali()) + .code() + .doesNotContain("Object string2") + .doesNotContain("r1v2"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6.java index 024a00266..417035d09 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6.java @@ -2,11 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTypeResolver6 extends IntegrationTest { @@ -24,10 +21,9 @@ public class TestTypeResolver6 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("this.obj = b ? this : makeObj();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("this.obj = b ? this : makeObj();"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6a.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6a.java index 84aec4f17..67f3608f8 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6a.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver6a.java @@ -2,11 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTypeResolver6a extends IntegrationTest { @@ -34,10 +31,9 @@ public class TestTypeResolver6a extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("this.runnable = b ? this : makeRunnable();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("this.runnable = b ? this : makeRunnable();"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver8.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver8.java index 021eca216..0a68d3fc7 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver8.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver8.java @@ -3,11 +3,9 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; import jadx.NotYetImplemented; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestTypeResolver8 extends SmaliTest { @@ -39,9 +37,8 @@ public class TestTypeResolver8 extends SmaliTest { @Test @NotYetImplemented public void test() { - ClassNode cls = getClassNodeFromSmaliFiles("types", "TestTypeResolver8", "TestCls"); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("use(a != null ? new B(a) : null);")); + assertThat(getClassNodeFromSmaliFiles("types", "TestTypeResolver8", "TestCls")) + .code() + .containsOne("use(a != null ? new B(a) : null);"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver9.java b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver9.java index 42eb1b326..00bdac8ae 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver9.java +++ b/jadx-core/src/test/java/jadx/tests/integration/types/TestTypeResolver9.java @@ -2,13 +2,8 @@ package jadx.tests.integration.types; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestTypeResolver9 extends IntegrationTest { @@ -24,11 +19,10 @@ public class TestTypeResolver9 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return 16777216 * b;")); - assertThat(code, not(containsString("Byte.MIN_VALUE"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return 16777216 * b;") + .doesNotContain("Byte.MIN_VALUE"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestDontInlineThis.java b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestDontInlineThis.java index 399702f4e..fdfa65bf0 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestDontInlineThis.java +++ b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestDontInlineThis.java @@ -4,11 +4,8 @@ import java.util.Random; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestDontInlineThis extends IntegrationTest { @@ -33,11 +30,10 @@ public class TestDontInlineThis extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("TestDontInlineThis$TestCls res")); - assertThat(code, containsOne("res = this;")); - assertThat(code, containsOne("res = new TestDontInlineThis$TestCls();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("TestDontInlineThis$TestCls res") + .containsOne("res = this;") + .containsOne("res = new TestDontInlineThis$TestCls();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis.java b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis.java index 60bd0119e..516ecc3ab 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis.java +++ b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis.java @@ -2,13 +2,8 @@ package jadx.tests.integration.usethis; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestInlineThis extends IntegrationTest { @@ -27,15 +22,13 @@ public class TestInlineThis extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("something"))); - assertThat(code, not(containsString("something.method()"))); - assertThat(code, not(containsString("something.field"))); - assertThat(code, not(containsString("= this"))); - - assertThat(code, containsOne("this.field = 123;")); - assertThat(code, containsOne("method();")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("something") + .doesNotContain("something.method()") + .doesNotContain("something.field") + .doesNotContain("= this") + .containsOne("this.field = 123;") + .containsOne("method();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis2.java b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis2.java index 5f3686558..64041e7eb 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestInlineThis2.java @@ -4,16 +4,13 @@ import java.util.Objects; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestInlineThis2 extends IntegrationTest { + @SuppressWarnings("ConstantValue") public static class TestCls { public int field; @@ -32,16 +29,14 @@ public class TestInlineThis2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("thisVar"))); - assertThat(code, not(containsString("thisVar.method()"))); - assertThat(code, not(containsString("thisVar.field"))); - assertThat(code, not(containsString("= this"))); - - assertThat(code, containsOne("if (Objects.isNull(this)) {")); - assertThat(code, containsOne("this.field = 123;")); - assertThat(code, containsOne("method();")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("thisVar") + .doesNotContain("thisVar.method()") + .doesNotContain("thisVar.field") + .doesNotContain("= this") + .containsOne("if (Objects.isNull(this)) {") + .containsOne("this.field = 123;") + .containsOne("method();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestRedundantThis.java b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestRedundantThis.java index 947e41d9c..b7f87857d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/usethis/TestRedundantThis.java +++ b/jadx-core/src/test/java/jadx/tests/integration/usethis/TestRedundantThis.java @@ -1,11 +1,8 @@ package jadx.tests.integration.usethis; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestRedundantThis extends IntegrationTest { @@ -29,12 +26,10 @@ public class TestRedundantThis extends IntegrationTest { // @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("this.f1();"))); - assertThat(code, not(containsString("return this.field1;"))); - - assertThat(code, containsString("this.field2 = field2;")); + assertThat(getClassNode(TestCls.class)) + .code() + .doesNotContain("this.f1();") + .doesNotContain("return this.field1;") + .contains("this.field2 = field2;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables2.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables2.java index c12fb8d5c..a85e89aff 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables2.java @@ -2,11 +2,8 @@ package jadx.tests.integration.variables; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestVariables2 extends IntegrationTest { @@ -23,18 +20,16 @@ public class TestVariables2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("Object store = s != null ? s : null;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("Object store = s != null ? s : null;"); } @Test public void testNoDebug() { noDebugInfo(); - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("Object obj2 = obj != null ? obj : null;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("Object obj2 = obj != null ? obj : null;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables3.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables3.java index b4884d724..37749018d 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables3.java @@ -2,11 +2,8 @@ package jadx.tests.integration.variables; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestVariables3 extends IntegrationTest { @@ -25,13 +22,12 @@ public class TestVariables3 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("int i;")); - assertThat(code, containsString("i = 2;")); - assertThat(code, containsString("i = 3;")); - assertThat(code, containsString("s = null;")); - assertThat(code, containsString("return s + \" \" + i;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("int i;") + .contains("i = 2;") + .contains("i = 3;") + .contains("s = null;") + .contains("return s + \" \" + i;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java index 6c37c09be..4958f1e62 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables4.java @@ -5,11 +5,8 @@ import java.lang.reflect.Method; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; @SuppressWarnings("checkstyle:printstacktrace") public class TestVariables4 extends IntegrationTest { @@ -59,14 +56,13 @@ public class TestVariables4 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsString("} catch (InvocationTargetException e) {")); - assertThat(code, containsString("pass = false;")); - assertThat(code, containsString("exc = e.getCause();")); - assertThat(code, containsString("System.err.println(\"Class '\" + clsName + \"' not found\");")); - assertThat(code, containsString("return pass;")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .contains("} catch (InvocationTargetException e) {") + .contains("pass = false;") + .contains("exc = e.getCause();") + .contains("System.err.println(\"Class '\" + clsName + \"' not found\");") + .contains("return pass;"); } @Test diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables5.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables5.java index 314db2816..26e03d709 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables5.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables5.java @@ -6,7 +6,6 @@ import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; public class TestVariables5 extends IntegrationTest { @@ -36,7 +35,7 @@ public class TestVariables5 extends IntegrationTest { public void check() { setEnabled(false); testIfInLoop(); - assertTrue(enabled); + assertThat(enabled).isTrue(); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables6.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables6.java index bb0ecd7c6..3fa0df385 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables6.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariables6.java @@ -2,25 +2,21 @@ package jadx.tests.integration.variables; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.SmaliTest; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestVariables6 extends SmaliTest { @Test public void test() { disableCompilation(); - ClassNode cls = getClassNodeFromSmaliWithPath("variables", "TestVariables6"); - String code = cls.getCode().toString(); - - assertThat(code, not(containsString("r4"))); - assertThat(code, not(containsString("r1v1"))); - assertThat(code, containsString("DateStringParser dateStringParser")); - assertThat(code, containsString("FinancialInstrumentMetadataAttribute startYear =" - + " this.mFinancialInstrumentMetadataDefinition.getStartYear();")); + assertThat(getClassNodeFromSmaliWithPath("variables", "TestVariables6")) + .code() + .doesNotContain("r4") + .doesNotContain("r1v1") + .contains("DateStringParser dateStringParser") + .contains("FinancialInstrumentMetadataAttribute startYear =" + + " this.mFinancialInstrumentMetadataDefinition.getStartYear();"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions.java index be4a7e701..78ee17246 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions.java @@ -10,10 +10,7 @@ import jadx.core.dex.visitors.DepthTraversal; import jadx.core.dex.visitors.IDexTreeVisitor; import jadx.tests.api.IntegrationTest; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestVariablesDefinitions extends IntegrationTest { @@ -36,11 +33,10 @@ public class TestVariablesDefinitions extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne(indent(3) + "for (IDexTreeVisitor pass : this.passes) {")); - assertThat(code, not(containsString("iterator;"))); - assertThat(code, not(containsString("Iterator"))); + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne(indent(3) + "for (IDexTreeVisitor pass : this.passes) {") + .doesNotContain("iterator;") + .doesNotContain("Iterator"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions2.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions2.java index edee0ceb7..ec3361a87 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesDefinitions2.java @@ -4,13 +4,8 @@ import java.util.List; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; - -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; +import jadx.tests.api.utils.assertj.JadxAssertions; public class TestVariablesDefinitions2 extends IntegrationTest { @@ -31,12 +26,11 @@ public class TestVariablesDefinitions2 extends IntegrationTest { @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("int i = 0;")); - assertThat(code, containsOne("i++;")); - assertThat(code, containsOne("return i;")); - assertThat(code, not(containsString("i2;"))); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("int i = 0;") + .containsOne("i++;") + .containsOne("return i;") + .doesNotContain("i2;"); } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesIfElseChain.java b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesIfElseChain.java index f2b0ec69b..9a6b1cf0c 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesIfElseChain.java +++ b/jadx-core/src/test/java/jadx/tests/integration/variables/TestVariablesIfElseChain.java @@ -2,12 +2,10 @@ package jadx.tests.integration.variables; import org.junit.jupiter.api.Test; -import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; +import jadx.tests.api.utils.assertj.JadxAssertions; -import static jadx.tests.api.utils.JadxMatchers.containsOne; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class TestVariablesIfElseChain extends IntegrationTest { @@ -43,21 +41,20 @@ public class TestVariablesIfElseChain extends IntegrationTest { public void check() { test(0); - assertThat(used, is("zero")); + assertThat(used).isEqualTo("zero"); test(1); - assertThat(used, is("hit1")); + assertThat(used).isEqualTo("hit1"); test(2); - assertThat(used, is("hit2")); - assertThat(test(5), is("miss")); + assertThat(used).isEqualTo("hit2"); + assertThat(test(5)).isEqualTo("miss"); } } @Test public void test() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - - assertThat(code, containsOne("return \"miss\";")); + JadxAssertions.assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("return \"miss\";"); // and compilable } } diff --git a/jadx-core/src/test/smali/inner/TestInnerClassSyntheticRename.smali b/jadx-core/src/test/smali/inner/TestInnerClassSyntheticRename.smali index 42974288c..b4ca39d2f 100644 --- a/jadx-core/src/test/smali/inner/TestInnerClassSyntheticRename.smali +++ b/jadx-core/src/test/smali/inner/TestInnerClassSyntheticRename.smali @@ -1,4 +1,4 @@ -.class Lcom/github/skylot/testasync/MyAsync; +.class Linner/TestInnerClassSyntheticRename; .super Landroid/os/AsyncTask; @@ -39,7 +39,7 @@ } .end annotation - const-string p1, "MyAsync" + const-string p1, "TestCls" const-string v0, "doInBackground" @@ -61,7 +61,7 @@ } .end annotation - const-string p1, "MyAsync" + const-string p1, "TestCls" const-string v0, "onPostExecute" @@ -75,7 +75,7 @@ check-cast p1, [Landroid/net/Uri; - invoke-virtual {p0, p1}, Lcom/github/skylot/testasync/MyAsync;->a([Landroid/net/Uri;)Ljava/util/List; + invoke-virtual {p0, p1}, Linner/TestInnerClassSyntheticRename;->a([Landroid/net/Uri;)Ljava/util/List; move-result-object p1 @@ -87,7 +87,7 @@ check-cast p1, Ljava/util/List; - invoke-virtual {p0, p1}, Lcom/github/skylot/testasync/MyAsync;->a(Ljava/util/List;)V + invoke-virtual {p0, p1}, Linner/TestInnerClassSyntheticRename;->a(Ljava/util/List;)V return-void .end method diff --git a/jadx-core/src/test/smali/names/TestReservedNames.smali b/jadx-core/src/test/smali/names/TestReservedNames.smali index 30bcbe08b..fa8286016 100644 --- a/jadx-core/src/test/smali/names/TestReservedNames.smali +++ b/jadx-core/src/test/smali/names/TestReservedNames.smali @@ -1,4 +1,4 @@ -.class public LTestReservedNames; +.class public Lnames/TestReservedNames; .super Ljava/lang/Object; .source "TestReservedNames.java" @@ -26,7 +26,7 @@ .prologue .line 8 - iget-object v0, p0, LTestReservedNames;->do:Ljava/lang/String; + iget-object v0, p0, Lnames/TestReservedNames;->do:Ljava/lang/String; return-object v0 .end method diff --git a/jadx-core/src/test/smali/types/TestTypeResolver5.smali b/jadx-core/src/test/smali/types/TestTypeResolver5.smali index 7d02817ec..ad0d14bf4 100644 --- a/jadx-core/src/test/smali/types/TestTypeResolver5.smali +++ b/jadx-core/src/test/smali/types/TestTypeResolver5.smali @@ -1,13 +1,10 @@ -.class public LTestTypeResolver5; +.class public Ltypes/TestTypeResolver5; .super Landroid/content/Context; .source "SourceFile" -# static fields .field public static final EXTERNAL_SOURCE:Ljava/lang/String; = "externalsource" - .field public static final IS_APPBOY_CAMPAIGN:Ljava/lang/String; = "appBoyCampaign" - .field public static final IS_NEWS_FEED:Ljava/lang/String; = "isNewsFeed" @@ -87,17 +84,17 @@ invoke-direct {v2, p0}, Landroid/webkit/WebView;->(Landroid/content/Context;)V .line 66 - invoke-direct {p0, v2, p1}, LTestTypeResolver5;->runJavaScriptForCampaign(Landroid/webkit/WebView;Landroid/os/Bundle;)V + invoke-direct {p0, v2, p1}, Ltypes/TestTypeResolver5;->runJavaScriptForCampaign(Landroid/webkit/WebView;Landroid/os/Bundle;)V .line 70 :cond_1 if-eqz v0, :cond_4 .line 72 - invoke-direct {p0, p1}, LTestTypeResolver5;->startHomeActivity(Landroid/os/Bundle;)V + invoke-direct {p0, p1}, Ltypes/TestTypeResolver5;->startHomeActivity(Landroid/os/Bundle;)V .line 73 - invoke-virtual {p0}, LTestTypeResolver5;->finish()V + invoke-virtual {p0}, Ltypes/TestTypeResolver5;->finish()V .line 80 :goto_2 @@ -119,7 +116,7 @@ .line 74 :cond_4 - invoke-virtual {p0}, LTestTypeResolver5;->isTaskRoot()Z + invoke-virtual {p0}, Ltypes/TestTypeResolver5;->isTaskRoot()Z move-result v0 @@ -129,13 +126,13 @@ .line 76 :cond_5 - invoke-direct {p0, p1}, LTestTypeResolver5;->openSplash(Landroid/os/Bundle;)V + invoke-direct {p0, p1}, Ltypes/TestTypeResolver5;->openSplash(Landroid/os/Bundle;)V goto :goto_2 .line 78 :cond_6 - invoke-virtual {p0}, LTestTypeResolver5;->finish()V + invoke-virtual {p0}, Ltypes/TestTypeResolver5;->finish()V goto :goto_2 .end method diff --git a/jadx-gui/src/test/java/jadx/gui/TestI18n.java b/jadx-gui/src/test/java/jadx/gui/TestI18n.java index 456114dd2..b394c6636 100644 --- a/jadx-gui/src/test/java/jadx/gui/TestI18n.java +++ b/jadx-gui/src/test/java/jadx/gui/TestI18n.java @@ -4,13 +4,12 @@ import java.io.IOException; import java.io.Reader; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Properties; import java.util.Set; +import java.util.stream.Stream; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -19,10 +18,10 @@ import org.junit.jupiter.api.Test; import jadx.gui.utils.LangLocale; import jadx.gui.utils.NLS; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static java.nio.file.Files.exists; +import static java.nio.file.Paths.get; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; public class TestI18n { @@ -34,10 +33,10 @@ public class TestI18n { @BeforeAll public static void init() { - i18nPath = Paths.get("src/main/resources/i18n"); - assertTrue(Files.exists(i18nPath)); - guiJavaPath = Paths.get("src/main/java"); - assertTrue(Files.exists(guiJavaPath)); + i18nPath = get("src/main/resources/i18n"); + assertThat(exists(i18nPath)).isTrue(); + guiJavaPath = get("src/main/java"); + assertThat(exists(guiJavaPath)).isTrue(); } @Test @@ -52,20 +51,22 @@ public class TestI18n { @Test public void filesExactlyMatch() throws IOException { - Files.list(i18nPath).forEach(p -> { - List lines; - try { - lines = Files.readAllLines(p); - if (reference == null) { - reference = lines; - referenceName = p.getFileName().toString(); - } else { - compareToReference(p); + try (Stream list = Files.list(i18nPath)) { + list.forEach(p -> { + List lines; + try { + lines = Files.readAllLines(p); + if (reference == null) { + reference = lines; + referenceName = p.getFileName().toString(); + } else { + compareToReference(p); + } + } catch (IOException e) { + Assertions.fail("Error " + e.getMessage()); } - } catch (IOException e) { - Assertions.fail("Error " + e.getMessage()); - } - }); + }); + } } private void compareToReference(Path path) throws IOException { @@ -99,27 +100,21 @@ public class TestI18n { try (Reader reader = Files.newBufferedReader(i18nPath.resolve("Messages_en_US.properties"))) { properties.load(reader); } - Set keys = new HashSet<>(); for (Object key : properties.keySet()) { keys.add("\"" + key + '"'); } - - Files.walk(guiJavaPath).filter(p -> Files.isRegularFile(p)).forEach(p -> { - try { - List lines = Files.readAllLines(p); - for (String line : lines) { - for (Iterator it = keys.iterator(); it.hasNext();) { - if (line.contains(it.next())) { - it.remove(); - } + try (Stream walk = Files.walk(guiJavaPath)) { + walk.filter(Files::isRegularFile).forEach(p -> { + try { + for (String line : Files.readAllLines(p)) { + keys.removeIf(line::contains); } + } catch (Exception e) { + throw new RuntimeException(e); } - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - - assertThat("keys not used", keys, empty()); + }); + } + assertThat(keys).as("keys not used").isEmpty(); } } diff --git a/jadx-gui/src/test/java/jadx/gui/utils/CertificateManagerTest.java b/jadx-gui/src/test/java/jadx/gui/utils/CertificateManagerTest.java index d622e1894..1ceb6d171 100644 --- a/jadx-gui/src/test/java/jadx/gui/utils/CertificateManagerTest.java +++ b/jadx-gui/src/test/java/jadx/gui/utils/CertificateManagerTest.java @@ -10,8 +10,7 @@ import java.util.Collection; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; public class CertificateManagerTest { private static final String CERTIFICATE_TEST_DIR = "certificate-test/"; @@ -45,78 +44,78 @@ public class CertificateManagerTest { public void decodeNotCertificateFile() throws IOException { try (InputStream in = new FileInputStream(emptyPath)) { String result = CertificateManager.decode(in); - assertEquals("", result); + assertThat(result).isEmpty(); } } @Test public void decodeRSAKeyHeader() { - String string = certificateManagerRSA.generateHeader(); - assertTrue(string.contains("X.509")); - assertTrue(string.contains("0x4bd68052")); - assertTrue(string.contains("CN=test cert, OU=test unit, O=OOO TestOrg, L=St.Peterburg, ST=Russia, C=123456")); + assertThat(certificateManagerRSA.generateHeader()) + .contains("X.509") + .contains("0x4bd68052") + .contains("CN=test cert, OU=test unit, O=OOO TestOrg, L=St.Peterburg, ST=Russia, C=123456"); } @Test public void decodeDSAKeyHeader() { - String string = certificateManagerDSA.generateHeader(); - assertTrue(string.contains("X.509")); - assertTrue(string.contains("0x16420ba2")); - assertTrue(string.contains("O=\"UJMRFVV CN=EDCVBGT C=TG\"")); + assertThat(certificateManagerDSA.generateHeader()) + .contains("X.509") + .contains("0x16420ba2") + .contains("O=\"UJMRFVV CN=EDCVBGT C=TG\""); } @Test public void decodeRSAKeySignature() { - String string = certificateManagerRSA.generateSignature(); - assertTrue(string.contains("SHA256withRSA")); - assertTrue(string.contains("1.2.840.113549.1.1.11")); + assertThat(certificateManagerRSA.generateSignature()) + .contains("SHA256withRSA") + .contains("1.2.840.113549.1.1.11"); } @Test public void decodeDSAKeySignature() { - String string = certificateManagerDSA.generateSignature(); - assertTrue(string.contains("SHA1withDSA")); - assertTrue(string.contains("1.2.840.10040.4.3")); + assertThat(certificateManagerDSA.generateSignature()) + .contains("SHA1withDSA") + .contains("1.2.840.10040.4.3"); } @Test public void decodeRSAFingerprint() { - String string = certificateManagerRSA.generateFingerprint(); - assertTrue(string.contains("61 18 0A 71 3F C9 55 16 4E 04 E3 C5 45 08 D9 11")); - assertTrue(string.contains("A0 6E A6 06 DB 2C 6F 3A 16 56 7F 75 97 7B AE 85 C2 13 09 37")); - assertTrue(string.contains("12 53 E8 BB C8 AA 27 A8 49 9B F8 0D 6E 68 CE 32 35 50 DE 55 A7 E7 8C 29 51 00 96 D7 56 F4 54 44")); + assertThat(certificateManagerRSA.generateFingerprint()) + .contains("61 18 0A 71 3F C9 55 16 4E 04 E3 C5 45 08 D9 11") + .contains("A0 6E A6 06 DB 2C 6F 3A 16 56 7F 75 97 7B AE 85 C2 13 09 37") + .contains("12 53 E8 BB C8 AA 27 A8 49 9B F8 0D 6E 68 CE 32 35 50 DE 55 A7 E7 8C 29 51 00 96 D7 56 F4 54 44"); } @Test public void decodeDSAFingerprint() { - String string = certificateManagerDSA.generateFingerprint(); - assertTrue(string.contains("D9 06 A6 2D 1F 79 8C 9D A6 EF 40 C7 2E C2 EA 0B")); - assertTrue(string.contains("18 E9 9C D4 A1 40 8F 63 FA EC 2E 62 A0 F2 AE B7 3F C3 C2 04")); - assertTrue(string.contains("74 F9 48 64 EE AC 92 26 53 2C 7A 0E 55 BE 5E D8 2F A7 D9 A9 99 F5 D5 21 2C 51 21 C4 31 AD 73 40")); + assertThat(certificateManagerDSA.generateFingerprint()) + .contains("D9 06 A6 2D 1F 79 8C 9D A6 EF 40 C7 2E C2 EA 0B") + .contains("18 E9 9C D4 A1 40 8F 63 FA EC 2E 62 A0 F2 AE B7 3F C3 C2 04") + .contains("74 F9 48 64 EE AC 92 26 53 2C 7A 0E 55 BE 5E D8 2F A7 D9 A9 99 F5 D5 21 2C 51 21 C4 31 AD 73 40"); } @Test public void decodeRSAPubKey() { - String string = certificateManagerRSA.generatePublicKey(); - assertTrue(string.contains("RSA")); - assertTrue(string.contains("65537")); - assertTrue(string.contains("1681953129031804462554643735709908030601939275292568895111488068832920121318010916" - + "889038430576806710152191447376363866950356097752126932858298006033288814768019331823126004318941179" - + "4465899645633586173494259691101582064441956032924396850221679489313043628562082670183392670094163371" - + "8586841184804093747497905514737738452134274762361473284344272721776230189352829291523087538543142199" - + "8761760403746876947208990209024335828599173964217021197086277312193991177728010193707324300633538463" - + "6193260583579409760790138329893534549366882523130765297472656435892831796545149793228897111760122091" - + "442123535919361963075454640516520743")); + assertThat(certificateManagerRSA.generatePublicKey()) + .contains("RSA") + .contains("65537") + .contains("1681953129031804462554643735709908030601939275292568895111488068832920121318010916" + + "889038430576806710152191447376363866950356097752126932858298006033288814768019331823126004318941179" + + "4465899645633586173494259691101582064441956032924396850221679489313043628562082670183392670094163371" + + "8586841184804093747497905514737738452134274762361473284344272721776230189352829291523087538543142199" + + "8761760403746876947208990209024335828599173964217021197086277312193991177728010193707324300633538463" + + "6193260583579409760790138329893534549366882523130765297472656435892831796545149793228897111760122091" + + "442123535919361963075454640516520743"); } @Test public void decodeDSAPubKey() { - String string = certificateManagerDSA.generatePublicKey(); - assertTrue(string.contains("DSA")); - assertTrue(string.contains("193233676050581546825633012823454532222793121048898990016982096262547255815113" - + "7546996381246109049596383861577383286736433045701055397423798599190480095839416942148507037843474" - + "67923797088055637932532829952742936211625049432875384559446523443782422268975073691469424116922209" - + "22477368782490423187845815262510366")); + assertThat(certificateManagerDSA.generatePublicKey()) + .contains("DSA") + .contains("193233676050581546825633012823454532222793121048898990016982096262547255815113" + + "7546996381246109049596383861577383286736433045701055397423798599190480095839416942148507037843474" + + "67923797088055637932532829952742936211625049432875384559446523443782422268975073691469424116922209" + + "22477368782490423187845815262510366"); } private String getResourcePath(String resName) { diff --git a/jadx-gui/src/test/java/jadx/gui/utils/JumpManagerTest.java b/jadx-gui/src/test/java/jadx/gui/utils/JumpManagerTest.java index 02b90806d..a6d741999 100644 --- a/jadx-gui/src/test/java/jadx/gui/utils/JumpManagerTest.java +++ b/jadx-gui/src/test/java/jadx/gui/utils/JumpManagerTest.java @@ -5,9 +5,7 @@ import org.junit.jupiter.api.Test; import jadx.gui.treemodel.TextNode; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.sameInstance; +import static org.assertj.core.api.Assertions.assertThat; class JumpManagerTest { private JumpManager jm; @@ -19,25 +17,25 @@ class JumpManagerTest { @Test public void testEmptyHistory() { - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), nullValue()); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isNull(); } @Test public void testEmptyHistory2() { - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), nullValue()); - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), nullValue()); - assertThat(jm.getPrev(), nullValue()); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isNull(); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isNull(); + assertThat(jm.getPrev()).isNull(); } @Test public void testOneElement() { jm.addPosition(makeJumpPos()); - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), nullValue()); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isNull(); } @Test @@ -47,10 +45,10 @@ class JumpManagerTest { JumpPosition pos2 = makeJumpPos(); jm.addPosition(pos2); - assertThat(jm.getPrev(), sameInstance(pos1)); - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), sameInstance(pos2)); - assertThat(jm.getNext(), nullValue()); + assertThat(jm.getPrev()).isSameAs(pos1); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isSameAs(pos2); + assertThat(jm.getNext()).isNull(); } @Test @@ -61,15 +59,15 @@ class JumpManagerTest { JumpPosition pos2 = makeJumpPos(); jm.addPosition(pos2); // 1 - 2@ - assertThat(jm.getPrev(), sameInstance(pos1)); + assertThat(jm.getPrev()).isSameAs(pos1); // 1@ - 2 JumpPosition pos3 = makeJumpPos(); jm.addPosition(pos3); // 1 - 3@ - assertThat(jm.getNext(), nullValue()); - assertThat(jm.getPrev(), sameInstance(pos1)); + assertThat(jm.getNext()).isNull(); + assertThat(jm.getPrev()).isSameAs(pos1); // 1@ - 3 - assertThat(jm.getNext(), sameInstance(pos3)); + assertThat(jm.getNext()).isSameAs(pos3); } @Test @@ -86,25 +84,25 @@ class JumpManagerTest { JumpPosition pos4 = makeJumpPos(); jm.addPosition(pos4); // 1 - 2 - 3 - 4@ - assertThat(jm.getPrev(), sameInstance(pos3)); + assertThat(jm.getPrev()).isSameAs(pos3); // 1 - 2 - 3@ - 4 - assertThat(jm.getPrev(), sameInstance(pos2)); + assertThat(jm.getPrev()).isSameAs(pos2); // 1 - 2@ - 3 - 4 JumpPosition pos5 = makeJumpPos(); jm.addPosition(pos5); // 1 - 2 - 5@ - assertThat(jm.getNext(), nullValue()); - assertThat(jm.getNext(), nullValue()); - assertThat(jm.getPrev(), sameInstance(pos2)); + assertThat(jm.getNext()).isNull(); + assertThat(jm.getNext()).isNull(); + assertThat(jm.getPrev()).isSameAs(pos2); // 1 - 2@ - 5 - assertThat(jm.getPrev(), sameInstance(pos1)); + assertThat(jm.getPrev()).isSameAs(pos1); // 1@ - 2 - 5 - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), sameInstance(pos2)); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isSameAs(pos2); // 1 - 2@ - 5 - assertThat(jm.getNext(), sameInstance(pos5)); + assertThat(jm.getNext()).isSameAs(pos5); // 1 - 2 - 5@ - assertThat(jm.getNext(), nullValue()); + assertThat(jm.getNext()).isNull(); } @Test @@ -113,8 +111,8 @@ class JumpManagerTest { jm.addPosition(pos); jm.addPosition(pos); - assertThat(jm.getPrev(), nullValue()); - assertThat(jm.getNext(), nullValue()); + assertThat(jm.getPrev()).isNull(); + assertThat(jm.getNext()).isNull(); } private JumpPosition makeJumpPos() { diff --git a/jadx-gui/src/test/java/jadx/gui/utils/pkgs/TestJRenamePackage.java b/jadx-gui/src/test/java/jadx/gui/utils/pkgs/TestJRenamePackage.java index 3442af1a2..b7c174309 100644 --- a/jadx-gui/src/test/java/jadx/gui/utils/pkgs/TestJRenamePackage.java +++ b/jadx-gui/src/test/java/jadx/gui/utils/pkgs/TestJRenamePackage.java @@ -23,12 +23,12 @@ class TestJRenamePackage { private void valid(String name) { assertThat(JRenamePackage.isValidPackageName(name)) .as("expect valid: %s", name) - .isEqualTo(true); + .isTrue(); } private void invalid(String name) { assertThat(JRenamePackage.isValidPackageName(name)) .as("expect invalid: %s", name) - .isEqualTo(false); + .isFalse(); } } diff --git a/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexAnnotationsConvert.java b/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexAnnotationsConvert.java index 733ee6202..d5a297916 100644 --- a/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexAnnotationsConvert.java +++ b/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexAnnotationsConvert.java @@ -67,7 +67,7 @@ public class DexAnnotationsConvert { attributes.add(new InnerClassesAttr(Collections.singletonMap(cls, innerClsInfo))); } } catch (Exception e) { - LOG.warn("Failed to parse annotation: " + annotation, e); + LOG.warn("Failed to parse annotation: {}", annotation, e); } break; @@ -109,7 +109,7 @@ public class DexAnnotationsConvert { attributes.add(new MethodParametersAttr(list)); } } catch (Exception e) { - LOG.warn("Failed to parse annotation: " + annotation, e); + LOG.warn("Failed to parse annotation: {}", annotation, e); } break; } diff --git a/jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaLoadResult.java b/jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaLoadResult.java index 537007774..695c6b82f 100644 --- a/jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaLoadResult.java +++ b/jadx-plugins/jadx-java-input/src/main/java/jadx/plugins/input/java/JavaLoadResult.java @@ -34,7 +34,7 @@ public class JavaLoadResult implements ICodeLoader { try { consumer.accept(reader.loadClassData()); } catch (Exception e) { - LOG.error("Failed to load class data for file: " + reader.getFileName(), e); + LOG.error("Failed to load class data for file: {}", reader.getFileName(), e); } } } diff --git a/jadx-plugins/jadx-java-input/src/test/java/jadx/plugins/input/java/CustomLoadTest.java b/jadx-plugins/jadx-java-input/src/test/java/jadx/plugins/input/java/CustomLoadTest.java index c457c538a..d731d8385 100644 --- a/jadx-plugins/jadx-java-input/src/test/java/jadx/plugins/input/java/CustomLoadTest.java +++ b/jadx-plugins/jadx-java-input/src/test/java/jadx/plugins/input/java/CustomLoadTest.java @@ -19,7 +19,7 @@ import jadx.api.JadxDecompiler; import jadx.api.plugins.input.ICodeLoader; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.fail; +import static org.assertj.core.api.Assertions.fail; class CustomLoadTest { @@ -98,7 +98,7 @@ class CustomLoadTest { .satisfiesOnlyOnce(cls -> assertThat(cls.getName()).isEqualTo("HelloWorld")) .satisfiesOnlyOnce(cls -> { assertThat(cls.getName()).isEqualTo("HelloInner"); - assertThat(cls.getCode()).isEqualTo(""); // no code for moved inner class + assertThat(cls.getCode()).isEmpty(); // no code for moved inner class }); assertThat(jadx.getClasses()) @@ -115,7 +115,7 @@ class CustomLoadTest { jadx.addCustomCodeLoader(codeLoader); jadx.load(); } catch (Exception e) { - fail(e); + fail("Failed to load sample", e); } } @@ -123,7 +123,7 @@ class CustomLoadTest { try { return Paths.get(ClassLoader.getSystemResource("samples/" + name).toURI()); } catch (Exception e) { - return fail(e); + return fail("Failed to load sample", e); } } }