void invokeMain(BootstrappedInstanceProxy instanceProxy, ExecuteJobParameters executeJobParameters,
                    Method mainMethod, List<String> args)
            throws IllegalAccessException, InvocationTargetException {
        try {
            instanceProxy.setExecuteJobParameters(executeJobParameters);

            String[] jobArgs = args.toArray(new String[0]);

            // upcast args to Object, so it's passed as a single array-typed argument
            mainMethod.invoke(null, (Object) jobArgs);
        } finally {
            instanceProxy.removeExecuteJobParameters();
        }
    }
@Test
    public void testInvokeMain() throws InvocationTargetException, IllegalAccessException {
        HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
        AbstractJetInstance abstractJetInstance = mock(AbstractJetInstance.class);
        when(hazelcastInstance.getJet()).thenReturn(abstractJetInstance);
        when(abstractJetInstance.getHazelcastInstance()).thenReturn(hazelcastInstance);

        // Parameter for test
        BootstrappedInstanceProxy instanceProxy = createWithMemberJetProxy(hazelcastInstance);

        // Parameter for test. Empty main method
        MainMethodFinder mainMethodFinder = new MainMethodFinder();
        mainMethodFinder.getMainMethodOfClass(MemberExecuteJarTest.class);

        // Parameter for test
        String jarPath = "jarPath";
        String snapshotName = "snapshotName";
        String jobName = "jobName";

        ExecuteJobParameters executeJobParameters = new ExecuteJobParameters(jarPath, snapshotName, jobName);

        // Test that invokeMain removes thread local values in BootstrappedInstanceProxy
        MemberExecuteJar memberExecuteJar = new MemberExecuteJar();
        memberExecuteJar.invokeMain(instanceProxy,
                executeJobParameters,
                mainMethodFinder.mainMethod,
                Collections.singletonList("jobArgs")
        );

        BootstrappedJetProxy bootstrappedJetProxy = instanceProxy.getJet();
        ExecuteJobParameters parameters = bootstrappedJetProxy.getExecuteJobParameters();

        assertThat(parameters.getJarPath()).isNull();
        assertThat(parameters.getSnapshotName()).isNull();
        assertThat(parameters.getJobName()).isNull();
    }