1 /*
2  * Copyright (c) 2007, 2008, 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 %I% %G%
26  * @bug 4935607
27  * @summary Tests transient properties
28  * @run main/othervm -Djava.security.manager=allow Test4935607
29  * @author Sergey Malenkov
30  */
31 
32 import java.beans.Transient;
33 
34 public class Test4935607 extends AbstractTest<Test4935607.TransientBean> {
main(String[] args)35     public static void main(String[] args) {
36         new Test4935607().test(true);
37     }
38 
39     @Override
getObject()40     protected TransientBean getObject() {
41         TransientBean bean = new TransientBean();
42         bean.setName("some string"); // NON-NLS: some string
43         return bean;
44     }
45 
46     @Override
getAnotherObject()47     protected TransientBean getAnotherObject() {
48         TransientBean bean = new TransientBean();
49         bean.setName("another string"); // NON-NLS: another string
50         bean.setComment("some comment"); // NON-NLS: some comment
51         return bean;
52     }
53 
54     @Override
validate(TransientBean before, TransientBean after)55     protected void validate(TransientBean before, TransientBean after) {
56         if (!before.getName().equals(after.getName()))
57             throw new Error("the name property incorrectly encoded");
58 
59         if (null != after.getComment())
60             throw new Error("the comment property should be encoded");
61     }
62 
63     public static class TransientBean {
64         private String name;
65         private String comment;
66 
getName()67         public String getName() {
68             return this.name;
69         }
70 
setName(String name)71         public void setName(String name) {
72             this.name = name;
73         }
74 
75         @Transient
getComment()76         public String getComment() {
77             return this.comment;
78         }
79 
setComment(String comment)80         public void setComment(String comment) {
81             this.comment = comment;
82         }
83     }
84 }
85