View Javadoc
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  package org.apache.juneau;
18  
19  import static org.apache.juneau.TestUtils.*;
20  import static org.junit.jupiter.api.Assertions.*;
21  
22  import java.io.*;
23  
24  import org.apache.juneau.json.*;
25  import org.junit.jupiter.api.*;
26  
27  class IgnoredClasses_Test extends TestBase {
28  
29  	//====================================================================================================
30  	// testFilesRenderedAsStrings
31  	//====================================================================================================
32  	@Test void a01_filesRenderedAsStrings() {
33  		if (! System.getProperty("os.name").toLowerCase().startsWith("win")) return;
34  		// Files should be rendered as strings.
35  		var f = new File("C:/temp");
36  		assertJson("'C:\\\\temp'", f);
37  	}
38  
39  	//====================================================================================================
40  	// testIgnorePackages
41  	//====================================================================================================
42  	@Test void a02_ignorePackages() throws Exception {
43  		var a = new A();
44  		var s = JsonSerializer.create().json5();
45  		assertEquals("{f1:'isBean'}", s.build().serialize(a));
46  		s.notBeanPackages("org.apache.juneau");
47  		assertEquals("'isNotBean'", s.build().serialize(a));
48  		s.beanContext().notBeanPackages().remove("org.apache.juneau");
49  		assertEquals("{f1:'isBean'}", s.build().serialize(a));
50  		s.notBeanPackages("org.apache.juneau.*");
51  		assertEquals("'isNotBean'", s.build().serialize(a));
52  		s.beanContext().notBeanPackages().remove("org.apache.juneau.*");
53  		assertEquals("{f1:'isBean'}", s.build().serialize(a));
54  		s.notBeanPackages("org.apache.juneau.*");
55  		assertEquals("'isNotBean'", s.build().serialize(a));
56  		s.beanContext().notBeanPackages().remove("org.apache.juneau.*");
57  		assertEquals("{f1:'isBean'}", s.build().serialize(a));
58  		s.notBeanPackages("org.apache.juneau");
59  		assertEquals("'isNotBean'", s.build().serialize(a));
60  		s.notBeanPackages("org.apache.juneau.x");
61  		assertEquals("'isNotBean'", s.build().serialize(a));
62  	}
63  
64  	public static class A {
65  		public String f1 = "isBean";
66  		@Override /* Object */
67  		public String toString() {
68  			return "isNotBean";
69  		}
70  	}
71  }