Election { @Override public boolean equals(Object obj) { if(obj instanceof Election) { Election that = (Election) obj; return this.getPlace().equals(that.getPlace()) && this.getKind().equals(that.getKind()) && this.getAsset().getName().equals(that.getAsset().getName()); } else { return false; } } Election(String kind, String place, Asset asset); String getKind(); String getPlace(); Asset getAsset(); static Election parseElection(Asset a, Context context); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); public String kind; public String place; public Asset asset; }
@Test public void equalsActualEqual() throws Exception { Election e1 = new Election("Delft", "Municipal election", new Asset("G_Delft", mockHash)); Election e2 = new Election("Delft", "Municipal election", new Asset("G_Delft", mockHash)); assertTrue(e1.equals(e2)); }
@Test public void equalsNonEqualPlace() throws Exception { Election e1 = new Election("Delft", "Municipal election", new Asset("G_Delft", mockHash)); Election e2 = new Election("Delft", "Municipal election", new Asset("G_Delft", mockHash)); assertTrue(e1.equals(e2)); }
@Test public void equalsNonEqualKind() throws Exception { Election e1 = new Election("Delft", "Municipal election", new Asset("G_Delft", mockHash)); Election e2 = new Election("Delft", "Provincial election", new Asset("G_Delft", mockHash)); assertFalse(e1.equals(e2)); }
@Test public void equalsNonEqualAssetName() throws Exception { Election e1 = new Election("Delft", "Municipal election", new Asset("G_Delft", mockHash)); Election e2 = new Election("Delft", "Municipal election", new Asset("T_Delft", mockHash)); assertFalse(e1.equals(e2)); }