Skip to content

Commit

Permalink
[BEANUTIL-547] Test case for reading java version in MethodUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Mar 13, 2021
1 parent 65d5c78 commit b399235
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
<!-- limit memory size see BEANUTILS-291
..also include ${argLine} from jacoco-maven-plugin
-->
<argLine>${surefire.argLine} ${argLine}</argLine>
<argLine>${surefire.argLine} ${argLine} -Djava.security.policy=${basedir}/src/test/resources/java.policy</argLine>
<includes>
<include>**/*TestCase.java</include>
</includes>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.beanutils2.secmgr;

import org.apache.commons.beanutils2.MethodUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class MethodUtilsTestCase {

@Before
public void setUp() {
System.setSecurityManager(new SecurityManager());
}

@After
public void tearDown() {
System.setSecurityManager(null);
}

@Test
public void testGetMatchingMethodsWithSecurityManager() {
Assert.assertNotNull(MethodUtils.getMatchingAccessibleMethod(MethodUtilsTestCase.class, "noopMethod", new Class[]{}));
}

public void noopMethod() {
// used in test for MethodUtils to read
}
}
20 changes: 20 additions & 0 deletions src/test/resources/java.policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

grant {
permission java.lang.RuntimePermission "setSecurityManager";
};

0 comments on commit b399235

Please sign in to comment.