001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.beans.tests.java.beans;
019:
020: import java.beans.Beans;
021: import java.beans.PropertyChangeEvent;
022: import java.beans.PropertyVetoException;
023: import java.io.Serializable;
024:
025: import junit.framework.TestCase;
026:
027: import org.apache.harmony.beans.tests.support.mock.MockJavaBean;
028: import org.apache.harmony.testframework.serialization.SerializationTest;
029: import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
030:
031: /**
032: * Unit test for class PropertyVetoException
033: */
034: public class PropertyVetoExceptionTest extends TestCase {
035:
036: private PropertyChangeEvent event;
037:
038: @Override
039: protected void setUp() throws Exception {
040: super .setUp();
041: MockJavaBean myBean = new MockJavaBean(
042: "Bean_PropertyVetoExceptionTest");
043: event = new PropertyChangeEvent(myBean, "propertyOne",
044: "value_old", "value_one");
045: }
046:
047: @Override
048: protected void tearDown() throws Exception {
049: super .tearDown();
050: }
051:
052: public void testPropertyVetoException() {
053: String message = "testPropertyVetoException";
054: PropertyVetoException e = new PropertyVetoException(message,
055: event);
056: assertSame(message, e.getMessage());
057: assertSame(event, e.getPropertyChangeEvent());
058: }
059:
060: public void testPropertyVetoException_MessageNull() {
061: String message = null;
062: PropertyVetoException e = new PropertyVetoException(message,
063: event);
064: assertNull(e.getMessage());
065: assertSame(event, e.getPropertyChangeEvent());
066: }
067:
068: public void testPropertyVetoException_EventNull() {
069: String message = "testPropertyVetoException";
070: PropertyVetoException e = new PropertyVetoException(message,
071: null);
072: assertSame(message, e.getMessage());
073: assertNull(e.getPropertyChangeEvent());
074: }
075:
076: // comparator for PropertyVetoException objects
077: private static final SerializableAssert comparator = new SerializableAssert() {
078: public void assertDeserialized(Serializable initial,
079: Serializable deserialized) {
080:
081: SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(
082: initial, deserialized);
083:
084: PropertyVetoException initEx = (PropertyVetoException) initial;
085: PropertyVetoException desrEx = (PropertyVetoException) deserialized;
086:
087: assertNull(desrEx.getPropertyChangeEvent().getSource());
088:
089: // compare event objects
090: PropertyChangeEventTest.comparator.assertDeserialized(
091: initEx.getPropertyChangeEvent(), desrEx
092: .getPropertyChangeEvent());
093: }
094: };
095:
096: /**
097: * @tests serialization/deserialization.
098: */
099: public void testSerializationSelf() throws Exception {
100:
101: SerializationTest.verifySelf(new PropertyVetoException(
102: "testPropertyVetoException", event), comparator);
103: }
104:
105: /**
106: * @tests serialization/deserialization compatibility with RI.
107: */
108: public void testSerializationCompatibility() throws Exception {
109:
110: SerializationTest.verifyGolden(this , new PropertyVetoException(
111: "testPropertyVetoException", event), comparator);
112: }
113:
114: public void testPropertyVetoExceptionMessage() {
115: // Regression for HARMONY-235 (tracking the similar bug)
116: PropertyChangeEvent event = new PropertyChangeEvent(
117: new Beans(), "propertyName", "oldValue", "newValue");
118:
119: String message = "test message";
120:
121: PropertyVetoException e = new PropertyVetoException(message,
122: event);
123: assertEquals(message, e.getMessage());
124: }
125: }
|