};
protected JUnitTest ensureJunitTest(JavaMethodTester javaMethodTester, String testsAnnotation, Iterable<Member> methodParents, AbstractRequirement reqParent) {
// create and initialize JUnit test
JUnitTest testReq = JexFactory.eINSTANCE.createJUnitTest();
testReq.setText("Test");
javaMethodTester.setReturnType("void");
testReq.setJavaElement(javaMethodTester);
testReq.setTestRunnable(javaMethodTester);
reqParent.getRequirements().add(testReq);
JavaClass methodParent = null;
for (Member member : methodParents) {
if (member instanceof JavaClass) {
methodParent = (JavaClass) member;
break;
}
}
// add java elements and requirements for the tested elements
String[] testedElements = testsAnnotation.split(";");
for (int i = 0; i < testedElements.length; i++) {
String testedElementName = testedElements[i].trim();
String returnType = null, modifiers = null;
for (int j = 0; j < visibilityPrefixes.length; j += 2) {
String prefix = visibilityPrefixes[j];
if (testedElementName.startsWith(prefix)) {
modifiers = visibilityPrefixes[j + 1];
testedElementName = testedElementName.substring(prefix.length());
break;
}
}
testReq.setText(testReq.getText() + (i == 0 ? " " : ", ") + testedElementName);
int pos1 = testedElementName.indexOf('('), pos = testedElementName.lastIndexOf(' ', pos1 >= 0 ? pos1 : testedElementName.length());
if (pos >= 0) {
returnType = testedElementName.substring(0, pos);
pos1 -= pos + 1;
testedElementName = testedElementName.substring(pos + 1);
}
int pos2 = testedElementName.lastIndexOf(')');
Member testedElement = null;
if (pos1 >= 0 && pos2 >= 0) {
String[] params = {}, exceptions = {};
if (pos2 > pos1 + 2) {
params = parseTypeList(testedElementName.substring(pos1 + 1, pos2));
}
String THROWS_KEYWORD = "throws ";
int pos3 = testedElementName.indexOf(THROWS_KEYWORD, pos2);
if (pos3 >= pos2) {
exceptions = parseTypeList(testedElementName.substring(pos3 + THROWS_KEYWORD.length()));
}
testedElementName = testedElementName.substring(0, pos1);
if (methodParent == null) {
continue;
}
if (testedElementName != methodParent.getName() && returnType == null) {
returnType = "void";
}
JavaMethod javaMethod = (JavaMethod) ensureJavaMethod(testedElementName, returnType, params, exceptions, methodParent.getMembers());
testedElement = javaMethod;
} else {
JavaField javaField = (JavaField) ensureJavaElement(testedElementName, methodParent.getMembers(), JexPackage.eINSTANCE.getJavaField());
javaField.setType(returnType);
testedElement = javaField;
}
javaMethodTester.getTestedElements().add(testedElement);
JavaRequirement javaReq = JexFactory.eINSTANCE.createJavaRequirement();
javaReq.setText("Requires " + testedElements[i].trim());
javaReq.setJavaElement(testedElement);
if (modifiers != null) {
testedElement.setModifiers((Integer) JexFactory.eINSTANCE.createFromString(JexPackage.eINSTANCE.getModifiers(), modifiers));
} else {
javaReq.setRequiredFeatures("!modifiers");
}
testReq.getRequirements().add(javaReq);
}
return testReq;
}