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: /*
019: * Licensed to the Apache Software Foundation (ASF) under one or more
020: * contributor license agreements. See the NOTICE file distributed with
021: * this work for additional information regarding copyright ownership.
022: * The ASF licenses this file to You under the Apache License, Version 2.0
023: * (the "License"); you may not use this file except in compliance with
024: * the License. You may obtain a copy of the License at
025: *
026: * http://www.apache.org/licenses/LICENSE-2.0
027: *
028: * Unless required by applicable law or agreed to in writing, software
029: * distributed under the License is distributed on an "AS IS" BASIS,
030: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
031: * See the License for the specific language governing permissions and
032: * limitations under the License.
033: */
034:
035: package org.apache.harmony.rmi.server;
036:
037: import java.io.Serializable;
038: import java.rmi.server.ServerCloneException;
039:
040: import org.apache.harmony.testframework.serialization.SerializationTest;
041: import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
042:
043: public class ServerCloneExceptionTest extends junit.framework.TestCase {
044:
045: private String errorMessage;
046:
047: private String causeMessage;
048:
049: private Exception cause;
050:
051: /**
052: * Sets up the fixture, for example, open a network connection. This method
053: * is called before a test is executed.
054: */
055: @Override
056: protected void setUp() {
057: errorMessage = "Clone Error";
058: causeMessage = "Caused Exception";
059: cause = new ServerCloneException(causeMessage);
060: }
061:
062: /**
063: * @tests java.rmi.server.ServerCloneException#ServerCloneException(String)
064: */
065: public void test_Constructor_String() {
066: ServerCloneException e = new ServerCloneException(errorMessage);
067: assertEquals(errorMessage, e.getMessage());
068: assertNull(e.detail);
069: try {
070: e.initCause(e);
071: fail("No expected IllegalArgumentException");
072: } catch (IllegalArgumentException exception) {
073: // expected
074: }
075: }
076:
077: /**
078: * @tests java.rmi.server.ServerCloneException#ServerCloneException(String,Exception)
079: */
080: public void test_Constructor_String_Exception() {
081: ServerCloneException e = new ServerCloneException(errorMessage,
082: cause);
083: assertEquals(cause.getMessage(), e.getCause().getMessage());
084: assertEquals(cause.getMessage(), e.detail.getMessage());
085: }
086:
087: // comparator for ServerCloneException objects
088: private static final SerializableAssert comparator = new SerializableAssert() {
089: public void assertDeserialized(Serializable initial,
090: Serializable deserialized) {
091:
092: SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(
093: initial, deserialized);
094:
095: ServerCloneException initEx = (ServerCloneException) initial;
096: ServerCloneException desrEx = (ServerCloneException) deserialized;
097:
098: assertEquals(initEx.getMessage(), desrEx.getMessage());
099: assertEquals(initEx.getCause().getMessage(), desrEx
100: .getCause().getMessage());
101: }
102: };
103:
104: /**
105: * @tests serialization/deserialization.
106: */
107: public void testSerializationSelf() throws Exception {
108:
109: SerializationTest.verifySelf(new ServerCloneException(
110: errorMessage, cause), comparator);
111: }
112:
113: /**
114: * @tests serialization/deserialization compatibility with RI.
115: */
116: public void testSerializationCompatibility() throws Exception {
117:
118: SerializationTest.verifyGolden(this , new ServerCloneException(
119: errorMessage, cause), comparator);
120: }
121:
122: }
|