You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/24 15:39:58 UTC
[commons-bcel] 01/02: Reuse Uncheck
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
commit f5fc126df48c43dcc3390e973aaee3e0a831fdf2
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sat Jun 24 11:34:59 2023 -0400
Reuse Uncheck
Javadoc
---
src/test/java/org/apache/bcel/AbstractTestCase.java | 15 +++++++--------
src/test/java/org/apache/bcel/generic/JavaHome.java | 14 ++------------
2 files changed, 9 insertions(+), 20 deletions(-)
diff --git a/src/test/java/org/apache/bcel/AbstractTestCase.java b/src/test/java/org/apache/bcel/AbstractTestCase.java
index e4e03b9c..2d7d9de1 100644
--- a/src/test/java/org/apache/bcel/AbstractTestCase.java
+++ b/src/test/java/org/apache/bcel/AbstractTestCase.java
@@ -20,8 +20,6 @@ package org.apache.bcel;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
-import java.io.IOException;
-import java.io.UncheckedIOException;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
@@ -41,6 +39,7 @@ import org.apache.bcel.generic.SimpleElementValueGen;
import org.apache.bcel.util.ClassPath;
import org.apache.bcel.util.SyntheticRepository;
import org.apache.bcel.verifier.VerifierFactory;
+import org.apache.commons.io.function.Uncheck;
public abstract class AbstractTestCase {
@@ -70,11 +69,11 @@ public abstract class AbstractTestCase {
}
public SyntheticRepository createRepos(final String cpentry) {
- try (ClassPath cp = new ClassPath("target" + File.separator + "testdata" + File.separator + cpentry + File.separator)) {
- return SyntheticRepository.getInstance(cp);
- } catch (final IOException e) {
- throw new UncheckedIOException(e);
- }
+ return Uncheck.get(() -> {
+ try (ClassPath cp = new ClassPath("target" + File.separator + "testdata" + File.separator + cpentry + File.separator)) {
+ return SyntheticRepository.getInstance(cp);
+ }
+ });
}
/**
@@ -89,7 +88,7 @@ public abstract class AbstractTestCase {
* Deletes a file under the TESTDATA directory
*
* @param name
- * @return
+ * @return See {@link File#delete()}.
*/
protected boolean delete(final String name) {
return new File(TESTDATA, name).delete();
diff --git a/src/test/java/org/apache/bcel/generic/JavaHome.java b/src/test/java/org/apache/bcel/generic/JavaHome.java
index 7b00a6cc..e4d04d45 100644
--- a/src/test/java/org/apache/bcel/generic/JavaHome.java
+++ b/src/test/java/org/apache/bcel/generic/JavaHome.java
@@ -20,8 +20,6 @@ package org.apache.bcel.generic;
import static com.sun.jna.platform.win32.WinReg.HKEY_LOCAL_MACHINE;
import java.io.File;
-import java.io.IOException;
-import java.io.UncheckedIOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -215,11 +213,7 @@ public class JavaHome {
}
ModularRuntimeImage getModularRuntimeImage() {
- try {
- return new ModularRuntimeImage(path.toString());
- } catch (final IOException e) {
- throw new UncheckedIOException(e);
- }
+ return Uncheck.get(() -> new ModularRuntimeImage(path.toString()));
}
Path getPath() {
@@ -255,11 +249,7 @@ public class JavaHome {
}
private JarFile toJarFile(final Path path) {
- try {
- return new JarFile(path.toFile());
- } catch (final IOException e) {
- throw new UncheckedIOException(e);
- }
+ return Uncheck.get(() -> new JarFile(path.toFile()));
}
@Override