-
-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test rule and property for better handling JNA if not available o…
…r in need of custom extension.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
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
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
46 changes: 46 additions & 0 deletions
46
byte-buddy-agent/src/test/java/net/bytebuddy/test/utility/JnaRule.java
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,46 @@ | ||
package net.bytebuddy.test.utility; | ||
|
||
import com.sun.jna.Library; | ||
import com.sun.jna.Native; | ||
import com.sun.jna.Platform; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
import java.util.logging.Logger; | ||
|
||
public class JnaRule implements TestRule { | ||
|
||
private final boolean available; | ||
|
||
@SuppressWarnings("deprecation") | ||
public JnaRule() { | ||
boolean available; | ||
try { | ||
Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class); | ||
available = true; | ||
} catch (Throwable ignored) { | ||
available = false; | ||
} | ||
this.available = available; | ||
} | ||
|
||
public Statement apply(Statement base, Description description) { | ||
return available | ||
? base | ||
: new NoOpStatement(); | ||
} | ||
|
||
private static class NoOpStatement extends Statement { | ||
|
||
public void evaluate() { | ||
Logger.getLogger("net.bytebuddy").info("Omitting test case: JNA not available"); | ||
} | ||
} | ||
|
||
public interface CLibrary extends Library { | ||
|
||
@SuppressWarnings("unused") | ||
void printf(String format, Object... args); | ||
} | ||
} |