How to use ValueInjector class of com.tngtech.jgiven.impl.inject package

Best JGiven code snippet using com.tngtech.jgiven.impl.inject.ValueInjector

Source:ScenarioExecutor.java Github

copy

Full Screen

...11import com.tngtech.jgiven.attachment.Attachment;12import com.tngtech.jgiven.exception.FailIfPassedException;13import com.tngtech.jgiven.exception.JGivenMissingRequiredScenarioStateException;14import com.tngtech.jgiven.exception.JGivenUserException;15import com.tngtech.jgiven.impl.inject.ValueInjector;16import com.tngtech.jgiven.impl.intercept.NoOpScenarioListener;17import com.tngtech.jgiven.impl.intercept.ScenarioListener;18import com.tngtech.jgiven.impl.intercept.StageTransitionHandler;19import com.tngtech.jgiven.impl.intercept.StepInterceptorImpl;20import com.tngtech.jgiven.impl.util.FieldCache;21import com.tngtech.jgiven.impl.util.ReflectionUtil;22import com.tngtech.jgiven.integration.CanWire;23import com.tngtech.jgiven.report.model.InvocationMode;24import com.tngtech.jgiven.report.model.NamedArgument;25import java.lang.annotation.Annotation;26import java.lang.reflect.Field;27import java.lang.reflect.Method;28import java.util.ArrayList;29import java.util.LinkedHashMap;30import java.util.List;31import java.util.Map;32import java.util.Optional;33import org.slf4j.Logger;34import org.slf4j.LoggerFactory;35/**36 * Main class of JGiven for executing scenarios.37 */38public class ScenarioExecutor {39 private static final Logger log = LoggerFactory.getLogger(ScenarioExecutor.class);40 enum State {41 INIT,42 STARTED,43 FINISHED44 }45 private Object currentTopLevelStage;46 private State state = State.INIT;47 private boolean beforeScenarioMethodsExecuted;48 /**49 * Whether life cycle methods should be executed.50 * This is only false for scenarios that are annotated with @NotImplementedYet51 */52 private boolean executeLifeCycleMethods = true;53 protected final Map<Class<?>, StageState> stages = new LinkedHashMap<>();54 private final List<Object> scenarioRules = new ArrayList<>();55 private final ValueInjector injector = new ValueInjector();56 private StageCreator stageCreator = createStageCreator(new ByteBuddyStageClassCreator());57 private ScenarioListener listener = new NoOpScenarioListener();58 protected final StageTransitionHandler stageTransitionHandler = new StageTransitionHandlerImpl();59 protected final StepInterceptorImpl methodInterceptor =60 new StepInterceptorImpl(this, listener, stageTransitionHandler);61 /**62 * Set if an exception was thrown during the execution of the scenario and63 * suppressStepExceptions is true.64 */65 private Throwable failedException;66 private boolean failIfPass;67 /**68 * Whether exceptions caught while executing steps should be thrown at the end69 * of the scenario. Only relevant if suppressStepExceptions is true, because otherwise...

Full Screen

Full Screen

Source:ValueInjector.java Github

copy

Full Screen

...18import org.slf4j.LoggerFactory;19/**20 * Used by Scenario to inject and read values from objects.21 */22public class ValueInjector {23 private static final Logger log = LoggerFactory.getLogger(ValueInjector.class);24 /**25 * Caches all classes that have been already validated for ambiguous resolution.26 * This avoids duplicate validations of the same class.27 */28 private static final ConcurrentHashMap<Class<?>, Boolean> validatedClasses = new ConcurrentHashMap<>();29 private final ValueInjectorState state = new ValueInjectorState();30 /**31 * @throws AmbiguousResolutionException when multiple fields with the same resolution exist in the given object32 */33 @SuppressWarnings("unchecked")34 public void validateFields(Object object) {35 if (validatedClasses.get(object.getClass()) == Boolean.TRUE) {36 return;37 }38 Map<Object, Field> resolvedFields = Maps.newHashMap();39 for (ScenarioStateField field : getScenarioFields(object)) {40 field.getField().setAccessible(true);41 Resolution resolution = field.getResolution();42 Object key = null;43 if (resolution == Resolution.NAME) {...

Full Screen

Full Screen

Source:ValueInjectorTest.java Github

copy

Full Screen

...5import com.tngtech.jgiven.annotation.ScenarioState;6import com.tngtech.jgiven.exception.JGivenMissingGuaranteedScenarioStateException;7import com.tngtech.jgiven.exception.JGivenMissingRequiredScenarioStateException;8import org.junit.Test;9public class ValueInjectorTest {10 private ValueInjector injector = new ValueInjector();11 @Test(expected = JGivenMissingGuaranteedScenarioStateException.class)12 public void null_provided_field_throws_exception() {13 FakeStage stageObject = new FakeStage(null, null, "");14 injector.readValues(stageObject);15 }16 @Test(expected = JGivenMissingGuaranteedScenarioStateException.class)17 public void null_state_field_throws_exception() throws Throwable {18 FakeStage stageObject = new FakeStage("", null, null);19 injector.readValues(stageObject);20 }21 @Test22 public void initialized_fields_do_not_interrupt_execution() {23 FakeStage stageObject = new FakeStage("", null, "");24 injector.readValues(stageObject);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JGiven automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful