1 /*
2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 8016545
27  * @summary Tests beans with predefined fields
28  * @author Sergey Malenkov
29  */
30 
31 public class Test8016545 extends AbstractTest {
main(String[] args)32     public static void main(String[] args) {
33         new Test8016545().test(true);
34     }
35 
36     @Override
getObject()37     protected Object getObject() {
38         Bean bean = new Bean();
39         bean.setUndefined(Boolean.FALSE);
40         Info info = new Info();
41         info.setEnabled(Boolean.TRUE);
42         info.setID(1);
43         bean.setInfo(info);
44         return bean;
45     }
46 
47     @Override
getAnotherObject()48     protected Object getAnotherObject() {
49         Bean bean = new Bean();
50         bean.setUndefined(Boolean.TRUE);
51         bean.getInfo().setEnabled(Boolean.FALSE);
52         bean.getInfo().setID(2);
53         return bean;
54     }
55 
56     public static class Bean {
57         private Info info = new Info(); // predefined
58         private Boolean defined = Boolean.TRUE;
59         private Boolean undefined;
60 
getInfo()61         public Info getInfo() {
62             return this.info;
63         }
64 
setInfo(Info info)65         public void setInfo(Info info) {
66             this.info = info;
67         }
68 
getDefined()69         public Boolean getDefined() {
70             return this.defined;
71         }
72 
setDefined(Boolean defined)73         public void setDefined(Boolean defined) {
74             this.defined = defined;
75         }
76 
getUndefined()77         public Boolean getUndefined() {
78             return this.undefined;
79         }
80 
setUndefined(Boolean undefined)81         public void setUndefined(Boolean undefined) {
82             this.undefined = undefined;
83         }
84     }
85 
86     public static class Info {
87         private Integer id;
88         private Boolean enabled;
89 
getID()90         public Integer getID() {
91             return this.id;
92         }
93 
setID(Integer id)94         public void setID(Integer id) {
95             this.id = id;
96         }
97 
getEnabled()98         public Boolean getEnabled() {
99             return this.enabled;
100         }
101 
setEnabled(Boolean enabled)102         public void setEnabled(Boolean enabled) {
103             this.enabled = enabled;
104         }
105     }
106 }
107