-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fe8877
commit d9a985b
Showing
8 changed files
with
211 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
protege-editor-core/src/main/java/org/protege/editor/core/ui/menu/PopupMenuId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.protege.editor.core.ui.menu; | ||
|
||
import java.util.Objects; | ||
|
||
import static com.google.common.base.MoreObjects.toStringHelper; | ||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 05/03/16 | ||
*/ | ||
public class PopupMenuId { | ||
|
||
private final String id; | ||
|
||
public PopupMenuId(String id) { | ||
this.id = checkNotNull(id); | ||
checkArgument(id.startsWith("["), "PopupMenuIds must start with '['"); | ||
checkArgument(id.endsWith("]"), "PopupMenuIds must end with ']'"); | ||
} | ||
|
||
/** | ||
* Tests whether an id is a popup menu Id. Popup menu ids start with '[' and end with ']' | ||
* @param id The id to test. Not {@code null}. | ||
* @return true if the id is a popup menu Id, otherwise false. | ||
*/ | ||
public static boolean isPopupMenuId(String id) { | ||
return id.startsWith("[") && id.endsWith("]"); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) { | ||
return true; | ||
} | ||
if (!(obj instanceof PopupMenuId)) { | ||
return false; | ||
} | ||
PopupMenuId other = (PopupMenuId) obj; | ||
return this.id.equals(other.id); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return toStringHelper("PopupMenuId") | ||
.addValue(id) | ||
.toString(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
protege-editor-core/src/test/java/org/protege/editor/core/ui/menu/PopupMenuId_TestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
package org.protege.editor.core.ui.menu; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.startsWith; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class PopupMenuId_TestCase { | ||
|
||
private PopupMenuId popupMenuId; | ||
private String id = "[The id]"; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
popupMenuId = new PopupMenuId(id); | ||
} | ||
|
||
@Test(expected = java.lang.NullPointerException.class) | ||
public void shouldThrowNullPointerExceptionIf_id_IsNull() { | ||
new PopupMenuId(null); | ||
} | ||
|
||
@Test | ||
public void shouldReturnSupplied_id() { | ||
assertThat(popupMenuId.getId(), is(this.id)); | ||
} | ||
|
||
@Test | ||
public void shouldBeEqualToSelf() { | ||
assertThat(popupMenuId, is(popupMenuId)); | ||
} | ||
|
||
@Test | ||
public void shouldNotBeEqualToNull() { | ||
assertThat(popupMenuId.equals(null), is(false)); | ||
} | ||
|
||
@Test | ||
public void shouldBeEqualToOther() { | ||
assertThat(popupMenuId, is(new PopupMenuId(id))); | ||
} | ||
|
||
@Test | ||
public void shouldNotBeEqualToOtherThatHasDifferent_id() { | ||
assertThat(popupMenuId, is(not(new PopupMenuId("[b4d7ddab-7759-43c9-a349-e9ee36423b70]")))); | ||
} | ||
|
||
@Test | ||
public void shouldBeEqualToOtherHashCode() { | ||
assertThat(popupMenuId.hashCode(), is(new PopupMenuId(id).hashCode())); | ||
} | ||
|
||
@Test | ||
public void shouldImplementToString() { | ||
assertThat(popupMenuId.toString(), startsWith("PopupMenuId")); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void shouldThrowExceptionForIllegalStart() { | ||
new PopupMenuId("TheInvalidId]"); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void shouldThrowExceptionForIllegalEnd() { | ||
new PopupMenuId("[TheInvalidId"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters