Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,31 +401,35 @@ private static String getDefaultTestFullyQualifiedName(ITypeBinding typeBinding,
IClasspathEntry testEntry) throws JavaModelException {
final String defaultName = typeBinding.getBinaryName() + "Test";
final String attemptName = typeBinding.getBinaryName() + "Tests";
ICompilationUnit testCompilationUnit = getTestCompilationUnit(project, testEntry, attemptName);
if (testCompilationUnit.exists()) {
return attemptName;
}

testCompilationUnit = getTestCompilationUnit(project, testEntry, defaultName);
if (testCompilationUnit.exists()) {
return defaultName;
}

// check the majority naming under the package and use it as the default type name
final IPackageFragment packageFragment = (IPackageFragment) testCompilationUnit.getParent();
int counter = 0;
final ICompilationUnit[] compilationUnits = packageFragment.getCompilationUnits();
for (final ICompilationUnit unit : compilationUnits) {
final String name = unit.getElementName();
if (name.endsWith("Tests.java")) {
counter++;
} else if (name.endsWith("Test.java")) {
counter--;
try {
ICompilationUnit testCompilationUnit = getTestCompilationUnit(project, testEntry, attemptName);
if (testCompilationUnit.exists()) {
return attemptName;
}

testCompilationUnit = getTestCompilationUnit(project, testEntry, defaultName);
if (testCompilationUnit.exists()) {
return defaultName;
}
}

if (counter > 0) {
return attemptName;
// check the majority naming under the package and use it as the default type name
final IPackageFragment packageFragment = (IPackageFragment) testCompilationUnit.getParent();
int counter = 0;
final ICompilationUnit[] compilationUnits = packageFragment.getCompilationUnits();
for (final ICompilationUnit unit : compilationUnits) {
final String name = unit.getElementName();
if (name.endsWith("Tests.java")) {
counter++;
} else if (name.endsWith("Test.java")) {
counter--;
}
}

if (counter > 0) {
return attemptName;
}
} catch (JavaModelException e) {
// ignore exception, for example: when packageFragment does not exist
}

return defaultName;
Expand Down