Skip to content

Commit

Permalink
Missing ForAll annotation will now fail property and not only skip it
Browse files Browse the repository at this point in the history
  • Loading branch information
jlink committed Apr 14, 2019
1 parent 045352d commit d1f899c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
12 changes: 4 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
- "All parameters must have @ForAll annotation."
Fail test (instead of ignore it)
https://github.com/jlink/jqwik/issues/54

- Case-based branching with statistical reporting:

```
Case
.of(condition1, "label1", () -> {})
.of(condition2, "label2", () -> {})
.of(true, "labelDefault", () -> {});
Cases.of("name")
.match(condition1, "label1", () -> {})
.match(condition2, "label2", () -> {})
.noMatch();
```

- Arbitrary.describe() for all built-in arbitraries
Expand Down
3 changes: 2 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ and
<a href="/docs/snapshot/javadoc/index.html">javadoc</a>
</p>

- Missing `@ForAll` annotation will now fail test - instead of skipping it.
See [this Github issue](https://github.com/jlink/jqwik/issues/54).
- Added `CharacterArbitrary.with(char ... allowedChars)'
- Added `CharacterArbitrary.range(char min, char max)'
- Deprecated `CharacterArbitrary.between(char min, char max)'


## 1.1.2

<p style="padding-left:1em;font-size:larger">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public PropertyExecutionResult execute(LifecycleSupplier lifecycleSupplier, Prop
}
}

private void ensureAllParametersHaveForAll(PropertyMethodDescriptor methodDescriptor) {
String parameters = Arrays.stream(methodDescriptor.getTargetMethod().getParameters())
.filter(parameter -> !parameter.isAnnotationPresent(ForAll.class))
.map(parameter -> parameter.toString())
.collect(Collectors.joining(", "));

if (!parameters.isEmpty()) {
String message = String.format("All parameters must have @ForAll annotation: %s", parameters);
throw new JqwikException(message);
}
}

private DomainContext combineDomainContexts(Set<Domain> domainAnnotations) {
if (domainAnnotations.isEmpty()) {
return DomainContext.global();
Expand Down Expand Up @@ -84,6 +96,7 @@ private PropertyExecutionResult executePropertyMethod(LifecycleSupplier lifecycl
PropertyExecutionResult propertyExecutionResult = PropertyExecutionResult.successful(methodDescriptor.getConfiguration().getSeed());
AroundPropertyHook around = lifecycleSupplier.aroundPropertyHook(methodDescriptor);
try {
ensureAllParametersHaveForAll(methodDescriptor);
propertyExecutionResult = around.aroundProperty(
propertyLifecycleContext,
() -> executeMethod(propertyLifecycleContext.testInstance(), listener)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.jqwik.engine.execution;

import java.util.*;

import net.jqwik.api.*;
import net.jqwik.api.lifecycle.*;
import net.jqwik.api.lifecycle.SkipExecutionHook.*;
Expand All @@ -13,14 +11,6 @@
class PropertyTaskCreator {

ExecutionTask createTask(PropertyMethodDescriptor methodDescriptor, LifecycleSupplier lifecycleSupplier, boolean reportOnlyFailures) {
if (hasUnspecifiedParameters(methodDescriptor)) {
String taskDescription = "skipping " + methodDescriptor.getDisplayName();
return ExecutionTask.from(
listener -> listener.executionSkipped(methodDescriptor, "All parameters must have @ForAll annotation."),
methodDescriptor.getUniqueId(),
taskDescription
);
}
return ExecutionTask.from(
listener -> {
Object testInstance = createTestInstance(methodDescriptor);
Expand Down Expand Up @@ -57,11 +47,6 @@ private Object createTestInstance(PropertyMethodDescriptor methodDescriptor) {
}
}

private boolean hasUnspecifiedParameters(PropertyMethodDescriptor methodDescriptor) {
return Arrays.stream(methodDescriptor.getTargetMethod().getParameters())
.anyMatch(parameter -> !parameter.isAnnotationPresent(ForAll.class));
}

private PropertyExecutionResult executeTestMethod(
PropertyMethodDescriptor methodDescriptor,
PropertyLifecycleContext propertyLifecycleContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ void failingTwiceInTargetAndInClose() {
}

@Example
void methodWithUnboundParameterIsSkipped() {
void methodWithUnboundParameterFails() {
PropertyMethodDescriptor descriptor = (PropertyMethodDescriptor) forMethod(ContainerClass.class, "withParameter", int.class)
.build();

executeTests(descriptor);

InOrder events = Mockito.inOrder(eventRecorder);
events.verify(eventRecorder).executionSkipped(isPropertyDescriptorFor(ContainerClass.class, "withParameter"), anyString());
events.verify(eventRecorder).executionFinished(isPropertyDescriptorFor(ContainerClass.class, "withParameter"), isFailed());
assertThat(executions).isEmpty();
}

Expand Down

0 comments on commit d1f899c

Please sign in to comment.