Java class hierarchy as test data is not working - unit test

Hello,

I have setup a unit test for testing my completion code and part of the code is showing a list of methods for a bean and it's super classes. It's working fine in production, but I can't seem to get it to work when I setup test data with super class and sub class, it does not recognise the super class when running the test case

What I'm missing here ?

CompleteJavaBeanSuperClassTestData.java
package testData;

public class CompleteJavaBeanSuperClassTestData {

public boolean mySuperMethod() {
mySuperAbstractMethod();
return false;
}

public abstract void mySuperAbstractMethod();
}

MyJavaBeanTestData.java
public class MyJavaBeanTestData extends CompleteJavaBeanSuperClassTestData {

public void letsDoThis() {}
public void anotherBeanMethod() {}
public void mySuperAbstractMethod() {}

private void thisIsVeryPrivate() {}

}
My test case:

public void testJavaBeanTestDataCompletionFile() {
myFixture.configureByFiles("CompleteJavaBeanRouteTestData.java", "CompleteJavaBeanTestData.java","CompleteJavaBeanSuperClassTestData.java");
myFixture.complete(CompletionType.BASIC, 1);
List<String> strings = myFixture.getLookupElementStrings();
assertThat(strings, Matchers.not(Matchers.contains("thisIsVeryPrivate")));
assertThat(strings, Matchers.hasItems("letsDoThis", "anotherBeanMethod", "mySuperAbstractMethod", "mySuperMethod"));
assertEquals("There is many options", 4, strings.size());
}

Thanks!

/Flemming

0

Hi Flemming,

I guess something went wrong with the post. I don't see how the classes you put in configureByFiles are connected to the test data above. MyJavaBeanTestData is in the default package and it's super class is not visible there. There is no caret position in the test data, so I am not sure what Fixture#complete is expected to do.

Hope this still helps somehow

Anna

0
Avatar
Permanently deleted user

Hi Anna

Sorry for the sloppy post :-| and I still have no clue why it's not working

I didn't listen the file was where the "<caret>" was in CompleteJavaBeanRouteTestData and I missed the "package TestData" in the super class when I copied the code, but it's there.

The Fixture#complete return "anotherBeanMethod", "letsDoThis", "mySuperAbstractMethod", but I also expect the "mySuperMethod". If I debug the code in my completion code the PsiClass(MyJavaBeanTestData) dosen't have any super classes.

My test files are placed in 

@Override
protected String getTestDataPath() {
return "src/test/resources/testData/";
}

The test case:

public void testJavaBeanTestDataCompletionFile() {
myFixture.configureByFiles("CompleteJavaBeanRouteTestData.java", "CompleteJavaBeanTestData.java","CompleteJavaBeanSuperClassTestData.java");
myFixture.complete(CompletionType.BASIC, 1);
List<String> strings = myFixture.getLookupElementStrings();
assertThat(strings, Matchers.not(Matchers.contains("thisIsVeryPrivate")));
assertThat(strings, Matchers.hasItems("letsDoThis", "anotherBeanMethod", "mySuperAbstractMethod", "mySuperMethod"));
assertEquals("There is many options", 4, strings.size());
}
package testData;

public final class CompleteJavaBeanRouteTestData extends RouteBuilder {

@Override
public void configure() {
from("file:inbox")
.bean(MyJavaBeanTestData.class, "<caret>")
.to("log:out");
}
}
package testData;

public class CompleteJavaBeanSuperClassTestData {

public boolean mySuperMethod() {
mySuperAbstractMethod();
return false;
}

public abstract void mySuperAbstractMethod();
}

public class MyJavaBeanTestData extends CompleteJavaBeanSuperClassTestData {

public void letsDoThis() {}
public void anotherBeanMethod() {}
public void mySuperAbstractMethod() {}

private void thisIsVeryPrivate() {}

}

 

0

How MyJavaBeanTestData is added to the project? It still lacks the package statement/import...

0
Avatar
Permanently deleted user

The MyJavaBeanTestData was added but the real name of the file was wrong and second I forgot to "import testData.CompleteJavaBeanSuperClassTestData;" in the MyJavaBeanTestData.java :-|

It's working now.

 

Thanks!

0

请先登录再写评论。