12 changed files with 42 additions and 334 deletions
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
|
||||
import java.lang.reflect.Array; |
||||
|
||||
/** |
||||
* Reflective mirror of JUnit 5's {@code Launcher}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @since 2.2.0 |
||||
*/ |
||||
public class Launcher extends ReflectiveWrapper { |
||||
|
||||
private final Class<?> testExecutionListenerType; |
||||
|
||||
private final Object instance; |
||||
|
||||
public Launcher(ClassLoader classLoader) throws Throwable { |
||||
super(classLoader, "org.junit.platform.launcher.Launcher"); |
||||
this.testExecutionListenerType = loadClass("org.junit.platform.launcher.TestExecutionListener"); |
||||
Class<?> factoryClass = loadClass("org.junit.platform.launcher.core.LauncherFactory"); |
||||
this.instance = factoryClass.getMethod("create").invoke(null); |
||||
} |
||||
|
||||
public void registerTestExecutionListeners(SummaryGeneratingListener listener) throws Throwable { |
||||
Object listeners = Array.newInstance(this.testExecutionListenerType, 1); |
||||
Array.set(listeners, 0, listener.instance); |
||||
this.type.getMethod("registerTestExecutionListeners", listeners.getClass()).invoke(this.instance, listeners); |
||||
} |
||||
|
||||
public void execute(LauncherDiscoveryRequest request) throws Throwable { |
||||
Object listeners = Array.newInstance(this.testExecutionListenerType, 0); |
||||
this.type.getMethod("execute", request.type, listeners.getClass()).invoke(this.instance, request.instance, |
||||
listeners); |
||||
} |
||||
|
||||
} |
||||
@ -1,34 +0,0 @@
@@ -1,34 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
|
||||
/** |
||||
* Reflective mirror of JUnit 5's {@code LauncherDiscoveryRequest}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @since 2.2.0 |
||||
*/ |
||||
public class LauncherDiscoveryRequest extends ReflectiveWrapper { |
||||
|
||||
final Object instance; |
||||
|
||||
LauncherDiscoveryRequest(ClassLoader classLoader, Object instance) throws Throwable { |
||||
super(classLoader, "org.junit.platform.launcher.LauncherDiscoveryRequest"); |
||||
this.instance = instance; |
||||
} |
||||
|
||||
} |
||||
@ -1,54 +0,0 @@
@@ -1,54 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
import org.junit.platform.engine.DiscoverySelector; |
||||
|
||||
/** |
||||
* Reflective mirror of JUnit 5's {@code LauncherDiscoveryRequestBuilder}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @since 2.2.0 |
||||
*/ |
||||
public class LauncherDiscoveryRequestBuilder extends ReflectiveWrapper { |
||||
|
||||
final Object instance; |
||||
|
||||
public LauncherDiscoveryRequestBuilder(ClassLoader classLoader) throws Throwable { |
||||
super(classLoader, "org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder"); |
||||
this.instance = this.type.getMethod("request").invoke(null); |
||||
} |
||||
|
||||
LauncherDiscoveryRequestBuilder(ClassLoader classLoader, Class<?> type, Object instance) throws Throwable { |
||||
super(classLoader, type); |
||||
this.instance = instance; |
||||
} |
||||
|
||||
public LauncherDiscoveryRequestBuilder selectors(DiscoverySelector... selectors) throws Throwable { |
||||
Class<?>[] parameterTypes = { DiscoverySelector[].class }; |
||||
Method method = this.type.getMethod("selectors", parameterTypes); |
||||
return new LauncherDiscoveryRequestBuilder(getClassLoader(), this.type, |
||||
method.invoke(this.instance, new Object[] { selectors })); |
||||
} |
||||
|
||||
public LauncherDiscoveryRequest build() throws Throwable { |
||||
return new LauncherDiscoveryRequest(getClassLoader(), this.type.getMethod("build").invoke(this.instance)); |
||||
} |
||||
|
||||
} |
||||
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
|
||||
import org.springframework.util.ClassUtils; |
||||
|
||||
/** |
||||
* Base class for all reflective wrappers. |
||||
* |
||||
* @author Phillip Webb |
||||
*/ |
||||
class ReflectiveWrapper { |
||||
|
||||
final ClassLoader classLoader; |
||||
|
||||
final Class<?> type; |
||||
|
||||
ReflectiveWrapper(ClassLoader classLoader, String type) throws Throwable { |
||||
this.classLoader = classLoader; |
||||
this.type = loadClass(type); |
||||
} |
||||
|
||||
protected ReflectiveWrapper(ClassLoader classLoader, Class<?> type) throws Throwable { |
||||
this.classLoader = classLoader; |
||||
this.type = type; |
||||
} |
||||
|
||||
protected final ClassLoader getClassLoader() { |
||||
return this.classLoader; |
||||
} |
||||
|
||||
protected final Class<?> loadClass(String type) throws ClassNotFoundException, LinkageError { |
||||
return ClassUtils.forName(type, this.classLoader); |
||||
} |
||||
|
||||
} |
||||
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
|
||||
/** |
||||
* Reflective mirror of JUnit 5's {@code SummaryGeneratingListener}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @since 2.2.0 |
||||
*/ |
||||
public class SummaryGeneratingListener extends ReflectiveWrapper { |
||||
|
||||
final Object instance; |
||||
|
||||
public SummaryGeneratingListener(ClassLoader classLoader) throws Throwable { |
||||
super(classLoader, "org.junit.platform.launcher.listeners.SummaryGeneratingListener"); |
||||
this.instance = this.type.newInstance(); |
||||
} |
||||
|
||||
public TestExecutionSummary getSummary() throws Throwable { |
||||
return new TestExecutionSummary(getClassLoader(), this.type.getMethod("getSummary").invoke(this.instance)); |
||||
} |
||||
|
||||
} |
||||
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.util.CollectionUtils; |
||||
|
||||
/** |
||||
* Reflective mirror of JUnit 5's {@code TestExecutionSummary}. |
||||
* |
||||
* @author Phillip Webb |
||||
* @since 2.2.0 |
||||
*/ |
||||
public class TestExecutionSummary extends ReflectiveWrapper { |
||||
|
||||
private final Class<?> failureType; |
||||
|
||||
private final Object instance; |
||||
|
||||
TestExecutionSummary(ClassLoader classLoader, Object instance) throws Throwable { |
||||
super(classLoader, "org.junit.platform.launcher.listeners.TestExecutionSummary"); |
||||
this.failureType = loadClass("org.junit.platform.launcher.listeners.TestExecutionSummary$Failure"); |
||||
this.instance = instance; |
||||
} |
||||
|
||||
public Throwable getFailure() throws Throwable { |
||||
List<?> failures = (List<?>) this.type.getMethod("getFailures").invoke(this.instance); |
||||
if (!CollectionUtils.isEmpty(failures)) { |
||||
Object failure = failures.get(0); |
||||
return (Throwable) this.failureType.getMethod("getException").invoke(failure); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
@ -1,21 +0,0 @@
@@ -1,21 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2019 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
/** |
||||
* Reflective mirror of JUnit 5 classes required to workaround surefire bug |
||||
* {@code SUREFIRE-1679}. |
||||
*/ |
||||
package org.springframework.boot.testsupport.junit.platform; |
||||
Loading…
Reference in new issue