Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TestEngine-specific context using type parameter
- Loading branch information
1 parent
28ffd5e
commit 57b3122
Showing
10 changed files
with
150 additions
and
50 deletions.
There are no files selected for viewing
13 changes: 11 additions & 2 deletions
13
junit-engine-api/src/main/java/org/junit/gen5/engine/Child.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,8 +1,17 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|
||
package org.junit.gen5.engine; | package org.junit.gen5.engine; | ||
|
|
||
public interface Child { | public interface Child<C extends Context> { | ||
|
|
||
Context execute(Context context) throws Throwable; | C execute(C context) throws Throwable; | ||
|
|
||
} | } |
35 changes: 10 additions & 25 deletions
35
junit-engine-api/src/main/java/org/junit/gen5/engine/Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,29 +1,14 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|
||
package org.junit.gen5.engine; | package org.junit.gen5.engine; | ||
|
|
||
import java.util.HashMap; | public interface Context { | ||
import java.util.Map; | |||
|
|||
public class Context { | |||
|
|||
private final Map<String, Object> map; | |||
|
|||
public Context() { | |||
this(new HashMap<>()); | |||
} | |||
|
|||
private Context(Map<String, Object> map) { | |||
this.map = map; | |||
} | |||
|
|||
public Context with(String key, Object value) { | |||
Map<String, Object> newMap = new HashMap<>(map); | |||
newMap.put(key, value); | |||
return new Context(newMap); | |||
} | |||
|
|||
public <T> T get(String key, Class<T> clazz) { | |||
return clazz.cast(map.get(key)); | |||
} | |||
|
|||
} | } |
15 changes: 12 additions & 3 deletions
15
junit-engine-api/src/main/java/org/junit/gen5/engine/Parent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,10 +1,19 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|
||
package org.junit.gen5.engine; | package org.junit.gen5.engine; | ||
|
|
||
public interface Parent { | public interface Parent<C extends Context> { | ||
|
|
||
Context beforeAll(Context context); | C beforeAll(C context); | ||
|
|
||
Context afterAll(Context context); | C afterAll(C context); | ||
|
|
||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
junit5-engine/src/main/java/org/junit/gen5/engine/junit5/JUnit5Context.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.engine.junit5; | |||
|
|||
import java.util.HashMap; | |||
import java.util.Map; | |||
|
|||
import org.junit.gen5.engine.Context; | |||
|
|||
public class JUnit5Context implements Context { | |||
|
|||
private final Map<String, Object> map; | |||
|
|||
public JUnit5Context() { | |||
this(new HashMap<>()); | |||
} | |||
|
|||
private JUnit5Context(Map<String, Object> map) { | |||
this.map = map; | |||
} | |||
|
|||
public JUnit5Context withTestInstanceProvider(TestInstanceProvider testInstanceProvider) { | |||
return with(TestInstanceProvider.class.getName(), testInstanceProvider); | |||
} | |||
|
|||
public TestInstanceProvider getTestInstanceProvider() { | |||
return get(TestInstanceProvider.class.getName(), TestInstanceProvider.class); | |||
} | |||
|
|||
private JUnit5Context with(String key, Object value) { | |||
Map<String, Object> newMap = new HashMap<>(map); | |||
newMap.put(key, value); | |||
return new JUnit5Context(newMap); | |||
} | |||
|
|||
private <T> T get(String key, Class<T> clazz) { | |||
return clazz.cast(map.get(key)); | |||
} | |||
|
|||
} |
9 changes: 9 additions & 0 deletions
9
junit5-engine/src/main/java/org/junit/gen5/engine/junit5/JUnit5EngineDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
junit5-engine/src/main/java/org/junit/gen5/engine/junit5/TestInstanceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters