Skip to content

Commit

Permalink
Add unit tests for GH-14 and GH-8
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed May 8, 2020
1 parent 70e6751 commit 0dab04a
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/org/cadixdev/mercury/test/RemappingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@

class RemappingTests {

// Mercury contains the following tests:
// 1. Simple remaps
// This test is used to verify that Mercury can remap simple things:
// - Mercury can remap simple classes, fields, and methods
// - Mercury will remove package declarations when remapping to the
// root package (GH-11)
// 2. Method overriding and generics
// This test is used to verify that Mercury can handle child classes
// overriding methods from their parents:
// - Mercury will remap methods with their return type raised (GH-14)
// - Mercury can handle generic return types, and parameters (GH-8).

@Test
void remap() throws Exception {
final Path tempDir = Files.createTempDirectory("mercury-test");
Expand All @@ -41,7 +53,11 @@ void remap() throws Exception {
Files.createDirectories(out);

// Copy our test classes to the virtual file system
// - Test 1
this.copy(in, "test/ObfClass.java");
// - Test 2
this.copy(in, "OverrideChild.java");
this.copy(in, "OverrideParent.java");

// Load our test mappings
final MappingSet mappings = MappingSet.create();
Expand All @@ -56,7 +72,11 @@ void remap() throws Exception {
mercury.rewrite(in, out);

// Check that the output is as expected
// - Test 1
this.verify(out, "Core.java");
// - Test 2
this.verify(out, "OverrideChild.java");
this.verify(out, "OverrideParent.java");

// Delete the directory
Files.walk(tempDir)
Expand Down
27 changes: 27 additions & 0 deletions src/test/resources/a/OverrideChild.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2018 Minecrell (https://github.com/Minecrell)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

class OverrideChild extends OverrideParent<String> {

@Override
public String abc() {
return "Hello, World!";
}

@Override
public String bcd() {
return "Hello, World!";
}

@Override
public void cde(final String abc) {
}

}
24 changes: 24 additions & 0 deletions src/test/resources/a/OverrideParent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2018 Minecrell (https://github.com/Minecrell)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

class OverrideParent<T> {

public Object abc() {
return null;
}

public T bcd() {
return null;
}

public void cde(final T abc) {
}

}
27 changes: 27 additions & 0 deletions src/test/resources/b/OverrideChild.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2018 Minecrell (https://github.com/Minecrell)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

class OverrideChild extends OverrideParent<String> {

@Override
public String get() {
return "Hello, World!";
}

@Override
public String fetch() {
return "Hello, World!";
}

@Override
public void set(final String abc) {
}

}
24 changes: 24 additions & 0 deletions src/test/resources/b/OverrideParent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2018 Minecrell (https://github.com/Minecrell)
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

class OverrideParent {

public Object get() {
return null;
}

public T fetch() {
return null;
}

public void set(final T abc) {
}

}
7 changes: 7 additions & 0 deletions src/test/resources/test.tsrg
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Test 1. Simple remaps
test/ObfClass Core
name firstName
name ()Ljava/lang/String; firstName

# Test 2. Remap overrides
OverrideParent OverrideParent
abc ()Ljava/lang/Object; get
bcd ()Ljava/lang/Object; fetch
cde (Ljava/lang/Object;)V set

0 comments on commit 0dab04a

Please sign in to comment.