1616import static org .junit .Assert .assertTrue ;
1717
1818import java .util .Arrays ;
19+ import java .util .LinkedHashMap ;
1920import java .util .List ;
21+ import java .util .Map ;
2022
2123import org .eclipse .core .resources .IProject ;
2224import org .eclipse .core .runtime .NullProgressMonitor ;
2729
2830import com .microsoft .java .test .plugin .AbstractProjectsManagerBasedTest ;
2931import com .microsoft .java .test .plugin .model .Response ;
32+ import com .google .gson .Gson ;
3033
3134public class JUnitLaunchConfigurationDelegateTest extends AbstractProjectsManagerBasedTest {
3235
@@ -53,17 +56,17 @@ public void testAddOpensForAllSelectedPackagesInModularProject() throws Exceptio
5356 assertNotNull (firstTest );
5457 assertNotNull (secondTest );
5558
56- final String launchRequest = String . format (
57- "{ \" projectName\" :%s, \" testLevel \" :5, \" testKind \" :0, \" testNames \" :[%s,%s],"
58- + " \" testHandles \" :[%s,%s]}" ,
59- toJsonString ( javaProject . getElementName ()),
60- toJsonString ( firstTest . getFullyQualifiedName ()),
61- toJsonString ( secondTest .getFullyQualifiedName ()),
62- toJsonString ( firstTest . getHandleIdentifier ()),
63- toJsonString ( secondTest .getHandleIdentifier ()));
59+ final Map < String , Object > request = new LinkedHashMap <>();
60+ request . put ( " projectName" , javaProject . getElementName ());
61+ request . put ( "testLevel" , 5 );
62+ request . put ( "testKind" , 0 );
63+ request . put ( "testNames" , Arrays . asList (
64+ firstTest . getFullyQualifiedName (), secondTest .getFullyQualifiedName ()));
65+ request . put ( "testHandles" , Arrays . asList (
66+ firstTest . getHandleIdentifier (), secondTest .getHandleIdentifier ()));
6467
6568 final Response <JUnitLaunchArguments > response = JUnitLaunchUtils .resolveLaunchArgument (
66- Arrays .asList (launchRequest ), new NullProgressMonitor ());
69+ Arrays .asList (new Gson (). toJson ( request ) ), new NullProgressMonitor ());
6770
6871 assertEquals (0 , response .getStatus ());
6972 final List <String > vmArguments = Arrays .asList (response .getBody ().vmArguments );
@@ -79,7 +82,4 @@ public void testAddOpensForAllSelectedPackagesInModularProject() throws Exceptio
7982 assertEquals ("--add-opens" , vmArguments .get (vmArguments .indexOf (secondPackageOpen ) - 1 ));
8083 }
8184
82- private static String toJsonString (String value ) {
83- return "\" " + value .replace ("\\ " , "\\ \\ " ).replace ("\" " , "\\ \" " ) + "\" " ;
84- }
8585}
0 commit comments