Skip to content

Commit ec904ef

Browse files
committed
Add unit tests for ComplexPropertyCollection.complexPropertyChanged
1 parent ee006d5 commit ec904ef

3 files changed

Lines changed: 61 additions & 10 deletions

File tree

src/main/java/microsoft/exchange/webservices/data/property/complex/ComplexProperty.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,18 @@ protected void clearChangeEvents() {
372372
/**
373373
* Implements ISelfValidate.validate. Validates this instance.
374374
*
375-
* @throws ServiceValidationException the service validation exception
376-
* @throws Exception the exception
375+
* @throws Exception the exception
377376
*/
378-
public void validate() throws ServiceValidationException, Exception {
377+
public void validate() throws Exception {
379378
this.internalValidate();
380379
}
381380

382381
/**
383382
* Validates this instance.
384383
*
385-
* @throws ServiceValidationException the service validation exception
386-
* @throws Exception
384+
* @throws Exception the exception
387385
*/
388-
protected void internalValidate() throws ServiceValidationException, Exception {
386+
protected void internalValidate() throws Exception {
389387
}
390388

391389
public Boolean func(EwsServiceXmlReader reader) throws Exception {

src/main/java/microsoft/exchange/webservices/data/property/complex/ComplexPropertyCollection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ public abstract class ComplexPropertyCollection
5353
/**
5454
* The item.
5555
*/
56-
private List<TComplexProperty> items = new ArrayList<TComplexProperty>();
56+
private final List<TComplexProperty> items = new ArrayList<TComplexProperty>();
5757

5858
/**
5959
* The added item.
6060
*/
61-
private List<TComplexProperty> addedItems =
61+
private final List<TComplexProperty> addedItems =
6262
new ArrayList<TComplexProperty>();
6363

6464
/**
6565
* The modified item.
6666
*/
67-
private List<TComplexProperty> modifiedItems =
67+
private final List<TComplexProperty> modifiedItems =
6868
new ArrayList<TComplexProperty>();
6969

7070
/**
7171
* The removed item.
7272
*/
73-
private List<TComplexProperty> removedItems =
73+
private final List<TComplexProperty> removedItems =
7474
new ArrayList<TComplexProperty>();
7575

7676
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package microsoft.exchange.webservices.data.property.complex;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.junit.runners.JUnit4;
7+
8+
import java.util.List;
9+
10+
/**
11+
* @author Vladislav Bauer
12+
*/
13+
14+
@RunWith(JUnit4.class)
15+
public class ComplexPropertyCollectionTest {
16+
17+
@Test
18+
public void testComplexPropertyChangedPositive() {
19+
final ComplexPropertyCollection<ComplexProperty> collection = createFakeComplexPropertyCollection();
20+
21+
final ComplexProperty property = createFakeComplexProperty();
22+
collection.complexPropertyChanged(property);
23+
24+
final List<ComplexProperty> modifiedItems = collection.getModifiedItems();
25+
Assert.assertTrue(collection.getAddedItems().isEmpty());
26+
Assert.assertTrue(modifiedItems.contains(property));
27+
Assert.assertEquals(1, modifiedItems.size());
28+
}
29+
30+
@Test(expected = RuntimeException.class)
31+
public void testComplexPropertyChangedNegative() {
32+
final ComplexPropertyCollection<ComplexProperty> collection = createFakeComplexPropertyCollection();
33+
collection.complexPropertyChanged(null);
34+
Assert.fail();
35+
}
36+
37+
38+
private ComplexProperty createFakeComplexProperty() {
39+
return new ComplexProperty() {};
40+
}
41+
42+
private ComplexPropertyCollection<ComplexProperty> createFakeComplexPropertyCollection() {
43+
return new ComplexPropertyCollection<ComplexProperty>() {
44+
@Override protected ComplexProperty createComplexProperty(final String xmlElementName) {
45+
return null;
46+
}
47+
@Override protected String getCollectionItemXmlElementName(final ComplexProperty complexProperty) {
48+
return null;
49+
}
50+
};
51+
}
52+
53+
}

0 commit comments

Comments
 (0)