/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/ /* * TestVeto - test the vetoable events *
*/
/* * Book * Index[1,n] * Word - String * Ref[1,n] * Page - String * Line - String * Chapter[1,n] * Comment? - String * Paragraph[0,n] - String * Summary? - String * Author[1,n] - String * Good - Boolean * Available - Boolean
*/
// // Set a listener on the root //
MyListener l = new MyListener("Book listener", book);
book.addVetoableChangeListener(l); //GraphManager.debug(true);
setTest("simple change event on the root - no veto");
l.reset();
String s = "This book is about how to veto changes"; // Change a property on the root - this should raises an event
book.setSummary(s); // Check the received event
check(l.oldValue() == null, "(old value)");
check(l.newValue().equals(s), "(new value)");
check(book.getSummary().equals(s), "(new value)");
boolean gotException = false;
setTest("simple change event on the root - veto");
l.reset();
l.veto();
String s2 = "this is the new value";
s = book.getSummary(); try {
book.setSummary(s2);
} catch(PropertyVetoException ve) {
check(book.getSummary().equals(s), "(got exception & same value)");
gotException = true;
}
if (!gotException)
check(false, " didn't get the veto exception (1)!");
setTest("Try to listen for a non vetoable property");
gotException = false; try {
book.addVetoableChangeListener("Reviews", l);
} catch(Exception e) {
check(true, "got exception:\n" + e.getMessage());
gotException = true;
}
if (!gotException)
check(false, " didn't get the runtime exception (2)!");
setTest("Indexed final property");
l.reset();
String [] ss = {"Author1", "Author2", "Author3"};
l.printStringArray();
book.setAuthor(ss);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.