Skip to content

Commit

Permalink
fix: add exception for mocked classes with security manager - EXO-65023
Browse files Browse the repository at this point in the history
… - Meeds-io/meeds#1084

Before this fix, mocked classes does not pass the rules of security managers and thrown exceptions that cause the failing of unit tests
This fix adds Nullity checks and adds the pattern of mocked classes to identify mocked instances.
  • Loading branch information
sofyenne authored Sep 14, 2023
1 parent af4754e commit 2cf5fde
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ public void checkPermission(Permission perm)
String className = traceElements[i].getClassName();
String fileName = traceElements[i].getFileName();
String methodName = traceElements[i].getMethodName();
if (i - 1 >= 0 && excludes.containsKey(className + "." + methodName)
&& excludes.get(className + "." + methodName).contains(traceElements[i - 1].getMethodName()))
if (className.contains("$MockitoMock$") || (i - 1 >= 0 && excludes.containsKey(className + "." + methodName)
&& excludes.get(className + "." + methodName).contains(traceElements[i - 1].getMethodName())))
{
// the called method is excluded thus we ignore the exception
return;
}
if (className.startsWith("org.exoplatform"))
{
// known tests classes
if (fileName.startsWith("Test") || fileName.endsWith("Test.java")
if (fileName != null && (fileName.startsWith("Test") || fileName.endsWith("Test.java")
|| fileName.endsWith("TestBase.java") || fileName.endsWith("TestCase.java")
|| fileName.equals("Probe.java") || fileName.equals("ExportBase.java")
|| fileName.equals("AbstractTestContainer.java") || fileName.equals("ContainerBuilder.java")
|| fileName.equals("WorkspaceStorageCacheBaseCase.java")
|| fileName.equals("ExoRepositoryStub.java") || fileName.equals("CloseableDataSource.java"))
|| fileName.equals("ExoRepositoryStub.java") || fileName.equals("CloseableDataSource.java")))
{
testCode = true;
}
Expand Down

0 comments on commit 2cf5fde

Please sign in to comment.