Skip to content

Commit

Permalink
Change to GenericTypeCollection equality to not consider generic type…
Browse files Browse the repository at this point in the history
… name as it was causing a bug when overriding generic types. Fixes #33
  • Loading branch information
richkeenan committed May 3, 2017
1 parent 20e1b01 commit 173ccf6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;

GenericTypeCollection that = (GenericTypeCollection) o;
if (underlying.length != that.underlying.length) return false;

return length == that.length && nameTypeMap.equals(that.nameTypeMap) && Arrays.equals(underlying, that.underlying);
for (int i = 0; i < underlying.length; i++) {
if (!underlying[i].getType().equals(that.underlying[i].getType())) return false;
}

return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import testtypes.TypeWithProperties;
import testtypes.generic.TypeWithGenericField;

import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertSame;
Expand Down Expand Up @@ -44,4 +46,30 @@ public void does_not_auto_populate_properties_of_instance() {
assertNull(specimen.getSymbol());
assertEquals(0, specimen.getSize());
}

@Test
public void instance_customisation_works_will_null_instances_for_generic_types() {
JFixture fixture = new JFixture();
fixture.customise(new InstanceCustomisation<List<Contained>>(new SpecimenType<List<Contained>>(){}, null));

Container container = fixture.create(Container.class);

assertNull(container.list);
}

static class Container {
final List<Contained> list;

Container(List<Contained> list) {
this.list = list;
}
}

static class Contained {
final String name;

Contained(String name) {
this.name = name;
}
}
}

0 comments on commit 173ccf6

Please sign in to comment.