Skip to content

Commit 0e02bde

Browse files
Hélios GILLESRoiSoleil
authored andcommitted
Support testing against interfaces instead of implementations
- Fix not working cases
1 parent 2a7c323 commit 0e02bde

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

org.moreunit.plugin/src/org/moreunit/matching/CorrespondingTypeSearcher.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ private Collection<IType> findPotentialTargets(boolean withLikelyMatches) throws
8686
boolean qualifyWithPackage = ! withLikelyMatches;
8787
Set<String> patterns = new LinkedHashSet<>(nameEvaluation.getAllCorrespondingClassPatterns(qualifyWithPackage));
8888

89+
Set<IType> matches = SearchTools.searchFor(patterns, searchScope);
90+
91+
if(matches.size() == 1 && ! matches.iterator().next().isInterface())
92+
{
93+
return matches;
94+
}
95+
8996
if(type != null && ! nameEvaluation.isTestCase())
9097
{
9198
try
@@ -119,7 +126,7 @@ private Collection<IType> findPotentialTargets(boolean withLikelyMatches) throws
119126
}
120127
}
121128

122-
Set<IType> matches = SearchTools.searchFor(patterns, searchScope);
129+
matches = SearchTools.searchFor(patterns, searchScope);
123130

124131
if(nameEvaluation.isTestCase())
125132
{

org.moreunit.test/test/org/moreunit/matching/InterfaceCorrespondingTypeSearcherTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Collection;
66

77
import org.eclipse.jdt.core.IType;
8+
import org.eclipse.jdt.core.JavaModelException;
89
import org.junit.Test;
910
import org.moreunit.test.context.ContextTestCase;
1011
import org.moreunit.test.context.Preferences;
@@ -15,7 +16,7 @@ public class InterfaceCorrespondingTypeSearcherTest extends ContextTestCase
1516
{
1617
@Project(mainCls = "class Foo", testCls = "FooTest")
1718
@Test
18-
public void getMatches_should_return_test_for_class() throws Exception
19+
public void getMatches_should_return_test_for_class()
1920
{
2021
CorrespondingTypeSearcher searcher = new CorrespondingTypeSearcher(context.getCompilationUnit("Foo"), getPreferences());
2122
Collection<IType> matches = searcher.getMatches(false);
@@ -25,7 +26,7 @@ public void getMatches_should_return_test_for_class() throws Exception
2526

2627
@Project(mainCls = "interface Foo", testCls = "FooTest")
2728
@Test
28-
public void getMatches_should_return_test_for_interface() throws Exception
29+
public void getMatches_should_return_test_for_interface()
2930
{
3031
context.getPrimaryTypeHandler("Foo").createSubclass("FooImpl");
3132

@@ -37,7 +38,7 @@ public void getMatches_should_return_test_for_interface() throws Exception
3738

3839
@Project(mainCls = "interface Foo", testCls = "FooTest")
3940
@Test
40-
public void getMatches_should_return_implementation_for_interface_test_and_exclude_interface() throws Exception
41+
public void getMatches_should_return_implementation_for_interface_test_and_exclude_interface()
4142
{
4243
context.getPrimaryTypeHandler("Foo").createSubclass("FooImpl");
4344

@@ -50,7 +51,7 @@ public void getMatches_should_return_implementation_for_interface_test_and_exclu
5051

5152
@Project(mainCls = "interface Foo", testCls = "FooTest")
5253
@Test
53-
public void getMatches_should_return_interface_test_for_implementation() throws Exception
54+
public void getMatches_should_return_interface_test_for_implementation()
5455
{
5556
context.getPrimaryTypeHandler("Foo").createSubclass("FooImpl");
5657

@@ -62,7 +63,7 @@ public void getMatches_should_return_interface_test_for_implementation() throws
6263

6364
@Project(mainCls = "interface Foo")
6465
@Test
65-
public void getMatches_should_return_interface_for_implementation_test() throws Exception
66+
public void getMatches_should_return_interface_for_implementation_test()
6667
{
6768
context.getPrimaryTypeHandler("Foo").createSubclass("FooImpl");
6869
context.getProjectHandler().getTestSrcFolderHandler().createClass("FooImplTest");
@@ -75,7 +76,7 @@ public void getMatches_should_return_interface_for_implementation_test() throws
7576

7677
@Project(mainCls = "interface Foo", testCls = "FooTest")
7778
@Test
78-
public void getMatches_should_include_interface_if_it_has_default_method() throws Exception
79+
public void getMatches_should_include_interface_if_it_has_default_method() throws JavaModelException
7980
{
8081
IType foo = context.getPrimaryTypeHandler("Foo").get();
8182
foo.createMethod("default void bar() {}", null, true, null);

0 commit comments

Comments
 (0)