-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
2 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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/mockito/internal/creation/bytebuddy/TypeSupport.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,42 @@ | ||
/* | ||
* Copyright (c) 2021 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.creation.bytebuddy; | ||
|
||
import org.mockito.exceptions.base.MockitoException; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
class TypeSupport { | ||
|
||
static final TypeSupport INSTANCE; | ||
|
||
static { | ||
Method isSealed; | ||
try { | ||
isSealed = Class.class.getMethod("isSealed"); | ||
} catch (NoSuchMethodException ignored) { | ||
isSealed = null; | ||
} | ||
INSTANCE = new TypeSupport(isSealed); | ||
} | ||
|
||
private final Method isSealed; | ||
|
||
private TypeSupport(Method isSealed) { | ||
this.isSealed = isSealed; | ||
} | ||
|
||
boolean isSealed(Class<?> type) { | ||
if (isSealed == null) { | ||
return false; | ||
} | ||
try { | ||
return (boolean) isSealed.invoke(type); | ||
} catch (Throwable t) { | ||
throw new MockitoException( | ||
"Failed to check if type is sealed using handle " + isSealed, t); | ||
} | ||
} | ||
} |
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