01: /*
02: * Copyright 2001-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.commons.codec;
18:
19: import junit.framework.TestCase;
20:
21: /**
22: * @version $Id: StringEncoderAbstractTest.java,v 1.9 2004/04/19 01:14:29 ggregory Exp $
23: * @author Apache Software Foundation
24: */
25: public abstract class StringEncoderAbstractTest extends TestCase {
26:
27: public StringEncoderAbstractTest(String name) {
28: super (name);
29: }
30:
31: protected abstract StringEncoder makeEncoder();
32:
33: // ------------------------------------------------------------------------
34:
35: public void testEncodeEmpty() throws Exception {
36: Encoder encoder = makeEncoder();
37: encoder.encode("");
38: encoder.encode(" ");
39: encoder.encode("\t");
40: }
41:
42: public void testEncodeNull() throws Exception {
43: StringEncoder encoder = makeEncoder();
44:
45: try {
46: encoder.encode(null);
47: } catch (EncoderException ee) {
48: // An exception should be thrown
49: }
50: }
51:
52: public void testEncodeWithInvalidObject() throws Exception {
53:
54: boolean exceptionThrown = false;
55: try {
56: StringEncoder encoder = makeEncoder();
57: encoder.encode(new Float(3.4));
58: } catch (Exception e) {
59: exceptionThrown = true;
60: }
61:
62: assertTrue(
63: "An exception was not thrown when we tried to encode "
64: + "a Float object", exceptionThrown);
65: }
66: }
|