File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed
main/java/de/danielbechler/diff
test/java/de/danielbechler/diff Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 158158 <version >2.0M6</version >
159159 <scope >test</scope >
160160 </dependency >
161+ <dependency >
162+ <groupId >com.google.guava</groupId >
163+ <artifactId >guava</artifactId >
164+ <version >13.0.1</version >
165+ <scope >test</scope >
166+ </dependency >
161167 </dependencies >
162168
163169 <distributionManagement >
Original file line number Diff line number Diff line change @@ -157,7 +157,20 @@ public Class<?> getType()
157157 if (types .size () == 1 )
158158 {
159159 return Collections .firstElementOf (types );
160- }
160+ }
161+ if (types .size () > 1 )
162+ {
163+ // check for common Collection base type
164+ boolean areAllCollectionTypes = true ;
165+ for (Class <?> type : types ) {
166+ areAllCollectionTypes = Collection .class .isAssignableFrom (type );
167+ }
168+ if (areAllCollectionTypes )
169+ {
170+ return Collection .class ;
171+ }
172+ }
173+
161174 throw new IllegalStateException ("Detected instances of different types " + types + ". " +
162175 "Instances must either be null or have the exact same type." );
163176 // NOTE It would be nice to be able to define a least common denominator like Map or Collection to allow mixed types
Original file line number Diff line number Diff line change 1616
1717package de .danielbechler .diff ;
1818
19+ import com .google .common .collect .ImmutableSet ;
20+ import com .google .common .collect .Sets ;
1921import de .danielbechler .diff .mock .*;
2022import de .danielbechler .diff .node .*;
2123import de .danielbechler .diff .path .*;
@@ -127,4 +129,12 @@ public void testCompareWithChangedItem() throws Exception
127129 final Node child = node .getChild (propertyPath );
128130 assertThat (child .getState (), is (Node .State .CHANGED ));
129131 }
132+
133+ @ Test
134+ public void testCollectionBaseType () throws Exception {
135+ Set base = Sets .newHashSet ("one" , "two" );
136+ Set working = ImmutableSet .copyOf (Sets .newHashSet ("one" , "three" ));
137+ final CollectionNode node = differ .compare (base , working );
138+ assertThat (node .hasChanges (), is (true ));
139+ }
130140}
You can’t perform that action at this time.
0 commit comments