I have a Java class called TestInfoFinder
in Project1
that extends TestCase as below:
public class TestInfoFinder extends TestCase {
private ClassFinder classFinderService = null;
public void setUp() {
classFinderService = new ClassFinderService();
}
public List<Integer> testFindAnnotatedClassByPackage() throws ClassNotFoundException, NoSuchMethodException, SecurityException {
String pattern = "\\bid\\b=\\[(.+?)\\]";
Pattern r = Pattern.compile(pattern);
List<String> classFilePaths = classFinderService.findAnnotatedClassesInPackage("com.mobile.tests", TestInfo.class);
Set<String> set = new HashSet<>();
set.addAll(classFilePaths);
classFilePaths.clear();
classFilePaths.addAll(set);
List<Integer> myListIntegers = new ArrayList<Integer>();
for (String ids : classFilePaths) {
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher(ids);
while (m.find()) {
myListIntegers.add(Integer.parseInt(m.group()));
}
}
for(int str: myListIntegers)
{
System.out.println(str);
}
return myListIntegers;
}
}
Uses ClassFinderService
class and its method findAnnotatedClassesInPackage()
and this class is in another project Project2
and not Project1
.
TestInfoFinder
class initially finds annotations
in the package com.mobile.tests
and then creates a list called classFilePaths
. Then I convert these String values of the classFilePaths list into the integer ones(which is what I want) and I store them in myListIntegers
list. Above all is the part of first Java project say Project1
Now, I have another project say Project2
that has a class called Integration.java and it has a method as:
public static String addRun() {
........
...
List<Integer> cases = new ArrayList<Integer>();
for (int index=0; index < myListIntegers.length; index++)
{
cases.add(myListIntegers[index]);
}
}
In above snippet, myListIntegers
should come from my Project1's
class returned List (from TestInfoFinder class)
For above scenario of Project1 and Project2, how can I use the returned list
from Project1
into the Project 2
? Also, is there a better approach to modify the class TestInfoFinder
in Project1 (as of now, I have to run the entire class to get the list, rather something else would be better for my objective)?