2222import junit .framework .TestCase ;
2323
2424import java .lang .reflect .Member ;
25- import java .util .Arrays ;
2625import java .util .Collections ;
2726import java .util .HashMap ;
2827import java .util .HashSet ;
@@ -62,7 +61,7 @@ public void testClassExclusion() throws Exception {
6261 String propertyName = "stringField" ;
6362 Member member = FooBar .class .getDeclaredMethod ("get" + propertyName .substring (0 , 1 ).toUpperCase () + propertyName .substring (1 ));
6463
65- Set <Class <?>> excluded = new HashSet <Class <?> >();
64+ Set <Class <?>> excluded = new HashSet <>();
6665 excluded .add (FooBar .class );
6766 sma .setExcludedClasses (excluded );
6867
@@ -108,7 +107,7 @@ public void testInterfaceInheritanceExclusion() throws Exception {
108107 String propertyName = "barLogic" ;
109108 Member member = BarInterface .class .getMethod (propertyName );
110109
111- Set <Class <?>> excluded = new HashSet <Class <?> >();
110+ Set <Class <?>> excluded = new HashSet <>();
112111 excluded .add (BarInterface .class );
113112 sma .setExcludedClasses (excluded );
114113
@@ -126,7 +125,7 @@ public void testMiddleOfInheritanceExclusion1() throws Exception {
126125 String propertyName = "fooLogic" ;
127126 Member member = FooBar .class .getMethod (propertyName );
128127
129- Set <Class <?>> excluded = new HashSet <Class <?> >();
128+ Set <Class <?>> excluded = new HashSet <>();
130129 excluded .add (BarInterface .class );
131130 sma .setExcludedClasses (excluded );
132131
@@ -158,7 +157,7 @@ public void testMiddleOfInheritanceExclusion4() throws Exception {
158157 String propertyName = "barLogic" ;
159158 Member member = BarInterface .class .getMethod (propertyName );
160159
161- Set <Class <?>> excluded = new HashSet <Class <?> >();
160+ Set <Class <?>> excluded = new HashSet <>();
162161 excluded .add (FooBarInterface .class );
163162 sma .setExcludedClasses (excluded );
164163
@@ -173,7 +172,7 @@ public void testPackageExclusion() throws Exception {
173172 // given
174173 SecurityMemberAccess sma = new SecurityMemberAccess (false );
175174
176- Set <Pattern > excluded = new HashSet <Pattern >();
175+ Set <Pattern > excluded = new HashSet <>();
177176 excluded .add (Pattern .compile ("^" + FooBar .class .getPackage ().getName ().replaceAll ("\\ ." , "\\ \\ ." ) + ".*" ));
178177 sma .setExcludedPackageNamePatterns (excluded );
179178
@@ -191,7 +190,7 @@ public void testPackageNameExclusion() throws Exception {
191190 // given
192191 SecurityMemberAccess sma = new SecurityMemberAccess (false );
193192
194- Set <String > excluded = new HashSet <String >();
193+ Set <String > excluded = new HashSet <>();
195194 excluded .add (FooBar .class .getPackage ().getName ());
196195 sma .setExcludedPackageNames (excluded );
197196
@@ -205,11 +204,11 @@ public void testPackageNameExclusion() throws Exception {
205204 assertFalse ("stringField is accessible!" , actual );
206205 }
207206
208- public void testDefaultPackageExclusion () throws Exception {
207+ public void testDefaultPackageExclusion () {
209208 // given
210209 SecurityMemberAccess sma = new SecurityMemberAccess (false );
211210
212- Set <Pattern > excluded = new HashSet <Pattern >();
211+ Set <Pattern > excluded = new HashSet <>();
213212 excluded .add (Pattern .compile ("^" + FooBar .class .getPackage ().getName ().replaceAll ("\\ ." , "\\ \\ ." ) + ".*" ));
214213 sma .setExcludedPackageNamePatterns (excluded );
215214
@@ -220,11 +219,11 @@ public void testDefaultPackageExclusion() throws Exception {
220219 assertFalse ("default package is excluded!" , actual );
221220 }
222221
223- public void testDefaultPackageExclusion2 () throws Exception {
222+ public void testDefaultPackageExclusion2 () {
224223 // given
225224 SecurityMemberAccess sma = new SecurityMemberAccess (false );
226225
227- Set <Pattern > excluded = new HashSet <Pattern >();
226+ Set <Pattern > excluded = new HashSet <>();
228227 excluded .add (Pattern .compile ("^$" ));
229228 sma .setExcludedPackageNamePatterns (excluded );
230229
@@ -317,10 +316,10 @@ public void testAccessPrimitiveInt() throws Exception {
317316 public void testAccessPrimitiveDoubleWithNames () throws Exception {
318317 // given
319318 SecurityMemberAccess sma = new SecurityMemberAccess (false );
320- sma .setExcludedPackageNames (TextParseUtil .commaDelimitedStringToSet ("java.lang.,ognl, javax" ));
319+ sma .setExcludedPackageNames (TextParseUtil .commaDelimitedStringToSet ("ognl., javax. " ));
321320
322321
323- Set <Class <?>> excluded = new HashSet <Class <?> >();
322+ Set <Class <?>> excluded = new HashSet <>();
324323 excluded .add (Object .class );
325324 excluded .add (Runtime .class );
326325 excluded .add (System .class );
@@ -369,7 +368,7 @@ public void testAccessPrimitiveDoubleWithNames() throws Exception {
369368 public void testAccessPrimitiveDoubleWithPackageRegExs () throws Exception {
370369 // given
371370 SecurityMemberAccess sma = new SecurityMemberAccess (false );
372- Set <Pattern > patterns = new HashSet <Pattern >();
371+ Set <Pattern > patterns = new HashSet <>();
373372 patterns .add (Pattern .compile ("^java\\ .lang\\ ..*" ));
374373 sma .setExcludedPackageNamePatterns (patterns );
375374
@@ -386,7 +385,7 @@ public void testAccessPrimitiveDoubleWithPackageRegExs() throws Exception {
386385 public void testAccessMemberAccessIsAccessible () throws Exception {
387386 // given
388387 SecurityMemberAccess sma = new SecurityMemberAccess (false );
389- Set <Class <?>> excluded = new HashSet <Class <?> >();
388+ Set <Class <?>> excluded = new HashSet <>();
390389 excluded .add (ognl .MemberAccess .class );
391390 sma .setExcludedClasses (excluded );
392391
@@ -404,7 +403,7 @@ public void testAccessMemberAccessIsAccessible() throws Exception {
404403 public void testAccessMemberAccessIsBlocked () throws Exception {
405404 // given
406405 SecurityMemberAccess sma = new SecurityMemberAccess (false );
407- Set <Class <?>> excluded = new HashSet <Class <?> >();
406+ Set <Class <?>> excluded = new HashSet <>();
408407 excluded .add (SecurityMemberAccess .class );
409408 sma .setExcludedClasses (excluded );
410409
@@ -419,6 +418,21 @@ public void testAccessMemberAccessIsBlocked() throws Exception {
419418 assertFalse (accessible );
420419 }
421420
421+ public void testPackageNameExclusionAsCommaDelimited () {
422+ // given
423+ SecurityMemberAccess sma = new SecurityMemberAccess (false );
424+
425+
426+ sma .setExcludedPackageNames (TextParseUtil .commaDelimitedStringToSet ("java.lang." ));
427+
428+ // when
429+ boolean actual = sma .isPackageExcluded (String .class .getPackage (), null );
430+ actual &= sma .isPackageExcluded (null , String .class .getPackage ());
431+
432+ // then
433+ assertTrue ("package java.lang. is accessible!" , actual );
434+ }
435+
422436}
423437
424438class FooBar implements FooBarInterface {
0 commit comments