-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for switch and try resources
- Loading branch information
nbauma109
committed
Dec 13, 2022
1 parent
218d56e
commit 315cc3b
Showing
14 changed files
with
258 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package jd.core.test; | ||
/* | ||
* TODO FIXME No need to import java.io.PrintStream | ||
*/ | ||
public class LookupSwitch { | ||
|
||
void lookupSwitch(int inputValue) { | ||
switch (inputValue) { | ||
case 1: | ||
System.out.println("One"); | ||
break; | ||
case 1000: | ||
System.out.println("One thousand"); | ||
break; | ||
case 1000000: | ||
System.out.println("One million"); | ||
break; | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package jd.core.test; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Test; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class LookupSwitchTest extends AbstractTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
String internalClassName = "jd/core/test/LookupSwitch"; | ||
String output = decompile(internalClassName); | ||
assertEquals(IOUtils.toString(getClass().getResource("LookupSwitch.txt"), StandardCharsets.UTF_8), output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package jd.core.test; | ||
/* | ||
* TODO FIXME No need to import java.io.PrintStream | ||
*/ | ||
public class StringSwitch { | ||
|
||
void stringSwitch(String inputValue) { | ||
switch (inputValue) { | ||
case "1": | ||
System.out.println("One"); | ||
break; | ||
case "2": | ||
System.out.println("Two"); | ||
break; | ||
case "3": | ||
System.out.println("Three"); | ||
break; | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package jd.core.test; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.jd.core.v1.util.ZipLoader; | ||
import org.junit.Test; | ||
|
||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class StringSwitchTest extends AbstractTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
try (InputStream in = getClass().getResourceAsStream("/jdk7-features.jar")) { | ||
ZipLoader loader = new ZipLoader(in); | ||
String output = decompile("jd/core/test/StringSwitch", loader); | ||
assertEquals(IOUtils.toString(getClass().getResource("StringSwitch.txt"), StandardCharsets.UTF_8), output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package jd.core.test; | ||
/* | ||
* TODO FIXME No need to import java.io.PrintStream | ||
*/ | ||
public class TableSwitch { | ||
|
||
void tableSwitch(int inputValue) { | ||
switch (inputValue) { | ||
case 1: | ||
System.out.println("One"); | ||
break; | ||
case 2: | ||
System.out.println("Two"); | ||
break; | ||
case 3: | ||
System.out.println("Three"); | ||
break; | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package jd.core.test; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Test; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TableSwitchTest extends AbstractTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
String internalClassName = "jd/core/test/TableSwitch"; | ||
String output = decompile(internalClassName); | ||
assertEquals(IOUtils.toString(getClass().getResource("TableSwitch.txt"), StandardCharsets.UTF_8), output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package jd.core.test; | ||
|
||
import java.io.BufferedReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class TryResources { | ||
|
||
List<String> readFile(Path path) { | ||
List<String> lines = new ArrayList<>(); | ||
try (BufferedReader br = Files.newBufferedReader(path, StandardCharsets.UTF_8); | ||
Scanner sc = new Scanner(br)) { | ||
while (sc.hasNextLine()) { | ||
lines.add(sc.nextLine()); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return lines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package jd.core.test; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.jd.core.v1.util.ZipLoader; | ||
import org.junit.Test; | ||
|
||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TryResourcesTest extends AbstractTestCase { | ||
@Test | ||
public void test() throws Exception { | ||
try (InputStream in = getClass().getResourceAsStream("/jdk7-features.jar")) { | ||
ZipLoader loader = new ZipLoader(in); | ||
String output = decompile("jd/core/test/TryResources", loader); | ||
assertEquals(IOUtils.toString(getClass().getResource("TryResources.txt"), StandardCharsets.UTF_8), output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* */ package jd.core.test; | ||
/* */ | ||
/* */ import java.io.PrintStream; | ||
/* */ | ||
/* */ public class LookupSwitch | ||
/* */ { | ||
/* */ void lookupSwitch(int inputValue) { | ||
/* 8 */ switch (inputValue) { | ||
/* */ case 1: | ||
/* 10 */ System.out.println("One"); | ||
/* 11 */ break; | ||
/* */ case 1000: | ||
/* 13 */ System.out.println("One thousand"); | ||
/* 14 */ break; | ||
/* */ case 1000000: | ||
/* 16 */ System.out.println("One million"); | ||
/* 17 */ break; | ||
/* */ default: | ||
/* 19 */ throw new IllegalArgumentException(); | ||
/* */ } | ||
/* */ } | ||
/* */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* */ package jd.core.test; | ||
/* */ | ||
/* */ import java.io.PrintStream; | ||
/* */ | ||
/* */ public class StringSwitch | ||
/* */ { | ||
/* */ void stringSwitch(String inputValue) { | ||
/* 8 */ switch (inputValue) { | ||
/* */ case "1": | ||
/* 10 */ System.out.println("One"); | ||
/* 11 */ break; | ||
/* */ case "2": | ||
/* 13 */ System.out.println("Two"); | ||
/* 14 */ break; | ||
/* */ case "3": | ||
/* 16 */ System.out.println("Three"); | ||
/* 17 */ break; | ||
/* */ default: | ||
/* 19 */ throw new IllegalArgumentException(); | ||
/* */ } | ||
/* */ } | ||
/* */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* */ package jd.core.test; | ||
/* */ | ||
/* */ import java.io.PrintStream; | ||
/* */ | ||
/* */ public class TableSwitch | ||
/* */ { | ||
/* */ void tableSwitch(int inputValue) { | ||
/* 8 */ switch (inputValue) { | ||
/* */ case 1: | ||
/* 10 */ System.out.println("One"); | ||
/* 11 */ break; | ||
/* */ case 2: | ||
/* 13 */ System.out.println("Two"); | ||
/* 14 */ break; | ||
/* */ case 3: | ||
/* 16 */ System.out.println("Three"); | ||
/* 17 */ break; | ||
/* */ default: | ||
/* 19 */ throw new IllegalArgumentException(); | ||
/* */ } | ||
/* */ } | ||
/* */ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* */ package jd.core.test; | ||
/* */ | ||
/* */ import java.io.BufferedReader; | ||
/* */ import java.nio.file.Path; | ||
/* */ import java.util.ArrayList; | ||
/* */ import java.util.List; | ||
/* */ import java.util.Scanner; | ||
/* */ | ||
/* */ | ||
/* */ public class TryResources | ||
/* */ { | ||
/* */ List<String> readFile(Path path) | ||
/* */ { | ||
/* 14 */ List<String> lines = new ArrayList(); | ||
/* 15 */ try (BufferedReader br = java.nio.file.Files.newBufferedReader(path, java.nio.charset.StandardCharsets.UTF_8); | ||
/* 16 */ Scanner sc = new Scanner(br);) { | ||
/* 17 */ while (sc.hasNextLine()) { | ||
/* 18 */ lines.add(sc.nextLine()); | ||
/* */ } | ||
/* */ } catch (Exception e) { | ||
/* 21 */ e.printStackTrace(); | ||
/* */ } | ||
/* 23 */ return lines; | ||
/* */ } | ||
/* */ } |
Binary file not shown.