Skip to content

Commit

Permalink
fix AbstractSlot#equals method which incorrectly compared the class (#45
Browse files Browse the repository at this point in the history
)

* fix AbstractSlot#equals method which incorrectly compared the class

* improve coverage on AbstractSlotTest
  • Loading branch information
will-molloy authored Apr 16, 2020
1 parent 75eb2fa commit 73e9d91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final boolean equals(Object o)
{
return true;
}
if (o == null || getClass() != o.getClass())
if (!(o instanceof Slot))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ public Optional<SlotMatch<String>> match(String token, Context context)
}
}

private static final class TestSlot2 extends AbstractSlot<String>
{
protected TestSlot2(String name)
{
super(name);
}

@Override
public Optional<SlotMatch<String>> match(String token, Context context)
{
return Optional.empty();
}
}

@Test
public void testGetName()
{
Expand All @@ -50,8 +64,12 @@ public void testEquals()
Slot<String> slot = new TestSlot("my-slot");
Slot<String> slotWithSameName = new TestSlot("my-slot");
Slot<String> slotWithDifferentName = new TestSlot("my-slot-2");
Slot<String> slotWithSameNameDifferentClass = new TestSlot2("my-slot");
assertEquals(slot, slotWithSameName);
assertNotEquals(slot, slotWithDifferentName);
assertEquals(slot, slotWithSameNameDifferentClass);
assertEquals(slot, slot);
assertNotEquals(slot, 1);
}

@Test
Expand Down

0 comments on commit 73e9d91

Please sign in to comment.