Skip to content

Commit 2eef8de

Browse files
committed
Javadocs. Make our exceptions fit the Java 1.4 pattern. 100%/100% line/branch code coverage for the main package.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@797804 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3210069 commit 2eef8de

5 files changed

Lines changed: 159 additions & 18 deletions

File tree

src/java/org/apache/commons/codec/DecoderException.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@ public class DecoderException extends Exception {
3333
private static final long serialVersionUID = 1L;
3434

3535
/**
36-
* Creates a DecoderException.
36+
* Constructs a new exception with <code>null</code> as its detail message. The cause is not initialized, and may
37+
* subsequently be initialized by a call to {@link #initCause}.
38+
*
39+
* @since 1.4
40+
*/
41+
public DecoderException() {
42+
super();
43+
}
44+
45+
/**
46+
* Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
47+
* be initialized by a call to {@link #initCause}.
3748
*
3849
* @param message
3950
* The detail message which is saved for later retrieval by the {@link #getMessage()} method.
@@ -43,28 +54,35 @@ public DecoderException(String message) {
4354
}
4455

4556
/**
46-
* Creates a DecoderException.
57+
* Constructsa new exception with the specified detail message and cause.
58+
*
59+
* <p>
60+
* Note that the detail message associated with <code>cause</code> is not automatically incorporated into this
61+
* exception's detail message.
62+
* </p>
4763
*
64+
* @param message
65+
* The detail message which is saved for later retrieval by the {@link #getMessage()} method.
4866
* @param cause
4967
* The cause which is saved for later retrieval by the {@link #getCause()} method. A <code>null</code>
5068
* value is permitted, and indicates that the cause is nonexistent or unknown.
5169
* @since 1.4
5270
*/
53-
public DecoderException(Throwable cause) {
54-
super(cause);
71+
public DecoderException(String message, Throwable cause) {
72+
super(message, cause);
5573
}
5674

5775
/**
58-
* Creates a DecoderException.
76+
* Constructs a new exception with the specified cause and a detail message of <code>(cause==null ?
77+
* null : cause.toString())</code> (which typically contains the class and detail message of <code>cause</code>).
78+
* This constructor is useful for exceptions that are little more than wrappers for other throwables.
5979
*
60-
* @param message
61-
* The detail message which is saved for later retrieval by the {@link #getMessage()} method.
6280
* @param cause
6381
* The cause which is saved for later retrieval by the {@link #getCause()} method. A <code>null</code>
6482
* value is permitted, and indicates that the cause is nonexistent or unknown.
6583
* @since 1.4
6684
*/
67-
public DecoderException(String message, Throwable cause) {
68-
super(message, cause);
85+
public DecoderException(Throwable cause) {
86+
super(cause);
6987
}
7088
}

src/java/org/apache/commons/codec/EncoderException.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,18 @@ public class EncoderException extends Exception {
3535
private static final long serialVersionUID = 1L;
3636

3737
/**
38-
* Creates a new instance of this exception with an useful message.
38+
* Constructs a new exception with <code>null</code> as its detail message. The cause is not initialized, and may
39+
* subsequently be initialized by a call to {@link #initCause}.
40+
*
41+
* @since 1.4
42+
*/
43+
public EncoderException() {
44+
super();
45+
}
46+
47+
/**
48+
* Constructs a new exception with the specified detail message. The cause is not initialized, and may subsequently
49+
* be initialized by a call to {@link #initCause}.
3950
*
4051
* @param message
4152
* a useful message relating to the encoder specific error.
@@ -45,28 +56,35 @@ public EncoderException(String message) {
4556
}
4657

4758
/**
48-
* Creates a EncoderException.
59+
* Constructs a new exception with the specified detail message and cause.
60+
*
61+
* <p>
62+
* Note that the detail message associated with <code>cause</code> is not automatically incorporated into this
63+
* exception's detail message.
64+
* </p>
4965
*
66+
* @param message
67+
* The detail message which is saved for later retrieval by the {@link #getMessage()} method.
5068
* @param cause
5169
* The cause which is saved for later retrieval by the {@link #getCause()} method. A <code>null</code>
5270
* value is permitted, and indicates that the cause is nonexistent or unknown.
5371
* @since 1.4
5472
*/
55-
public EncoderException(Throwable cause) {
56-
super(cause);
73+
public EncoderException(String message, Throwable cause) {
74+
super(message, cause);
5775
}
5876

5977
/**
60-
* Creates a EncoderException.
78+
* Constructs a new exception with the specified cause and a detail message of <code>(cause==null ?
79+
* null : cause.toString())</code> (which typically contains the class and detail message of <code>cause</code>).
80+
* This constructor is useful for exceptions that are little more than wrappers for other throwables.
6181
*
62-
* @param message
63-
* The detail message which is saved for later retrieval by the {@link #getMessage()} method.
6482
* @param cause
6583
* The cause which is saved for later retrieval by the {@link #getCause()} method. A <code>null</code>
6684
* value is permitted, and indicates that the cause is nonexistent or unknown.
6785
* @since 1.4
6886
*/
69-
public EncoderException(String message, Throwable cause) {
70-
super(message, cause);
87+
public EncoderException(Throwable cause) {
88+
super(cause);
7189
}
7290
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 1993-2003 SEAGULL
3+
*
4+
* DecoderException.java
5+
* Created on Jul 25, 2009, 9:28:09 AM
6+
*
7+
*/
8+
9+
package org.apache.commons.codec;
10+
11+
import junit.framework.TestCase;
12+
13+
/**
14+
* Tests DecoderException.
15+
*
16+
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
17+
* @version $Id: $
18+
*/
19+
public class DecoderExceptionTest extends TestCase {
20+
21+
private static final String MSG = "TEST";
22+
23+
private static final Throwable t = new Exception();
24+
25+
public void testConstructor0() {
26+
DecoderException e = new DecoderException();
27+
assertNull(e.getMessage());
28+
assertNull(e.getCause());
29+
}
30+
31+
public void testConstructorString() {
32+
DecoderException e = new DecoderException(MSG);
33+
assertEquals(MSG, e.getMessage());
34+
assertNull(e.getCause());
35+
}
36+
37+
public void testConstructorStringThrowable() {
38+
DecoderException e = new DecoderException(MSG, t);
39+
assertEquals(MSG, e.getMessage());
40+
assertEquals(t, e.getCause());
41+
}
42+
43+
public void testConstructorThrowable() {
44+
DecoderException e = new DecoderException(t);
45+
assertEquals(t.getClass().getName(), e.getMessage());
46+
assertEquals(t, e.getCause());
47+
}
48+
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 1993-2003 SEAGULL
3+
*
4+
* DecoderException.java
5+
* Created on Jul 25, 2009, 9:28:09 AM
6+
*
7+
*/
8+
9+
package org.apache.commons.codec;
10+
11+
import junit.framework.TestCase;
12+
13+
/**
14+
* Tests EncoderException.
15+
*
16+
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
17+
* @version $Id: $
18+
*/
19+
public class EncoderExceptionTest extends TestCase {
20+
21+
private static final String MSG = "TEST";
22+
23+
private static final Throwable t = new Exception();
24+
25+
public void testConstructor0() {
26+
EncoderException e = new EncoderException();
27+
assertNull(e.getMessage());
28+
assertNull(e.getCause());
29+
}
30+
31+
public void testConstructorString() {
32+
EncoderException e = new EncoderException(MSG);
33+
assertEquals(MSG, e.getMessage());
34+
assertNull(e.getCause());
35+
}
36+
37+
public void testConstructorStringThrowable() {
38+
EncoderException e = new EncoderException(MSG, t);
39+
assertEquals(MSG, e.getMessage());
40+
assertEquals(t, e.getCause());
41+
}
42+
43+
public void testConstructorThrowable() {
44+
EncoderException e = new EncoderException(t);
45+
assertEquals(t.getClass().getName(), e.getMessage());
46+
assertEquals(t, e.getCause());
47+
}
48+
49+
}

src/test/org/apache/commons/codec/RequiredCharsetNamesTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
*/
2929
public class RequiredCharsetNamesTest extends TestCase {
3030

31+
/**
32+
* We could make the constructor private in the future, it's a matter a style.
33+
*/
34+
public void testConstructor() {
35+
new RequiredCharsetNames();
36+
}
37+
3138
public void testIso8859_1() {
3239
Assert.assertEquals("ISO-8859-1", RequiredCharsetNames.ISO_8859_1);
3340
}

0 commit comments

Comments
 (0)