Skip to content

Commit

Permalink
added tests for switch and try resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauma109 committed Dec 13, 2022
1 parent 218d56e commit 315cc3b
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/jd/core/test/LookupSwitch.java
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();
}
}
}
17 changes: 17 additions & 0 deletions src/test/java/jd/core/test/LookupSwitchTest.java
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);
}
}
22 changes: 22 additions & 0 deletions src/test/java/jd/core/test/StringSwitch.java
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();
}
}
}
21 changes: 21 additions & 0 deletions src/test/java/jd/core/test/StringSwitchTest.java
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);
}
}
}
22 changes: 22 additions & 0 deletions src/test/java/jd/core/test/TableSwitch.java
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();
}
}
}
17 changes: 17 additions & 0 deletions src/test/java/jd/core/test/TableSwitchTest.java
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);
}
}
25 changes: 25 additions & 0 deletions src/test/java/jd/core/test/TryResources.java
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;
}
}
21 changes: 21 additions & 0 deletions src/test/java/jd/core/test/TryResourcesTest.java
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);
}
}
}
22 changes: 22 additions & 0 deletions src/test/resources/jd/core/test/LookupSwitch.txt
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();
/* */ }
/* */ }
/* */ }
22 changes: 22 additions & 0 deletions src/test/resources/jd/core/test/StringSwitch.txt
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();
/* */ }
/* */ }
/* */ }
22 changes: 22 additions & 0 deletions src/test/resources/jd/core/test/TableSwitch.txt
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();
/* */ }
/* */ }
/* */ }
25 changes: 25 additions & 0 deletions src/test/resources/jd/core/test/TryResources.txt
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 added src/test/resources/jdk7-features.jar
Binary file not shown.

0 comments on commit 315cc3b

Please sign in to comment.