Skip to content

Commit

Permalink
Generify Precondition- and RetryConditionContext
Browse files Browse the repository at this point in the history
to include the actual specification type for instance
and shared (precondition only)
  • Loading branch information
leonard84 committed Oct 11, 2023
1 parent 985fe54 commit 3f893d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
import spock.lang.IgnoreIf;
import spock.lang.PendingFeatureIf;
import spock.lang.Requires;
import spock.lang.Specification;
import spock.util.environment.Jvm;
import spock.util.environment.OperatingSystem;

/**
* The context (delegate) for a {@link Requires}, {@link IgnoreIf} or {@link PendingFeatureIf} condition.
*/
public class PreconditionContext {
public class PreconditionContext<S extends Specification> {
private final Object theSharedInstance;
private final Object theInstance;
private final Map<String, Object> dataVariables;
Expand Down Expand Up @@ -88,11 +89,11 @@ public Jvm getJvm() {
* @since 2.0
* @return the test instance
*/
public Object getInstance() {
public S getInstance() {
if (theInstance == null) {
throw new InstanceContextException();
}
return theInstance;
return (S) theInstance;
}

/**
Expand All @@ -103,11 +104,11 @@ public Object getInstance() {
* @since 2.1
* @return the shared instance
*/
public Object getShared() {
public S getShared() {
if (theSharedInstance == null) {
throw new SharedContextException();
}
return theSharedInstance;
return (S) theSharedInstance;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.spockframework.runtime.extension.builtin;

import spock.lang.Specification;

/**
* The context (delegate) for a {@link spock.lang.Retry} condition.
*/
public class RetryConditionContext {
public class RetryConditionContext<S extends Specification> {

private final Object instance;
private final Throwable failure;
Expand All @@ -27,8 +29,8 @@ public Throwable getFailure() {
*
* @return the current {@code Specification} instance
*/
public Object getInstance() {
return instance;
public S getInstance() {
return (S) instance;
}

}

0 comments on commit 3f893d0

Please sign in to comment.