diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/FixedQuantity.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/FixedQuantity.java
similarity index 86%
rename from deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/FixedQuantity.java
rename to deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/FixedQuantity.java
index a339078b..f58bf84e 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/FixedQuantity.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/FixedQuantity.java
@@ -3,9 +3,7 @@
* This program is made available under the terms of the MIT License.
*/
-package de.ppi.deepsampler.core.internal;
-
-import de.ppi.deepsampler.core.api.Quantity;
+package de.ppi.deepsampler.core.api;
public class FixedQuantity implements Quantity {
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/FunctionalSampleBuilder.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/FunctionalSampleBuilder.java
new file mode 100644
index 00000000..4f87ba67
--- /dev/null
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/FunctionalSampleBuilder.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2020 PPI AG (Hamburg, Germany)
+ * This program is made available under the terms of the MIT License.
+ */
+
+package de.ppi.deepsampler.core.api;
+
+import de.ppi.deepsampler.core.model.Answer;
+import de.ppi.deepsampler.core.model.SampleDefinition;
+
+/**
+ *
+ * Provides a fluent API for creating a {@link SampleDefinition} for methods that return a value (i.e. functions).
+ *
+ *
+ *
+ * With the FunctionalSampleBuilder you are able to define:
+ *
+ *
A concrete return value
+ *
An abstract {@link Answer} that executes arbitrary code and returns a value
+ *
+ *
+ * The return value will be used (and evaluated) when the stubbed method will be invoked.
+ *
+ *
+ * @param type of the class you want stub
+ */
+public class FunctionalSampleBuilder extends VoidSampleBuilder {
+
+ /**
+ * Create a {@link FunctionalSampleBuilder} with a sampler of the class you want to build a sample for, and the sampleDefinition
+ * you want to extend.
+ *
+ * @param sampler the sampler {@link Sampler}
+ * @param sampleDefinition {@link SampleDefinition}
+ */
+ @SuppressWarnings("unused")
+ public FunctionalSampleBuilder(final T sampler, final SampleDefinition sampleDefinition) {
+ super(sampleDefinition);
+ }
+
+ /**
+ * Defines the value, that will be returned when the stubbed method is invoked. This value is called the "Sample".
+ *
+ * @param sampleReturnValue the return value that should be returned by the stubbed method.
+ */
+ public void is(final T sampleReturnValue) {
+ getSampleDefinition().setAnswer(stubInvocation -> sampleReturnValue);
+ }
+
+ /**
+ * In most cases it will be sufficient to define a fixed Sample as a return value for a stubbed method, but sometimes it
+ * is necessary to execute some logic that would compute the return value or that would even change some additional state.
+ * This can be done by using an Answer like so:
+ *
+ *
+ * Sample.of(sampler.echo(anyString())).answer(invocation -> invocation.getParameters().get(0));
+ *
+ *
+ * In essence using Answers gives free control on what a stubbed method should do.
+ *
+ * @param answer supplier you want to get evaluated when the stubbed method got invoked
+ */
+ @SuppressWarnings("unchecked")
+ public void answers(final Answer extends Throwable> answer) {
+ getSampleDefinition().setAnswer((Answer) answer);
+ }
+
+}
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/PersistentSample.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/PersistentSample.java
new file mode 100644
index 00000000..9d321432
--- /dev/null
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/PersistentSample.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2020 PPI AG (Hamburg, Germany)
+ * This program is made available under the terms of the MIT License.
+ */
+
+package de.ppi.deepsampler.core.api;
+
+import de.ppi.deepsampler.core.error.NotASamplerException;
+import de.ppi.deepsampler.core.internal.ProxyFactory;
+import de.ppi.deepsampler.core.model.SampleDefinition;
+import de.ppi.deepsampler.core.model.SampleRepository;
+
+import java.util.Objects;
+
+/**
+ * This is the starting point for the definition of Samples in test classes.
+ *
+ * A "Sample" is an exemplary return value or an exemplary behavior of a method that fulfills a prerequisite of a particular test case. When the tested methods are not able
+ * to reproduce the Sample by their own means (i.e. due to changes in the underlying database, or passing of time, etc.), the methods can be coerced to reproduce the Sample using
+ * this API.
+ *
+ * A method is called "sampled" if the method is coerced to return a Sample.
+ *
+ * Objects which contain sampled methods, are called "Sampler".
+ *
+ * DeepSampler defines Samples on classes rather then on objects. This enables DeepSampler to change the behavior of all instances of these classes without the need to instantiate
+ * the Sampler manually and to distribute the Sampler into the objects that will be tested. The distribution is done by a Dependency Injection Framework like Spring or Guice.
+ *
+ * Methods of the class {@link Object} are ignored. Otherwise strange effects might appear, e.g. if Object::finalize is
+ * called by the garbage collector.
+ *
+ * @author Jan Schankin, Rico Schrage
+ */
+public class PersistentSample {
+
+ private PersistentSample() {
+ // This class is meant to be used as a frontend for a static fluent API and should never be instantiated.
+ }
+
+
+ /**
+ * Defines a sampled method by calling the method inside of the parameter. The returned {@link FunctionalSampleBuilder} will then offer possibilities to define the Sample,
+ * or in other words, it offers possibilities to override the default behavior or the return value of a method.
+ *
+ * @param sampledMethodCall The method call that will be sampled.
+ * @param The type of the return value and therefore the type of the Sample.
+ * @return A {@link FunctionalSampleBuilder} which can be used to define the concrete Sample. Do not keep references to this object, it is intended to be used as a
+ * fluent API only.
+ */
+ public static PersistentSampleBuilder of(final T sampledMethodCall) {
+ SampleDefinition currentSampleDefinition = SampleRepository.getInstance().getCurrentSampleDefinition();
+ SampleDefinition lastSampleDefinition = SampleRepository.getInstance().getLastSampleDefinition();
+
+ if (currentSampleDefinition == lastSampleDefinition) {
+ throw new NotASamplerException("sampledMethodCall is not a Sampler. Did you prepare the Sampler using Sampler.prepare() or @PrepareSampler?");
+ }
+
+ currentSampleDefinition.setMarkedForPersistence(true);
+
+ SampleRepository.getInstance().setLastSampleDefinition(currentSampleDefinition);
+ return new PersistentSampleBuilder<>(sampledMethodCall, currentSampleDefinition);
+ }
+
+ /**
+ * Along with the subsequent method call it defines a Sample for which the framework should start to track
+ * how often this Sample is used in the component. This is necessary to be able to verify the invocation
+ * of a specific method.
+ *
+ * @param sampler the sampler for which you want to activate a method call
+ * @param the type of the target Class/sampler
+ * @return the sampler itself
+ */
+ public static T forVerification(final T sampler) {
+ Objects.requireNonNull(sampler);
+
+ if (!ProxyFactory.isProxyClass(sampler.getClass())) {
+ throw new NotASamplerException(sampler.getClass());
+ }
+
+ SampleRepository.getInstance().setMarkNextVoidSamplerForPersistence(true);
+
+ return sampler;
+ }
+
+
+
+ /**
+ * This method will set the sampleId of the last defined sampleDefinition. Mostly you
+ * want to set the sampleId with the Method {@link PersistentSampleBuilder#hasId(String)}. But in case of
+ * void-returning methods, it is not possible to create a {@link FunctionalSampleBuilder}. As a consequence
+ * you will need to set the id with this method.
+ *
+ * @param id the id you want to set.
+ */
+ public static void setIdToLastMethodCall(final String id) {
+ SampleRepository.getInstance().getCurrentSampleDefinition().setSampleId(id);
+ }
+
+}
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/PersistentSampleBuilder.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/PersistentSampleBuilder.java
new file mode 100644
index 00000000..05ad3080
--- /dev/null
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/PersistentSampleBuilder.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2020 PPI AG (Hamburg, Germany)
+ * This program is made available under the terms of the MIT License.
+ */
+
+package de.ppi.deepsampler.core.api;
+
+import de.ppi.deepsampler.core.model.SampleDefinition;
+
+/**
+ *
+ * Provides a fluent API for creating a {@link SampleDefinition} for persistent Samples that are loaded from a file or any other DataSource.
+ * The persistence (i.e. recording and loading samples) is managed by PersistentSampleManager.
+ *
+ *
+ *
+ * With the sampleBuilder you are able to define a sampleId, that is used to identify a Sample in the persistence. By default
+ * DeepSampler creates a sampleId from the signature of the stubbed method. If this signature is changed, maybe because of a future
+ * refactoring, the sample cannot be loaded from the persistence anymore. Defining manual sampleIds can be used to avoid this situation.
+ *
+ *
+ *
+ * @param type of the class you want stub
+ */
+public class PersistentSampleBuilder extends SampleBuilder {
+
+ /**
+ * Create a {@link PersistentSampleBuilder} with a sampler of the class you want to build a sample for, and the sampleDefinition
+ * you want to extend.
+ *
+ * @param sampler the sampler {@link Sampler}
+ * @param sampleDefinition {@link SampleDefinition}
+ */
+ @SuppressWarnings("unused")
+ public PersistentSampleBuilder(final T sampler, final SampleDefinition sampleDefinition) {
+ super(sampleDefinition);
+ }
+
+ /**
+ * Set an id for the current SampleDefinition. The Id is used to find a Sample for a stubbed method. By default
+ * sampleIds are generated from the signature of the sampled method. Therefore a change of the signature would mean, that
+ * DeepSample isn't able anymore to find the Sample for the method. To prevent this situation, manual sampleIds can be used.
+ *
+ * @param sampleId the sampleId you want to set
+ * @return this
+ */
+ public PersistentSampleBuilder hasId(final String sampleId) {
+ getSampleDefinition().setSampleId(sampleId);
+ return this;
+ }
+
+
+}
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/Sample.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/Sample.java
index 661b47f8..7d765083 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/Sample.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/Sample.java
@@ -12,8 +12,6 @@
import de.ppi.deepsampler.core.model.SampleDefinition;
import de.ppi.deepsampler.core.model.SampleRepository;
-import java.util.Objects;
-
/**
* This is the starting point for the definition of Samples in test classes.
*
@@ -41,15 +39,15 @@ private Sample() {
/**
- * Defines a sampled method by calling the method inside of the parameter. The returned {@link SampleBuilder} will then offer possibilities to define the Sample,
+ * Defines a sampled method by calling the method inside of the parameter. The returned {@link FunctionalSampleBuilder} will then offer possibilities to define the Sample,
* or in other words, it offers possibilities to override the default behavior or the return value of a method.
*
* @param sampledMethodCall The method call that will be sampled.
* @param The type of the return value and therefore the type of the Sample.
- * @return A {@link SampleBuilder} which can be used to define the concrete Sample. Do not keep references to this object, it is intended to be used as a
+ * @return A {@link FunctionalSampleBuilder} which can be used to define the concrete Sample. Do not keep references to this object, it is intended to be used as a
* fluent API only.
*/
- public static SampleBuilder of(final T sampledMethodCall) {
+ public static FunctionalSampleBuilder of(final T sampledMethodCall) {
SampleDefinition currentSampleDefinition = SampleRepository.getInstance().getCurrentSampleDefinition();
SampleDefinition lastSampleDefinition = SampleRepository.getInstance().getLastSampleDefinition();
@@ -59,27 +57,9 @@ public static SampleBuilder of(final T sampledMethodCall) {
SampleRepository.getInstance().setLastSampleDefinition(currentSampleDefinition);
- return new SampleBuilder<>(sampledMethodCall, currentSampleDefinition);
+ return new FunctionalSampleBuilder<>(sampledMethodCall, currentSampleDefinition);
}
- /**
- * Along with the subsequent method call it defines a Sample for which the framework should start to track
- * how often this Sample is used in the component. This is necessary to be able to verify the invocation
- * of a specific method.
- *
- * @param sampler the sampler for which you want to activate a method call
- * @param the type of the target Class/sampler
- * @return the sampler itself
- */
- public static T forVerification(final T sampler) {
- Objects.requireNonNull(sampler);
-
- if (!ProxyFactory.isProxyClass(sampler.getClass())) {
- throw new NotASamplerException(sampler.getClass());
- }
-
- return sampler;
- }
/**
* Along with the subsequent method call you can assert that this method call has been called
@@ -95,18 +75,6 @@ public static T verifyCallQuantity(final Class cls, final Quantity quanti
return ProxyFactory.createProxy(cls, new VerifySampleHandler(quantity, cls));
}
- /**
- * This method will set the sampleId of the last defined sampleDefinition. Mostly you
- * want to set the sampleId with the Method {@link SampleBuilder#hasId(String)}. But in case of
- * void-returning methods, it is not possible to create a {@link SampleBuilder}. As a consequence
- * you will need to set the id with this method.
- *
- * @param id the id you want to set.
- */
- public static void setIdToLastMethodCall(final String id) {
- SampleRepository.getInstance().getCurrentSampleDefinition().setSampleId(id);
- }
-
/**
* Defines a stubbed void method by calling the method inside of a lambda. The returned {@link VoidSampleBuilder} will then offer possibilities to define the Sample,
* or in other words, it offers possibilities to override the default behavior or the stubbed method.
@@ -125,7 +93,7 @@ public static VoidSampleBuilder of(final VoidCall sampl
try {
sampledMethodCall.call();
} catch (final Exception e) {
- throw new NotASamplerException("The VoidCall did throw an Exception. Did you call an unstubbed method inside of the lamda, " +
+ throw new NotASamplerException("The VoidCall did throw an Exception. Did you call an unstubbed method inside of the lambda, " +
"instead of a method on a Sampler?", e);
}
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/SampleBuilder.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/SampleBuilder.java
index f032237a..09fa1d74 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/SampleBuilder.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/SampleBuilder.java
@@ -1,86 +1,31 @@
-/*
- * Copyright 2020 PPI AG (Hamburg, Germany)
- * This program is made available under the terms of the MIT License.
- */
-
package de.ppi.deepsampler.core.api;
-import de.ppi.deepsampler.core.model.Answer;
import de.ppi.deepsampler.core.model.SampleDefinition;
+import java.util.Objects;
+
/**
- *
- * Provides a fluent API for creating a {@link SampleDefinition}. You should never create a {@link SampleBuilder} by
- * yourself instead you should use {@link Sample#of(Object)}.
- *
+ * Parent off all {@link SampleBuilder}s. A {@link SampleBuilder} is a Builder that is used to compose a {@link SampleDefinition} using a
+ * fluent API in conjunction with {@link Sample} and {@link PersistentSample}.
*
- *
- * With the sampleBuilder you are able to define:
- *
- *
A return value or returnValueSupplier
- *
A sampleId
- *
- *
- * The return value will be used (and evaluated) when the stubbed method will be invoked.
- * The sampleId is a possibility to assign an id to the sampleDefinition. This id will be used
- * in the persistence to identify the stubbed method.
- *
- *
- * @param type of the class you want stub
+ * DeepSampler defines different {@link SampleDefinition}s depending on the type of method that should be stubbed. For instance, different
+ * configurations are necessary for void methods and methods that return values.
*/
-public class SampleBuilder extends VoidSampleBuilder {
+public abstract class SampleBuilder {
- /**
- * Create a {@link SampleBuilder} with a sampler of the class you want to build a sample for, and the sampleDefinition
- * you want to extend.
- *
- * @param sampler the sampler {@link Sampler}
- * @param sampleDefinition {@link SampleDefinition}
- */
- @SuppressWarnings("unused")
- public SampleBuilder(final T sampler, final SampleDefinition sampleDefinition) {
- super(sampleDefinition);
- }
-
- /**
- * Makes the stubbed method return the given value when invoked.
- *
- * @param sampleReturnValue the return value you want to set for the sampleDefinition
- */
- public void is(final T sampleReturnValue) {
- getSampleDefinition().setAnswer(stubInvocation -> sampleReturnValue);
- }
+ private final SampleDefinition sampleDefinition;
/**
- * In most cases it will be sufficient to define a fixed Sample as a return value for a stubbed method, but sometimes it
- * is necessary to execute some logic that would compute the return value or that would even change some additional state.
- * This can be done by using an Answer like so:
+ * Create a {@link SampleBuilder} with a {@link SampleDefinition}
*
- *
- * Sample.of(sampler.echo(anyString())).answer(invocation -> invocation.getParameters().get(0));
- *
- *
- * In essence using Answers gives free control on what a stubbed method should do.
- *
- * @param answer supplier you want to get evaluated when the stubbed method get invoked
+ * @param sampleDefinition {@link SampleDefinition}
*/
- @SuppressWarnings("unchecked")
- public void answers(final Answer extends Throwable> answer) {
- getSampleDefinition().setAnswer((Answer) answer);
+ protected SampleBuilder(final SampleDefinition sampleDefinition) {
+ this.sampleDefinition = Objects.requireNonNull(sampleDefinition, "the SampleDefinition must not be null.");
}
-
-
- /**
- * Set an id for the current SampleDefinition.
- *
- * @param sampleId the sampleId you want to set
- * @return this
- */
- public SampleBuilder hasId(final String sampleId) {
- getSampleDefinition().setSampleId(sampleId);
- return this;
+ protected SampleDefinition getSampleDefinition() {
+ return sampleDefinition;
}
-
}
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/VoidSampleBuilder.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/VoidSampleBuilder.java
index 25b31510..e4d14a7f 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/VoidSampleBuilder.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/api/VoidSampleBuilder.java
@@ -12,12 +12,9 @@
import org.objenesis.ObjenesisStd;
import org.objenesis.instantiator.ObjectInstantiator;
-import java.util.Objects;
-
/**
*
- * Provides a fluent API for creating a {@link SampleDefinition}. You should never create a {@link SampleBuilder} by
- * yourself instead you should use {@link Sample#of(Object)}.
+ * Provides a fluent API for creating a {@link SampleDefinition} for void methods.
*
*
*
@@ -25,24 +22,19 @@
*
*
throw Exceptions when a stubbed method is called
*
deactivate a method, so that a stubbed method does nothing when it is called
+ *
delegate to the original method, so that a stubbed method does the same as the original method when it is called
*
*/
-public class VoidSampleBuilder {
+public class VoidSampleBuilder extends SampleBuilder {
- private final SampleDefinition sampleDefinition;
/**
* Create a {@link VoidSampleBuilder} with a {@link SampleDefinition}
- * you want to extend.
*
* @param sampleDefinition {@link SampleDefinition}
*/
- public VoidSampleBuilder(final SampleDefinition sampleDefinition) {
- this.sampleDefinition = Objects.requireNonNull(sampleDefinition, "the SampleDefinition must not be null.");
- }
-
- protected SampleDefinition getSampleDefinition() {
- return sampleDefinition;
+ protected VoidSampleBuilder(SampleDefinition sampleDefinition) {
+ super(sampleDefinition);
}
/**
@@ -51,7 +43,7 @@ protected SampleDefinition getSampleDefinition() {
* @param exception the Exception that will be thrown.
*/
public void throwsException(final Exception exception) {
- sampleDefinition.setAnswer(invocation -> {
+ getSampleDefinition().setAnswer(invocation -> {
throw exception;
});
}
@@ -62,7 +54,7 @@ public void throwsException(final Exception exception) {
* @param exceptionClass The type of the {@link Exception} that will be thrown. The Exception is instantiated at the time when the stubbed method is called.
*/
public void throwsException(final Class extends Exception> exceptionClass) {
- sampleDefinition.setAnswer(invocation -> {
+ getSampleDefinition().setAnswer(invocation -> {
final Objenesis objenesis = new ObjenesisStd();
final ObjectInstantiator> exceptionInstantiator = objenesis.getInstantiatorOf(exceptionClass);
@@ -75,18 +67,18 @@ public void throwsException(final Class extends Exception> exceptionClass) {
*
* There are several situation where this might be useful. One example would be a
* method that would attempt to write data in a database using values that do not comply to a foreign key, since the values are now Samples that
- * don't exist in the real database. In another case it might simply be necessary to prevent a method from deleting data.
+ * don't exist in the real database. In another case, it might simply be necessary to prevent a method from deleting data.
*/
public void doesNothing() {
- sampleDefinition.setAnswer(invocation -> null);
+ getSampleDefinition().setAnswer(invocation -> null);
}
/**
* Calls the original unstubbed method. This is useful in conjunction with other Samples that are only supposed to be used for particular
- * parameter values while all other calls of the method with different parameter values should still call the original method.
+ * parameter values while all other calls of the method, with different parameter values, should still call the original method.
*/
public void callsOriginalMethod() {
- sampleDefinition.setAnswer(StubMethodInvocation::callOriginalMethod);
+ getSampleDefinition().setAnswer(StubMethodInvocation::callOriginalMethod);
}
/**
@@ -102,7 +94,7 @@ public void callsOriginalMethod() {
* @param answer method you want to get evaluated when the stubbed method is invoked
*/
public void answers(final VoidAnswer> answer) {
- sampleDefinition.setAnswer(stubMethodInvocation -> {
+ getSampleDefinition().setAnswer(stubMethodInvocation -> {
answer.call(stubMethodInvocation);
return null;
});
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/RecordSampleHandler.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/RecordSampleHandler.java
index 36e31046..1b87dec7 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/RecordSampleHandler.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/RecordSampleHandler.java
@@ -16,7 +16,7 @@
* that should be stubbed. (@see {@link de.ppi.deepsampler.core.api.Sampler}).
*
* Methods of the class {@link Object} are ignored. Otherwise strange effects might appear, e.g. if Object::finalize is
- * called by the garbage collactor.
+ * called by the garbage collector.
*/
public class RecordSampleHandler extends ReturningSampleHandler {
private final Class> cls;
@@ -30,6 +30,7 @@ public Object invoke(final Object self, final Method method, final Method procee
if (!Object.class.equals(method.getDeclaringClass())) {
final SampleDefinition sampleDefinition = createSampleDefinition(cls, method, args);
SampleRepository.getInstance().add(sampleDefinition);
+ SampleRepository.getInstance().setMarkNextVoidSamplerForPersistence(false);
}
return createEmptyProxy(method.getReturnType());
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/ReturningSampleHandler.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/ReturningSampleHandler.java
index 44edc58b..b54f5b81 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/ReturningSampleHandler.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/aophandler/ReturningSampleHandler.java
@@ -31,6 +31,7 @@ protected SampleDefinition createSampleDefinition(final Class> cls, final Meth
sampleDefinition.setParameterMatchers(parameterMatchers);
sampleDefinition.setParameterValues(new ArrayList<>(Arrays.asList(args)));
+ sampleDefinition.setMarkedForPersistence(SampleRepository.getInstance().getMarkNextVoidSamplerForPersistence());
return sampleDefinition;
}
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/api/ExecutionManager.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/api/ExecutionManager.java
index a7724e02..71e72e3d 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/api/ExecutionManager.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/internal/api/ExecutionManager.java
@@ -6,8 +6,10 @@
package de.ppi.deepsampler.core.internal.api;
import de.ppi.deepsampler.core.api.SampleReturnProcessor;
+import de.ppi.deepsampler.core.error.InvalidConfigException;
import de.ppi.deepsampler.core.model.*;
+import java.io.InvalidClassException;
import java.util.ArrayList;
import java.util.List;
diff --git a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/model/SampleDefinition.java b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/model/SampleDefinition.java
index cb101068..24a84f9f 100644
--- a/deepsampler-core/src/main/java/de/ppi/deepsampler/core/model/SampleDefinition.java
+++ b/deepsampler-core/src/main/java/de/ppi/deepsampler/core/model/SampleDefinition.java
@@ -16,6 +16,7 @@ public class SampleDefinition {
private List> parameterMatchers = new ArrayList<>();
private Answer answer;
private String sampleId;
+ private boolean isMarkedForPersistence;
public SampleDefinition(final SampledMethod sampledMethod) {
this.sampledMethod = sampledMethod;
@@ -74,6 +75,15 @@ public List