refactor(tests): migrate from Hamcrest to AssertJ

This commit is contained in:
Skylot
2024-08-11 21:52:56 +01:00
parent a2bfe9bbe8
commit 1051dacb1e
354 changed files with 2620 additions and 4058 deletions
@@ -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")
@@ -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<String, String> 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;
}
@@ -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<RenameEnum> 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<RenameEnum> 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");
}
}
@@ -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 {
@@ -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();
@@ -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);
}
}
}
@@ -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() {
@@ -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);
}
@@ -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");
}
}
@@ -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);
}
}
@@ -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<K, V>$Entry<K, V>"));
assertTrue(genericInner.containsTypeVariable());
assertThat(genericInner.toString()).isEqualTo("java.util.Map<K, V>$Entry<K, V>");
assertThat(genericInner.containsTypeVariable()).isTrue();
ArgType genericInner2 = ArgType.outerGeneric(base, ArgType.object("Entry"));
assertThat(genericInner2.toString(), is("java.util.Map<K, V>$Entry"));
assertTrue(genericInner2.containsTypeVariable());
assertThat(genericInner2.toString()).isEqualTo("java.util.Map<K, V>$Entry");
assertThat(genericInner2.containsTypeVariable()).isTrue();
}
}
@@ -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;
@@ -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 {
@@ -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 {
@@ -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<ArgType> 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);
}
}
@@ -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 {
@@ -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<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <attr name=\"size\" format=\"dimension\">\n"
+ " </attr>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -56,15 +56,15 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <attr name=\"size\">\n"
+ " <enum name=\"android:string.aerr_wait\" value=\"1\" />\n"
+ " </attr>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -79,15 +79,15 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <attr name=\"size\">\n"
+ " <flag name=\"android:string.aerr_wait\" value=\"1\" />\n"
+ " </attr>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -102,14 +102,14 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <attr name=\"size\" format=\"integer\" min=\"1\">\n"
+ " </attr>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -127,17 +127,17 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <style name=\"JadxGui\" parent=\"\">\n"
+ " <item name=\"android:windowBackground\">@android:color/transparent</item>\n"
+ " </style>\n"
+ " <style name=\"JadxGui.Dialog\" parent=\"@style/JadxGui\">\n"
+ " </style>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -154,13 +154,13 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <string name=\"app_name\">Jadx Decompiler App</string>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -177,13 +177,13 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <string name=\"app_name\" formatted=\"false\">%s at %s</string>\n"
+ "</resources>", input);
+ "</resources>");
}
@Test
@@ -200,14 +200,14 @@ class ResXmlGenTest {
ResXmlGen resXmlGen = new ResXmlGen(resStorage, vp);
List<ResContainer> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
assertThat(input).isEqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<resources>\n"
+ " <array name=\"single_quote_escape_sample\">\n"
+ " <item>Let\\'s go</item>\n"
+ " </array>\n"
+ "</resources>", input);
+ "</resources>");
}
}
@@ -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 {
@@ -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;
@@ -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<File> 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<ClassNode> getClassNodes(Class<?>... classes) {
try {
assertThat("Class list is empty", classes, not(emptyArray()));
assertThat(classes).as("Class list is empty").isNotEmpty();
List<File> srcFiles = Stream.of(classes).map(this::getSourceFileForClass).collect(Collectors.toList());
List<File> 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[] {});
}
@@ -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());
@@ -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());
@@ -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);
@@ -1,34 +0,0 @@
package jadx.tests.api.utils;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
public class CountString extends TypeSafeMatcher<String> {
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);
}
}
@@ -1,35 +0,0 @@
package jadx.tests.api.utils;
import org.hamcrest.Matcher;
public class JadxMatchers {
public static Matcher<String> countString(int count, String substring) {
return new CountString(count, substring);
}
public static Matcher<String> containsOne(String substring) {
return countString(1, substring);
}
public static Matcher<String> containsLines(String... lines) {
StringBuilder sb = new StringBuilder();
for (String line : lines) {
sb.append(line).append('\n');
}
return countString(1, sb.toString());
}
public static Matcher<String> 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());
}
}
@@ -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) {
@@ -18,7 +18,6 @@ public class JadxAssertions extends Assertions {
}
public static JadxCodeAssertions assertThat(String code) {
Assertions.assertThat(code).isNotNull();
return new JadxCodeAssertions(code);
}
}
@@ -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<JadxClassNodeAssertions, ClassNode> {
@@ -21,14 +20,14 @@ public class JadxClassNodeAssertions extends AbstractObjectAssert<JadxClassNodeA
public JadxCodeInfoAssertions decompile() {
isNotNull();
ICodeInfo codeInfo = actual.getCode();
Assertions.assertThat(codeInfo).isNotNull();
assertThat(codeInfo).isNotNull();
return new JadxCodeInfoAssertions(codeInfo);
}
public JadxCodeAssertions code() {
isNotNull();
ICodeInfo code = actual.getCode();
Assertions.assertThat(code).isNotNull();
assertThat(code).isNotNull();
String codeStr = code.getCodeStr();
assertThat(codeStr).isNotBlank();
return new JadxCodeAssertions(codeStr);
@@ -44,9 +43,9 @@ public class JadxClassNodeAssertions extends AbstractObjectAssert<JadxClassNodeA
public JadxCodeAssertions reloadCode(IntegrationTest testInstance) {
isNotNull();
ICodeInfo code = actual.reloadCode();
Assertions.assertThat(code).isNotNull();
assertThat(code).isNotNull();
String codeStr = code.getCodeStr();
Assertions.assertThat(codeStr).isNotBlank();
assertThat(codeStr).isNotBlank();
JadxCodeAssertions codeAssertions = new JadxCodeAssertions(codeStr);
codeAssertions.print();
@@ -76,7 +75,7 @@ public class JadxClassNodeAssertions extends AbstractObjectAssert<JadxClassNodeA
int refPos = codePos + refOffset;
for (Map.Entry<Integer, ICodeAnnotation> entry : code.getCodeMetadata().getAsMap().entrySet()) {
if (entry.getKey() == refPos) {
Assertions.assertThat(entry.getValue()).isEqualTo(node);
assertThat(entry.getValue()).isEqualTo(node);
return this;
}
}
@@ -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);
}
}
@@ -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<TestAttr> 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);
}
}
@@ -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();
}
}
@@ -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<String> check(List<IDexTreeVisitor> passes) {
@@ -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();
}
}
}
@@ -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<TV;>.LinkedHashIterator<Lb$c<Ls;TV;>;>;";
String objectStr = new SignatureParser(signature).consumeType().getObject();
assertThat(objectStr, is("a$LinkedHashIterator"));
assertThat(objectStr).isEqualTo("a$LinkedHashIterator");
}
@Test
public void testNestedInnerGeneric() {
String signature = "La<TV;>.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<Lsome/pkg/s;>.some/long/pkg/bb<Lsome/pkg/p;Lsome/pkg/n;>;";
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<ArgType> list = (List<ArgType>) objs[i + 1];
expectedList.add(ArgType.genericType(typeVar, list));
}
assertThat(genericsList, is(expectedList));
assertThat(genericsList).isEqualTo(expectedList);
}
@Test
public void testMethodArgs() {
List<ArgType> 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<ArgType> argTypes = new SignatureParser("(La/b/C<TT;>.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
@@ -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);
}
}
@@ -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\"");
}
}
@@ -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);
}
}
@@ -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;");
}
}
@@ -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<ClassNode> 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);
}
}
@@ -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;");
}
}
@@ -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;");
}
}
@@ -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();");
}
}
@@ -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();");
}
}
@@ -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)");
}
}
@@ -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)");
}
}
@@ -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) {");
}
}
@@ -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++;");
}
}
@@ -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;");
}
}
@@ -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 (");
}
}
@@ -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;");
}
}
@@ -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("^");
}
}
@@ -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 + '_';");
}
}
@@ -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;");
}
}
@@ -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;");
}
}
@@ -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");
}
}
@@ -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\"};");
}
}
@@ -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};");
}
}
@@ -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}");
}
}
@@ -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};");
}
}
@@ -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];");
}
}
@@ -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}");
}
}
@@ -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};");
}
}
@@ -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);");
}
}
@@ -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;");
}
}
@@ -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});");
}
}
@@ -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);
}
}
@@ -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) {");
}
}
@@ -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) {");
}
}
@@ -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);");
}
}
@@ -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;");
}
}
@@ -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;");
}
}
@@ -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\")) {");
}
}
@@ -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)) {");
}
}
@@ -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");
}
}
@@ -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;");
}
}
@@ -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\");");
}
}
@@ -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");
}
}
@@ -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");
}
}
@@ -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");
}
}
@@ -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);");
}
}
@@ -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)");
}
}
@@ -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;");
}
}
@@ -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(" & ");
}
}
@@ -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));");
}
}
@@ -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)");
}
}
@@ -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");
}
}
@@ -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)) {");
}
}
@@ -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");
}
}
@@ -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("||");
}
}
@@ -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();");
}
}
@@ -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;");
}
}
@@ -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
}
}
@@ -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\");");
}
}
@@ -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;");
}
}
@@ -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");
}
}
@@ -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];");
}
}
@@ -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;");
}
}
@@ -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);");
}
}
@@ -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)) {");
}
}
@@ -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

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