This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROO-2850: Tab completion ignores some available commands - reverted p…
…revious fix, implemented equals and hashCode properly in MethodTarget instead
- Loading branch information
Andrew Swan
committed
Oct 26, 2011
1 parent
b6210bc
commit 1195a76
Showing
4 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
shell/src/main/java/org/springframework/roo/shell/CommandMarker.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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
package org.springframework.roo.shell; | ||
|
||
/** | ||
* Marker interface indicating a provider of one or more shell commands. | ||
*/ | ||
public interface CommandMarker {} |
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
52 changes: 52 additions & 0 deletions
52
shell/src/test/java/org/springframework/roo/shell/MethodTargetTest.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,52 @@ | ||
package org.springframework.roo.shell; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test of {@link MethodTarget} | ||
* | ||
* @author Andrew Swan | ||
* @since 1.2.0 | ||
*/ | ||
public class MethodTargetTest { | ||
|
||
// Constants | ||
private static final Object TARGET_1 = new CommandMarker() {}; | ||
private static final Object TARGET_2 = new CommandMarker() {}; | ||
private static final Method METHOD_1 = TARGET_1.getClass().getMethods()[0]; // unmockable | ||
private static final Method METHOD_2 = TARGET_2.getClass().getMethods()[1]; // unmockable | ||
|
||
@Test | ||
public void testInstanceEqualsItself() { | ||
final MethodTarget instance = new MethodTarget(METHOD_1, TARGET_1); | ||
assertEquals(instance, instance); | ||
} | ||
|
||
@Test | ||
public void testInstanceDoesNotEqualNull() { | ||
assertFalse(new MethodTarget(METHOD_1, TARGET_1).equals(null)); | ||
} | ||
|
||
@Test | ||
public void testInstancesWithSameMethodAndTargetAreEqualAndHaveSameHashCode() { | ||
final MethodTarget instance1 = new MethodTarget(METHOD_1, TARGET_1, "the-buff", "the-key"); | ||
final MethodTarget instance2 = new MethodTarget(METHOD_1, TARGET_1); | ||
assertEquals(instance1, instance2); | ||
assertEquals(instance1.hashCode(), instance2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testInstancesWithDifferentMethodAreNotEqual() { | ||
assertFalse(new MethodTarget(METHOD_1, TARGET_1).equals(new MethodTarget(METHOD_2, TARGET_1))); | ||
} | ||
|
||
@Test | ||
public void testInstancesWithDifferentTargetAreNotEqual() { | ||
assertFalse(new MethodTarget(METHOD_1, TARGET_1).equals(new MethodTarget(METHOD_1, TARGET_2))); | ||
} | ||
} |