Skip to content

Commit 30d3a91

Browse files
committed
Merge pull request #8 from mariuszs/topic/cleanup
javadoc cleanup, removed duplicated code
2 parents 4981272 + c5388ef commit 30d3a91

File tree

7 files changed

+89
-111
lines changed

7 files changed

+89
-111
lines changed

catch-exception/src/main/java/com/googlecode/catchexception/apis/BDDCatchException.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
* approach to catch and verify exceptions (<i>given/when/then</i>).
2525
* <p>
2626
* EXAMPLE:
27-
* <code><pre class="prettyprint lang-java">// given an empty list
27+
* <code><pre class="prettyprint lang-java">import static org.assertj.core.api.BDDAssertions.then;
28+
29+
// given an empty list
2830
List myList = new ArrayList();
2931
3032
// when we try to get the first element of the list
@@ -40,6 +42,9 @@
4042
thenThrown(IndexOutOfBoundsException.class);
4143
</pre></code>
4244
* <p>
45+
* The Method {@link org.assertj.core.api.BDDAssertions#then(Throwable)} is originated from <a
46+
* href="http://assertj.org">AssertJ</a>. You can also use method <code>assertThat</code>:
47+
* <code><pre class="prettyprint lang-java">// import static org.assertj.core.api.Assertions.assertThat;
4348
4449
// then we expect an IndexOutOfBoundsException
4550
assertThat(caughtException())
@@ -52,6 +57,7 @@
5257
</pre></code>
5358
*
5459
* @author rwoo
60+
* @author mariuszs
5561
* @since 1.3.0
5662
*/
5763
public class BDDCatchException {

catch-exception/src/main/java/com/googlecode/catchexception/apis/CatchExceptionAssertJ.java

+37-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,41 @@
1919
import org.assertj.core.api.CompatibilityAssertions;
2020

2121
/**
22+
* Supports <a
23+
* href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">BDD</a>-like
24+
* approach to catch and verify exceptions (<i>given/when/then</i>).
25+
* <p>
26+
* EXAMPLE:
27+
* <code><pre class="prettyprint lang-java">// given an empty list
28+
List myList = new ArrayList();
29+
30+
// when we try to get the first element of the list
31+
when(myList).get(1);
32+
33+
// then we expect an IndexOutOfBoundsException
34+
then(caughtException())
35+
.isInstanceOf(IndexOutOfBoundsException.class)
36+
.hasMessage("Index: 1, Size: 0")
37+
.hasNoCause();
38+
39+
// then we expect an IndexOutOfBoundsException (alternatively)
40+
thenThrown(IndexOutOfBoundsException.class);
41+
</pre></code>
42+
* <p>
43+
* The Method {@link #then(Exception)} uses <a
44+
* href="https://github.com/joel-costigliola/assertj-core">AssertJ</a>
45+
* assertions. You can use them directly if you like:
46+
* <code><pre class="prettyprint lang-java">// import static org.assertj.core.api.Assertions.assertThat;
47+
48+
// then we expect an IndexOutOfBoundsException
49+
assertThat(caughtException())
50+
.isInstanceOf(IndexOutOfBoundsException.class)
51+
.hasMessage("Index: 1, Size: 0")
52+
.hasMessageStartingWith("Index: 1")
53+
.hasMessageEndingWith("Size: 0")
54+
.hasMessageContaining("Size")
55+
.hasNoCause();
56+
</pre></code>
2257
*
2358
* @author rwoo
2459
* @since 1.1.0
@@ -53,8 +88,8 @@ public class CatchExceptionAssertJ extends BDDCatchException {
5388
* @param actualException
5489
* the value to be the target of the assertions methods.
5590
* @return Returns the created assertion object.
56-
* @see org.assertj.core.api.CompatibilityAssertions#assertThat(Throwable)
57-
* @deprecated As of release 1.3.0, replaced by {@link org.assertj.core.api.BDDAssertions#then(java.lang.Throwable}
91+
* @see org.assertj.core.api.Assertions#assertThat(Throwable)
92+
* @deprecated As of release 1.3.0, replaced by {@link org.assertj.core.api.BDDAssertions#then(Throwable)}
5893
*/
5994
public static AbstractThrowableAssert<?, ? extends Throwable> then(Exception actualException) {
6095
// delegate to AssertJ assertions

catch-exception/src/main/java/com/googlecode/catchexception/apis/CatchExceptionBdd.java

+1-54
Original file line numberDiff line numberDiff line change
@@ -63,60 +63,7 @@
6363
* @deprecated As of release 1.3.0, replaced by {@link com.googlecode.catchexception.apis.BDDCatchException()}
6464
*/
6565
@Deprecated
66-
public class CatchExceptionBdd {
67-
68-
/**
69-
* Use it together with {@link #then(Exception)} or
70-
* {@link #thenThrown(Class)} in order to catch an exception and to get
71-
* access to the thrown exception (for further verifications).
72-
*
73-
* @param <T>
74-
* The type of the given <code>obj</code>.
75-
*
76-
* @param obj
77-
* The instance that shall be proxied. Must not be
78-
* <code>null</code>.
79-
* @return Returns a proxy for the given object. The proxy catches
80-
* exceptions of the given type when a method on the proxy is
81-
* called.
82-
* @see CatchException#catchException(Object)
83-
*/
84-
public static <T> T when(T obj) {
85-
return CatchException.catchException(obj);
86-
}
87-
88-
/**
89-
* Throws an assertion if no exception is thrown or if an exception of an
90-
* unexpected type is thrown.
91-
* <p>
92-
* EXAMPLE:
93-
* <code><pre class="prettyprint lang-java">// given a list with nine members
94-
List myList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
95-
96-
// when we try to get the 500th member of the fellowship
97-
when(myList).get(500);
98-
99-
// then we expect an IndexOutOfBoundsException
100-
thenThrown(IndexOutOfBoundsException.class);
101-
</pre></code>
102-
*
103-
* @param actualExceptionClazz
104-
* the expected type of the caught exception.
105-
*/
106-
@SuppressWarnings({ "unchecked", "rawtypes" })
107-
public static void thenThrown(Class actualExceptionClazz) {
108-
Exception e = CatchException.caughtException();
109-
if (e == null) {
110-
// no exception caught -> assertion failed
111-
throw new ExceptionNotThrownAssertionError(actualExceptionClazz);
112-
} else if (!actualExceptionClazz.isAssignableFrom(CatchException
113-
.caughtException().getClass())) {
114-
// caught exception is of wrong type -> assertion failed
115-
throw new ExceptionNotThrownAssertionError(actualExceptionClazz, e);
116-
} else {
117-
// the caught exception is of the expected type -> nothing to do :-)
118-
}
119-
}
66+
public class CatchExceptionBdd extends BDDCatchException {
12067

12168
/**
12269
* Enables <a href="https://github.com/alexruiz/fest-assert-2.x">FEST Fluent

catch-throwable/src/main/java/com/googlecode/catchexception/throwable/apis/BDDCatchThrowable.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
* Supports <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">BDD</a>-like approach to catch and verify
2323
* throwables (<i>given/when/then</i>).
2424
* <p>
25-
* EXAMPLE: <code><pre class="prettyprint lang-java">// given an empty list
25+
* <code><pre class="prettyprint lang-java">import static org.assertj.core.api.BDDAssertions.then;
26+
27+
// given an empty list
2628
List myList = new ArrayList();
2729
2830
// when we try to get the first element of the list
@@ -37,6 +39,10 @@
3739
// then we expect an IndexOutOfBoundsThrowable (alternatively)
3840
thenThrown(IndexOutOfBoundsThrowable.class);
3941
</pre></code>
42+
* <p>
43+
* The Method {@link org.assertj.core.api.BDDAssertions#then(Throwable)} is originated from <a
44+
* href="http://assertj.org">AssertJ</a>. You can also use method <code>assertThat</code>:
45+
* <code><pre class="prettyprint lang-java">// import static org.assertj.core.api.Assertions.assertThat;
4046
4147
// then we expect an IndexOutOfBoundsThrowable
4248
assertThat(caughtThrowable())
@@ -49,6 +55,7 @@
4955
</pre></code>
5056
*
5157
* @author rwoo
58+
* @author mariuszs
5259
* @since 1.3.0
5360
*
5461
*/

catch-throwable/src/main/java/com/googlecode/catchexception/throwable/apis/CatchThrowableAssertJ.java

+33-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,43 @@
1919
import org.assertj.core.api.CompatibilityAssertions;
2020

2121
/**
22-
* Use BDDCatchThrowable
22+
* Supports <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development">BDD</a>-like approach to catch and verify
23+
* throwables (<i>given/when/then</i>).
24+
* <p>
25+
* EXAMPLE: <code><pre class="prettyprint lang-java">// given an empty list
26+
List myList = new ArrayList();
27+
28+
// when we try to get the first element of the list
29+
when(myList).get(1);
30+
31+
// then we expect an IndexOutOfBoundsThrowable
32+
then(caughtThrowable())
33+
.isInstanceOf(IndexOutOfBoundsThrowable.class)
34+
.hasMessage("Index: 1, Size: 0")
35+
.hasNoCause();
36+
37+
// then we expect an IndexOutOfBoundsThrowable (alternatively)
38+
thenThrown(IndexOutOfBoundsThrowable.class);
39+
</pre></code>
40+
* <p>
41+
* The Method {@link #then(Throwable)} uses <a href="https://github.com/joel-costigliola/assertj-core">AssertJ</a>
42+
* assertions. You can use them directly if you like:
43+
* <code><pre class="prettyprint lang-java">// import static org.assertj.core.api.Assertions.assertThat;
44+
45+
// then we expect an IndexOutOfBoundsThrowable
46+
assertThat(caughtThrowable())
47+
.isInstanceOf(IndexOutOfBoundsThrowable.class)
48+
.hasMessage("Index: 1, Size: 0")
49+
.hasMessageStartingWith("Index: 1")
50+
.hasMessageEndingWith("Size: 0")
51+
.hasMessageContaining("Size")
52+
.hasNoCause();
53+
</pre></code>
2354
*
2455
* @author rwoo
2556
* @since 1.2.0
2657
* @deprecated As of release 1.3.0, replaced by {@link com.googlecode.catchexception.throwable.apis.BDDCatchThrowable()}
27-
* @see com.googlecode.catchexception.throwable.apis.BDDCatchThrowable
58+
* @see org.assertj.core.api.Assertions#assertThat(Throwable)
2859
*/
2960
@Deprecated
3061
public class CatchThrowableAssertJ extends BDDCatchThrowable{

catch-throwable/src/main/java/com/googlecode/catchexception/throwable/apis/CatchThrowableBdd.java

+2-50
Original file line numberDiff line numberDiff line change
@@ -62,57 +62,9 @@
6262
*
6363
*/
6464
@Deprecated
65-
public class CatchThrowableBdd {
65+
public class CatchThrowableBdd extends BDDCatchThrowable {
6666

67-
/**
68-
* Use it together with {@link #then(Throwable)} or {@link #thenThrown(Class)} in order to catch an throwable and to
69-
* get access to the thrown throwable (for further verifications).
70-
*
71-
* @param <T>
72-
* The type of the given <code>obj</code>.
73-
*
74-
* @param obj
75-
* The instance that shall be proxied. Must not be <code>null</code>.
76-
* @return Returns a proxy for the given object. The proxy catches throwables of the given type when a method on the
77-
* proxy is called.
78-
* @see CatchThrowable#catchThrowable(Object)
79-
*/
80-
public static <T> T when(T obj) {
81-
return CatchThrowable.catchThrowable(obj);
82-
}
83-
84-
/**
85-
* Throws an assertion if no throwable is thrown or if an throwable of an unexpected type is thrown.
86-
* <p>
87-
* EXAMPLE:
88-
* <code><pre class="prettyprint lang-java">// given a list with nine members
89-
List myList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
90-
91-
// when we try to get the 500th member of the fellowship
92-
when(myList).get(500);
93-
94-
// then we expect an IndexOutOfBoundsThrowable
95-
thenThrown(IndexOutOfBoundsThrowable.class);
96-
</pre></code>
97-
*
98-
* @param actualThrowableClazz
99-
* the expected type of the caught throwable.
100-
*/
101-
@SuppressWarnings({ "unchecked", "rawtypes" })
102-
public static void thenThrown(Class actualThrowableClazz) {
103-
Throwable e = CatchThrowable.caughtThrowable();
104-
if (e == null) {
105-
// no throwable caught -> assertion failed
106-
throw new ThrowableNotThrownAssertionError(actualThrowableClazz);
107-
} else if (!actualThrowableClazz.isAssignableFrom(CatchThrowable.caughtThrowable().getClass())) {
108-
// caught throwable is of wrong type -> assertion failed
109-
throw new ThrowableNotThrownAssertionError(actualThrowableClazz, e);
110-
} else {
111-
// the caught throwable is of the expected type -> nothing to do :-)
112-
}
113-
}
114-
115-
/**
67+
/**
11668
* Enables <a href="https://github.com/alexruiz/fest-assert-2.x">FEST Fluent Assertions 2.x</a> about the caught
11769
* throwable.
11870
* <p>

functional-tests/catch-exception-assertj16/src/test/java/com/googlecode/catchexception/apis/BDDCatchExceptionAssertJ16Test.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
*/
3737
@SuppressWarnings("javadoc")
38-
public class BDDCatchExceptionAssertJ16Test extends BDDCatchExceptionTest{
38+
public class BDDCatchExceptionAssertJ16Test extends BDDCatchExceptionTest {
3939

4040
@SuppressWarnings("rawtypes")
4141
@Test

0 commit comments

Comments
 (0)