Skip to content

Commit 58daef5

Browse files
committed
Adding unit tests for the aggregate exception
1 parent a316bc5 commit 58daef5

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* ****************************************************************************
3+
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client.exceptions;
17+
18+
import org.junit.Test;
19+
20+
import java.util.ArrayList;
21+
import java.util.Iterator;
22+
import java.util.List;
23+
24+
import static org.hamcrest.CoreMatchers.is;
25+
import static org.hamcrest.CoreMatchers.notNullValue;
26+
import static org.junit.Assert.assertFalse;
27+
import static org.junit.Assert.assertThat;
28+
import static org.junit.Assert.assertTrue;
29+
30+
public class AggregateException_Test {
31+
32+
@Test
33+
public void basicAggregate() {
34+
final Exception e1 = new Exception("first exception");
35+
final Exception e2 = new Exception("second exception");
36+
37+
final List<Throwable> exceptionList = new ArrayList<>();
38+
exceptionList.add(e1);
39+
exceptionList.add(e2);
40+
41+
final AggregateException aggregateException = new AggregateException(exceptionList);
42+
43+
final Iterator<Throwable> exceptionIter = aggregateException.getExceptions().iterator();
44+
45+
assertTrue(exceptionIter.hasNext());
46+
assertThat(exceptionIter.next(), is(notNullValue()));
47+
assertTrue(exceptionIter.hasNext());
48+
assertThat(exceptionIter.next(), is(notNullValue()));
49+
assertFalse(exceptionIter.hasNext());
50+
}
51+
52+
@Test
53+
public void repeatIteration() {
54+
final Exception e1 = new Exception("first exception");
55+
56+
final List<Throwable> exceptionList = new ArrayList<>();
57+
exceptionList.add(e1);
58+
59+
final AggregateException aggregateException = new AggregateException(exceptionList);
60+
61+
final Iterator<Throwable> exceptionIter = aggregateException.getExceptions().iterator();
62+
63+
assertTrue(exceptionIter.hasNext());
64+
assertThat(exceptionIter.next(), is(notNullValue()));
65+
assertFalse(exceptionIter.hasNext());
66+
67+
final Iterator<Throwable> repeatIter = aggregateException.getExceptions().iterator();
68+
assertTrue(repeatIter.hasNext());
69+
assertThat(repeatIter.next(), is(notNullValue()));
70+
assertFalse(repeatIter.hasNext());
71+
72+
}
73+
}

0 commit comments

Comments
 (0)