Skip to content

Commit b399235

Browse files
committed
[BEANUTIL-547] Test case for reading java version in MethodUtils
1 parent 65d5c78 commit b399235

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
<!-- limit memory size see BEANUTILS-291
369369
..also include ${argLine} from jacoco-maven-plugin
370370
-->
371-
<argLine>${surefire.argLine} ${argLine}</argLine>
371+
<argLine>${surefire.argLine} ${argLine} -Djava.security.policy=${basedir}/src/test/resources/java.policy</argLine>
372372
<includes>
373373
<include>**/*TestCase.java</include>
374374
</includes>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.commons.beanutils2.secmgr;
19+
20+
import org.apache.commons.beanutils2.MethodUtils;
21+
import org.junit.After;
22+
import org.junit.Assert;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
26+
public class MethodUtilsTestCase {
27+
28+
@Before
29+
public void setUp() {
30+
System.setSecurityManager(new SecurityManager());
31+
}
32+
33+
@After
34+
public void tearDown() {
35+
System.setSecurityManager(null);
36+
}
37+
38+
@Test
39+
public void testGetMatchingMethodsWithSecurityManager() {
40+
Assert.assertNotNull(MethodUtils.getMatchingAccessibleMethod(MethodUtilsTestCase.class, "noopMethod", new Class[]{}));
41+
}
42+
43+
public void noopMethod() {
44+
// used in test for MethodUtils to read
45+
}
46+
}

src/test/resources/java.policy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
grant {
19+
permission java.lang.RuntimePermission "setSecurityManager";
20+
};

0 commit comments

Comments
 (0)