File: setValue.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (145 lines) | stat: -rw-r--r-- 5,057 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//Tags: JDK1.4

//Copyright (C) 2004 Robert Schuster <theBohemian@gmx.net>

//This file is part of Mauve.

//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING.  If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA.package gnu.testlet.java.beans.PropertyEditorSupport;

package gnu.testlet.java.beans.PropertyEditorSupport;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditorSupport;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

/** This test checks whether PropertyEditorSupport.setValue() and its event notification
 * works as specified.  
 * 
 * These tests have been written as a reaction on classpath's bug #10799
 * (http://savannah.gnu.org/bugs/index.php?func=detailitem&item_id=10799).
 * 
 * @author Robert Schuster
 */
public class setValue implements Testlet
{

    private boolean nonNullPropertyChanged;

    private boolean nullPropertyChanged;

    // declaration is needed for anonymous class access without using 'final'
    private PropertyEditorSupport pes;

    public void test(final TestHarness harness)
    {
        // for 1.4 compatibility it is needed to subclass PropertyEditorSupport because the constructors are
        // 'protected' (they are 'public' in 1.5)
        pes = new PropertyEditorSupport()
        {};

        final Object newValue = "new value";

        pes.addPropertyChangeListener(new PropertyChangeListener()
        {
            public void propertyChange(PropertyChangeEvent event)
            {
                nonNullPropertyChanged = true;

                // the PropertyEditorSupport instance should be the event source 
                // (according to documentation of its zero argument constructor)
                harness.check(
                    event.getSource(),
                    pes,
                    "pes1-event-event source");

                // the property name for an PropertyEditorSupport object is always null
                harness.check(
                    event.getPropertyName(),
                    null,
                    "pes1-event-property name");

                // according to documentation of PropertyChangeEvent the old and new value should be
                // null if the property name is null.
                harness.check(
                    event.getOldValue(),
                    null,
                    "pes1-event-old value");
                harness.check(
                    event.getNewValue(),
                    null,
                    "pes1-event-new value");

                // at this point the PropertyEditorSupport instance should have been updated to the new value already
                harness.check(pes.getValue(), newValue, "pes1-new value");
            }

        });

        // this method should trigger the calling of anonymous PropertyChangeListener above
        pes.setValue(newValue);

        harness.check(
            nonNullPropertyChanged,
            "pes1-PropertyChangeListener call");

        // creates another PropertyEditorSupport instance for a slightly different test
        pes = new PropertyEditorSupport()
        {};

        pes.addPropertyChangeListener(new PropertyChangeListener()
        {

            public void propertyChange(PropertyChangeEvent event)
            {
                nullPropertyChanged = true;

                // the same as in pes1 tests
                harness.check(
                    event.getSource(),
                    pes,
                    "pes2-event-event source");
                    
                harness.check(
                    event.getPropertyName(),
                    null,
                    "pes2-event-property name");
                    
                harness.check(
                    event.getOldValue(),
                    null,
                    "pes2-event-old value");
                    
                harness.check(
                    event.getNewValue(),
                    null,
                    "pes2-event-new value");

                // the new value should be null, too
                harness.check(pes.getValue(), null, "pes2-new value");

            }

        });

        // changing the PropertyEditorSupport value (which is null at this moment) to null should
        // cause the PropertyChangeListener to get notified
        pes.setValue(null);

        harness.check(nullPropertyChanged, "pes2-PropertyChangeListener call");
    }

}