testasyouthink.GivenTwoArgumentsWhenSteps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-as-you-think-core Show documentation
Show all versions of test-as-you-think-core Show documentation
The TestAsYouThink Core is a DSL style fluent API in Java to promote good coding practices in tests.
/*-
* #%L
* Test As You Think
* %%
* Copyright (C) 2017 Xavier Pigeon and TestAsYouThink contributors
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package testasyouthink;
import testasyouthink.GivenWhenThenDsl.ExecutionStage.WhenApplyingThreeArguments;
import testasyouthink.GivenWhenThenDsl.PreparationStage.AndGivenTwoArguments;
import testasyouthink.GivenWhenThenDsl.VerificationStage.Then;
import testasyouthink.GivenWhenThenDsl.VerificationStage.ThenFailure;
import testasyouthink.GivenWhenThenDsl.VerificationStage.ThenWithoutResult;
import testasyouthink.function.CheckedConsumer;
import testasyouthink.function.CheckedSupplier;
import testasyouthink.function.CheckedTriConsumer;
import testasyouthink.function.CheckedTriFunction;
import testasyouthink.function.Functions;
import testasyouthink.preparation.Preparation;
public class GivenTwoArgumentsWhenSteps<$SystemUnderTest, $Argument1, $Argument2> implements
AndGivenTwoArguments<$SystemUnderTest, $Argument1, $Argument2> {
private final Functions functions = Functions.INSTANCE;
private final ThenStepFactory thenStepFactory = ThenStepFactory.INSTANCE;
private final Preparation<$SystemUnderTest> preparation;
GivenTwoArgumentsWhenSteps(Preparation<$SystemUnderTest> preparation) {
this.preparation = preparation;
}
@Override
public <$Argument3> WhenApplyingThreeArguments<$SystemUnderTest, $Argument1, $Argument2, $Argument3> andArgument(
CheckedSupplier<$Argument3> givenStep) {
preparation.recordGivenStep(givenStep);
return new GivenThreeArgumentsWhenSteps<>(preparation);
}
@Override
public <$Argument3> WhenApplyingThreeArguments<$SystemUnderTest, $Argument1, $Argument2, $Argument3> andArgument(
Class<$Argument3> mutableArgumentClass, CheckedConsumer<$Argument3> givenStep) {
preparation.recordGivenStep(mutableArgumentClass, givenStep);
return new GivenThreeArgumentsWhenSteps<>(preparation);
}
@Override
public <$Argument3> WhenApplyingThreeArguments<$SystemUnderTest, $Argument1, $Argument2, $Argument3> andArgument(
String description, CheckedSupplier<$Argument3> givenStep) {
return andArgument(givenStep);
}
@Override
public <$Argument3> WhenApplyingThreeArguments<$SystemUnderTest, $Argument1, $Argument2, $Argument3> andArgument(
String description, $Argument3 argument) {
preparation.recordGivenStep(functions.toCheckedSupplier(argument));
return new GivenThreeArgumentsWhenSteps<>(preparation);
}
@Override
public ThenWithoutResult<$SystemUnderTest> when(
CheckedTriConsumer<$SystemUnderTest, $Argument1, $Argument2> whenStep) {
return thenStepFactory.createThenStep(preparation,
functions.toConsumer(whenStep, preparation.getArgumentSuppliers()));
}
@Override
public ThenWithoutResult<$SystemUnderTest> whenSutRuns(
CheckedTriConsumer<$SystemUnderTest, $Argument1, $Argument2> whenStep) {
return when(whenStep);
}
@Override
public <$Result> Then<$SystemUnderTest, $Result> when(
CheckedTriFunction<$SystemUnderTest, $Argument1, $Argument2, $Result> whenStep) {
return thenStepFactory.createThenStep(preparation,
functions.toFunction(whenStep, preparation.getArgumentSuppliers()));
}
@Override
public <$Result> Then<$SystemUnderTest, $Result> whenSutReturns(
CheckedTriFunction<$SystemUnderTest, $Argument1, $Argument2, $Result> whenStep) {
return when(whenStep);
}
@Override
public ThenFailure whenSutRunsOutsideOperatingConditions(
CheckedTriConsumer<$SystemUnderTest, $Argument1, $Argument2> whenStep) {
return thenStepFactory.createThenStep(preparation, functions.toFunctionWithThrowableAsResult(
functions.toConsumer(whenStep, preparation.getArgumentSuppliers())));
}
}