@Override public boolean equals(Object other) { if (!(other instanceof AccessLevel)) { return false; } AccessLevel otherLevel = (AccessLevel) other; return getName().equals(otherLevel.getName()); }
/** Basic test for {@link AccessLevel#equals(Object)}. */ @Test public void equalsTest() throws ComponentLookupException { // Equals itself Assert.assertTrue( this.mocker.getComponentUnderTest().equals(this.mocker.getComponentUnderTest())); // Never equals null Assert.assertFalse(this.mocker.getComponentUnderTest().equals(null)); // Equals another level with the same name AccessLevel other = mock(AccessLevel.class); when(other.getName()).thenReturn("view", "edit"); Assert.assertTrue(this.mocker.getComponentUnderTest().equals(other)); // Doesn't equal a level with a different name Assert.assertFalse(this.mocker.getComponentUnderTest().equals(other)); // Doesn't equal other types of objects Assert.assertFalse(this.mocker.getComponentUnderTest().equals("view")); }