Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail fast conditions can now be specified with assertions
- Loading branch information
1 parent
d39c00d
commit fc45eb7
Showing
7 changed files
with
317 additions
and
27 deletions.
There are no files selected for viewing
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
74 changes: 61 additions & 13 deletions
74
awaitility/src/main/java/org/awaitility/core/FailFastCondition.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 | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,71 @@ | ||
/* | ||
* Copyright 2022 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 | ||
* | ||
* http://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.awaitility.core; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
public class FailFastCondition { | ||
private static final String DEFAULT_FAILURE_REASON = "Fail fast condition triggered"; | ||
|
||
private final Callable<Boolean> failFastCondition; | ||
private final String failFastFailureReason; | ||
// Simulate sealed classes | ||
|
||
public FailFastCondition(String failFastFailureReason, Callable<Boolean> failFastCondition) { | ||
this.failFastCondition = failFastCondition; | ||
this.failFastFailureReason = failFastFailureReason == null ? DEFAULT_FAILURE_REASON : failFastFailureReason; | ||
public abstract class FailFastCondition { | ||
private FailFastCondition() { | ||
} | ||
|
||
public Callable<Boolean> getFailFastCondition() { | ||
return this.failFastCondition; | ||
} | ||
public abstract String getFailFastFailureReason(); | ||
|
||
public static final class CallableFailFastCondition extends FailFastCondition { | ||
private static final String DEFAULT_FAILURE_REASON = "Fail fast condition triggered"; | ||
|
||
private final Callable<Boolean> failFastCondition; | ||
private final String failFastFailureReason; | ||
|
||
public CallableFailFastCondition(String failFastFailureReason, Callable<Boolean> failFastCondition) { | ||
this.failFastCondition = failFastCondition; | ||
this.failFastFailureReason = failFastFailureReason == null ? DEFAULT_FAILURE_REASON : failFastFailureReason; | ||
} | ||
|
||
public Callable<Boolean> getFailFastCondition() { | ||
return this.failFastCondition; | ||
} | ||
|
||
@Override | ||
public String getFailFastFailureReason() { | ||
return this.failFastFailureReason; | ||
} | ||
|
||
public static final class FailFastAssertion extends FailFastCondition { | ||
private final String failFastFailureReason; | ||
private final ThrowingRunnable failFastAssertion; | ||
|
||
public FailFastAssertion(String failFastFailureReason, ThrowingRunnable failFastAssertion) { | ||
if (failFastAssertion == null) { | ||
throw new IllegalArgumentException("failFastAssertion cannot be null"); | ||
} | ||
this.failFastFailureReason = failFastFailureReason; | ||
this.failFastAssertion = failFastAssertion; | ||
} | ||
|
||
public ThrowingRunnable getFailFastAssertion() { | ||
return failFastAssertion; | ||
} | ||
|
||
public String getFailFastFailureReason() { | ||
return this.failFastFailureReason; | ||
@Override | ||
public String getFailFastFailureReason() { | ||
return failFastFailureReason; | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.