How to use instance method of com.greghaskins.spectrum.internal.DeclarationState class

Best Spectrum code snippet using com.greghaskins.spectrum.internal.DeclarationState.instance

Source:Specification.java Github

copy

Full Screen

...25 * @param block {@link Block} with one or more calls to {@link #it(String, Block) it} that26 * define each expected behavior27 */28 static void describe(final String context, final Block block) {29 final Suite suite = DeclarationState.instance()30 .getCurrentSuiteBeingDeclared()31 .addSuite(context);32 suite.applyConfigurationFromBlock(block);33 DeclarationState.instance().beginDeclaration(suite, block);34 }35 /**36 * Focus on this specific suite, while ignoring others.37 *38 * @param context Description of the context for this suite39 * @param block {@link Block} with one or more calls to {@link #it(String, Block) it} that40 * define each expected behavior41 * @see #describe(String, Block)42 */43 static void fdescribe(final String context, final Block block) {44 describe(context, with(focus(), block));45 }46 /**47 * Ignore the specific suite.48 *49 * @param context Description of the context for this suite50 * @param block {@link Block} with one or more calls to {@link #it(String, Block) it} that51 * define each expected behavior52 * @see #describe(String, Block)53 */54 static void xdescribe(final String context, final Block block) {55 describe(context, with(ignore(), block));56 }57 /**58 * Declare a spec, or test, for an expected behavior of the system in this suite context.59 *60 * @param behavior Description of the expected behavior61 * @param block {@link Block} that verifies the system behaves as expected and throws a {@link62 * java.lang.Throwable Throwable} if that expectation is not met.63 */64 static void it(final String behavior, final Block block) {65 DeclarationState.instance().getCurrentSuiteBeingDeclared().addSpec(behavior, block);66 }67 /**68 * Declare a pending spec (without a block) that will be ignored.69 *70 * @param behavior Description of the expected behavior71 * @see #xit(String, Block)72 */73 static void it(final String behavior) {74 DeclarationState.instance().getCurrentSuiteBeingDeclared().addSpec(behavior, null).ignore();75 }76 /**77 * Focus on this specific spec, while ignoring others.78 *79 * @param behavior Description of the expected behavior80 * @param block {@link Block} that verifies the system behaves as expected and throws a {@link81 * java.lang.Throwable Throwable} if that expectation is not met.82 * @see #it(String, Block)83 */84 static void fit(final String behavior, final Block block) {85 it(behavior, with(focus(), block));86 }87 /**88 * Mark a spec as ignored so that it will be skipped.89 *90 * @param behavior Description of the expected behavior91 * @param block {@link Block} that will not run, since this spec is ignored.92 * @see #it(String, Block)93 */94 static void xit(final String behavior, final Block block) {95 it(behavior);96 }97 /**98 * Declare a {@link Block} to be run before each spec in the suite.99 *100 * <p>101 * Use this to perform setup actions that are common across tests in the context. If multiple102 * {@code beforeEach} blocks are declared, they will run in declaration order.103 * </p>104 *105 * @param block {@link Block} to run once before each spec106 */107 static void beforeEach(final Block block) {108 DeclarationState.instance().addHook(before(block), AppliesTo.ATOMIC_ONLY, Precedence.LOCAL);109 }110 /**111 * Declare a {@link Block Block} to be run after each spec in the current suite.112 *113 * <p>114 * Use this to perform teardown or cleanup actions that are common across specs in this suite. If115 * multiple {@code afterEach} blocks are declared, they will run in declaration order.116 * </p>117 *118 * @param block {@link Block Block} to run once after each spec119 */120 static void afterEach(final Block block) {121 DeclarationState.instance().addHook(after(block), AppliesTo.ATOMIC_ONLY,122 Precedence.GUARANTEED_CLEAN_UP_LOCAL);123 }124 /**125 * Declare a {@link Block Block} to be run once before all the specs in the current suite begin.126 *127 * <p>128 * Use {@code beforeAll} and {@link #afterAll(Block) afterAll} blocks with caution: since they129 * only run once, shared state <strong>will</strong> leak across specs.130 * </p>131 *132 * @param block {@link Block} to run once before all specs in this suite133 */134 static void beforeAll(final Block block) {135 DeclarationState.instance().addHook(before(new IdempotentBlock(block)), AppliesTo.ATOMIC_ONLY,136 Precedence.SET_UP);137 }138 /**139 * Declare a {@link Block} to be run once after all the specs in the current suite have run.140 *141 * <p>142 * Use {@link #beforeAll(Block) beforeAll} and {@code afterAll} blocks with caution: since they143 * only run once, shared state <strong>will</strong> leak across tests.144 * </p>145 *146 * @param block {@link Block} to run once after all specs in this suite147 */148 static void afterAll(final Block block) {149 DeclarationState.instance().addHook(after(block), AppliesTo.ONCE,150 Precedence.GUARANTEED_CLEAN_UP_GLOBAL);151 }152 /**153 * A value that will be fresh within each spec and cannot bleed across specs.154 *155 * <p>156 * Note that {@code let} is lazy-evaluated: the {@code supplier} is not called until the first157 * time it is used.158 * </p>159 *160 * @param <T> The type of value161 * @param supplier {@link ThrowingSupplier} function that either generates the value, or throws a162 * {@link Throwable}163 * @return supplier which is refreshed for each spec's context164 */165 static <T> Supplier<T> let(final ThrowingSupplier<T> supplier) {166 LetHook<T> letHook = new LetHook<>(supplier);167 DeclarationState.instance().addHook(letHook, AppliesTo.ATOMIC_ONLY, Precedence.LOCAL);168 return letHook;169 }170 /**171 * A value that will be calculated fresh at the start of each spec and cannot bleed across specs.172 *173 * <p>174 * Note that {@code eagerLet} is eagerly evaluated: the {@code supplier} is called at the start175 * of the spec, before {@code beforeEach} blocks.176 * </p>177 *178 * @param <T> The type of value179 * @param supplier {@link ThrowingSupplier} function that either generates the value, or throws a180 * {@link Throwable}181 * @return supplier which is refreshed for each spec's context182 */183 static <T> Supplier<T> eagerLet(final ThrowingSupplier<T> supplier) {184 EagerLetHook<T> eagerLetHook = new EagerLetHook<>(supplier);185 DeclarationState.instance().addHook(eagerLetHook, AppliesTo.ATOMIC_ONLY, Precedence.LOCAL);186 return eagerLetHook;187 }188 /**189 * Define a test context. Alias for {@link #describe}.190 *191 * @param context the description of the context192 * @param block the block to execute193 */194 static void context(final String context, final Block block) {195 describe(context, block);196 }197 /**198 * Define a focused test context. Alias for {@link #fdescribe}.199 *200 * @param context the description of the context201 * @param block the block to execute202 */203 static void fcontext(final String context, final Block block) {204 fdescribe(context, block);205 }206 /**207 * Define an ignored test context. Alias for {@link #xdescribe}.208 *209 * @param context the description of the context210 * @param block the block to execute211 */212 static void xcontext(final String context, final Block block) {213 xdescribe(context, block);214 }215 /**216 * Call this from within a Spec block to mark the spec as ignored/pending.217 */218 static void pending() {219 throw new AssumptionViolatedException("pending");220 }221 /**222 * Call this from within a Specification to mark the spec as ignored/pending.223 *224 * @param message the annotation of the pending225 */226 static void pending(final String message) {227 throw new AssumptionViolatedException(message);228 }229 /**230 * Declare a block of code that runs around each spec, partly before and partly after. You must231 * call {@link com.greghaskins.spectrum.Block#run} inside this Consumer. This code is applied to232 * every spec in the current suite.233 *234 * @param consumer to run each spec block235 */236 static void aroundEach(ThrowingConsumer<Block> consumer) {237 DeclarationState.instance().addHook(Hook.from(consumer), AppliesTo.ATOMIC_ONLY,238 Precedence.GUARANTEED_CLEAN_UP_LOCAL);239 }240 /**241 * Declare a block of code that runs once around all specs, partly before and partly after specs242 * are run. You must call {@link Block#run} inside this Consumer. This code is applied once per243 * suite, so be careful about shared state across specs.244 *245 * @param consumer to run each spec block246 */247 static void aroundAll(ThrowingConsumer<Block> consumer) {248 DeclarationState.instance().addHook(Hook.from(consumer), AppliesTo.ONCE, Precedence.OUTER);249 }250}...

Full Screen

Full Screen

Source:Configure.java Github

copy

Full Screen

...106 * @see #includeTags(String...)107 * @see #excludeTags(String...)108 */109 static void filterRun(FilterConfigurationChain configuration) {110 configuration.applyTo(DeclarationState.instance().getCurrentSuiteBeingDeclared());111 }112 /**113 * Set the test filter to require at least one of these tags for all following specs.114 *115 * @param tagsToInclude specs (or their parent suite) must have at least one of these116 * @return FilterConfigurationChain instance for chaining further calls117 */118 static FilterConfigurationChain includeTags(String... tagsToInclude) {119 return new FilterConfigurationChain(new IncludeTags(tagsToInclude));120 }121 /**122 * Set the test filter to exclude any following specs that have one of these tags.123 *124 * @param tagsToExclude specs and their parent suite must not have any of these125 * @return FilterConfigurationChain instance for chaining further calls126 */127 static FilterConfigurationChain excludeTags(String... tagsToExclude) {128 return new FilterConfigurationChain(new ExcludeTags(tagsToExclude));129 }130 /**131 * Uses the given class as a mix-in for JUnit rules to be applied. These rules will cascade down132 * and be applied at the level of specs or atomic specs.133 *134 * @param classWithRules Class to create and apply rules to for each spec.135 * @param <T> type of the object136 * @return a supplier of the rules object137 */138 static <T> Supplier<T> junitMixin(final Class<T> classWithRules) {139 return Rules.applyRules(classWithRules, DeclarationState.instance()::addHook);140 }141}...

Full Screen

Full Screen

Source:DeclarationState.java Github

copy

Full Screen

...6import com.greghaskins.spectrum.internal.hooks.HookContext.Precedence;7import java.util.ArrayDeque;8import java.util.Deque;9public final class DeclarationState {10 private static final ThreadLocal<DeclarationState> instance =11 ThreadLocal.withInitial(DeclarationState::new);12 public static DeclarationState instance() {13 return instance.get();14 }15 private final Deque<Suite> suiteStack = new ArrayDeque<>();16 private DeclarationState() {}17 public Suite getCurrentSuiteBeingDeclared() {18 return suiteStack.peek();19 }20 private int getCurrentDepth() {21 return suiteStack.size();22 }23 public void beginDeclaration(final Suite suite, final Block definitionBlock) {24 suiteStack.push(suite);25 try {26 definitionBlock.run();27 } catch (final Throwable error) {28 suite.removeAllChildren();29 suite.addSpec("encountered an error", () -> {30 throw error;31 });32 }33 suiteStack.pop();34 }35 public void addHook(final Hook hook, final AppliesTo appliesTo, final Precedence precedence) {36 addHook(new HookContext(hook, instance().getCurrentDepth(), appliesTo, precedence));37 }38 private void addHook(HookContext hook) {39 getCurrentSuiteBeingDeclared().addHook(hook);40 }41}...

Full Screen

Full Screen

instance

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.DeclarationState;2import java.lang.reflect.Method;3import java.util.List;4import java.util.ArrayList;5import java.util.Arrays;6public class 1 {7 public static void main(String[] args) {8 try {9 Class<?> cls = Class.forName("com.greghaskins.spectrum.internal.DeclarationState");10 Method method = cls.getDeclaredMethod("getDeclaredMethods");11 method.setAccessible(true);12 List<Method> methods = new ArrayList<Method>(Arrays.asList((Method[]) method.invoke(null)));13 for (Method m : methods) {14 System.out.println(m);15 }16 } catch (Exception e) {17 System.out.println(e);18 }19 }20}21import com.greghaskins.spectrum.internal.DeclarationState;22import java.util.List;23import java.util.ArrayList;24import java.util.Arrays;25public class 2 {26 public static void main(String[] args) {27 List<Method> methods = new ArrayList<Method>(Arrays.asList(DeclarationState.getDeclaredMethods()));28 for (Method m : methods) {29 System.out.println(m);30 }31 }32}

Full Screen

Full Screen

instance

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum.internal;2import java.lang.reflect.Method;3public class DeclarationState {4 public static void reset() throws Exception {5 Class<?> clazz = Class.forName("com.greghaskins.spectrum.internal.DeclarationState");6 Method method = clazz.getDeclaredMethod("reset");7 method.setAccessible(true);8 method.invoke(null);9 }10}11package com.greghaskins.spectrum.internal;12import java.lang.reflect.Method;13public class DeclarationState {14 public static void reset() throws Exception {15 Class<?> clazz = Class.forName("com.greghaskins.spectrum.internal.DeclarationState");16 Method method = clazz.getDeclaredMethod("reset");17 method.setAccessible(true);18 method.invoke(null);19 }20}21package com.greghaskins.spectrum.internal;22import java.lang.reflect.Method;23public class DeclarationState {24 public static void reset() throws Exception {25 Class<?> clazz = Class.forName("com.greghaskins.spectrum.internal.DeclarationState");26 Method method = clazz.getDeclaredMethod("reset");27 method.setAccessible(true);28 method.invoke(null);29 }30}31package com.greghaskins.spectrum.internal;32import java.lang.reflect.Method;33public class DeclarationState {34 public static void reset() throws Exception {35 Class<?> clazz = Class.forName("com.greghaskins.spectrum.internal.DeclarationState");36 Method method = clazz.getDeclaredMethod("reset");37 method.setAccessible(true);38 method.invoke(null);39 }40}41package com.greghaskins.spectrum.internal;42import java.lang.reflect.Method;43public class DeclarationState {44 public static void reset() throws Exception {45 Class<?> clazz = Class.forName("com.greghaskins.spectrum.internal.DeclarationState");46 Method method = clazz.getDeclaredMethod("reset");47 method.setAccessible(true);48 method.invoke(null);49 }50}

Full Screen

Full Screen

instance

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.DeclarationState;2import com.greghaskins.spectrum.internal.Specification;3import com.greghaskins.spectrum.internal.SpecificationContext;4import com.greghaskins.spectrum.internal.Suite;5import com.greghaskins.spectrum.internal.SuiteContext;6import com.greghaskins.spectrum.internal.SuiteState;7import com.greghaskins.spectrum.internal.hooks.BlockHook;8import com.greghaskins.spectrum.internal.hooks.BeforeAllHook;9import com.greghaskins.spectrum.internal.hooks.BeforeEachHook;10import com.greghaskins.spectrum.internal.hooks.Hook;11import com.greghaskins.spectrum.internal.hooks.HookContext;12import com.greghaskins.spectrum.internal.hooks.HookType;13import com.greghaskins.spectrum.internal.hooks.Hooks;14import com.greghaskins.spectrum.internal.hooks.HooksContext;15import com.greghaskins.spectrum.internal.hooks.HooksState;16import com.greghaskins.spectrum.internal.hooks.ParentHook;17import com.greghaskins.spectrum.internal.hooks.Scope;18import com.greghaskins.spectrum.internal.hooks.ScopeType;19import com.greghaskins.spectrum.internal.hooks.SpecHook;20import com.greghaskins.spectrum.internal.hooks.SuiteHook;21import com.greghaskins.spectrum.internal.hooks.TestHook;22import com.greghaskins.spectrum.internal.hooks.TestHookContext;23import com.greghaskins.spectrum.internal.hooks.TestHooks;24import com.greghaskins.spectrum.internal.hooks.TestHooksContext;25import com.greghaskins.spectrum.internal.hooks.TestHooksState;26import com.greghaskins.spectrum.internal.hooks.TestHooksState.HookedBlock;27import com.greghaskins.spectrum.internal.hooks.TestHooksState.HookedBlockType;28import com.greghaskins.spectrum.internal.hooks.TestHooksState.HookedBlockTypeAndScope;29import com.greghaskins.spectrum.internal.hooks.TestHooksState.HookedBlockTypeAndScopeAndBlock;30import com.greghaskins.spectrum.internal.hooks.TestHooksState.HookedBlockTypeAndScopeAnd

Full Screen

Full Screen

instance

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 com.greghaskins.spectrum.internal.DeclarationState state = new com.greghaskins.spectrum.internal.DeclarationState();4 state.getStackTrace();5 }6}7com.greghaskins.spectrum.internal.DeclarationState.getStackTrace(DeclarationState.java:81)8com.greghaskins.spectrum.internal.DeclarationState.getStackTrace(DeclarationState.java:1)91.main(1.java:8)10com.greghaskins.spectrum.internal.DeclarationState.getStackTrace(DeclarationState.java:81)11com.greghaskins.spectrum.internal.DeclarationState.getStackTrace(DeclarationState.java:1)121.main(1.java:8)

Full Screen

Full Screen

instance

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum.internal;2import com.greghaskins.spectrum.Spectrum;3import com.greghaskins.spectrum.Spectrum.*;4import org.junit.runner.*;5import org.junit.runner.notification.*;6import org.junit.runners.model.*;7public class RunListener extends RunListener {8 private String className;9 private String methodName;10 public void testStarted(Description description) throws Exception {11 className = description.getClassName();12 methodName = description.getMethodName();13 System.out.println("Test started: " + className + " " + methodName);14 }15 public void testFinished(Description description) throws Exception {16 System.out.println("Test finished: " + className + " " + methodName);17 }18 public void testFailure(Failure failure) throws Exception {19 System.out.println("Test failed: " + className + " " + methodName);20 }21 public void testIgnored(Description description) throws Exception {22 System.out.println("Test ignored: " + className + " " + methodName);23 }24}25package com.greghaskins.spectrum.internal;26import com.greghaskins.spectrum.Spectrum;27import com.greghaskins.spectrum.Spectrum.*;28import org.junit.runner.*;29import org.junit.runner.notification.*;30import org.junit.runners.model.*;31public class RunListener extends RunListener {32 private String className;33 private String methodName;34 public void testStarted(Description description) throws Exception {35 className = description.getClassName();36 methodName = description.getMethodName();37 System.out.println("Test started: " + className + " " + methodName);38 }39 public void testFinished(Description description) throws Exception {40 System.out.println("Test finished: " + className + " " + methodName);41 }42 public void testFailure(Failure failure) throws Exception {43 System.out.println("Test failed: " +

Full Screen

Full Screen

instance

Using AI Code Generation

copy

Full Screen

1package com.greghaskins.spectrum.internal;2public class GetTestName {3 public static String getTestName() {4 return DeclarationState.getCurrentTestName();5 }6}7package com.greghaskins.spectrum.internal;8public class GetTestName {9 public static String getTestName() {10 return DeclarationState.getCurrentTestName();11 }12}13package com.greghaskins.spectrum.internal;14public class GetTestName {15 public static String getTestName() {16 return DeclarationState.getCurrentTestName();17 }18}19package com.greghaskins.spectrum.internal;20public class GetTestName {21 public static String getTestName() {22 return DeclarationState.getCurrentTestName();23 }24}25package com.greghaskins.spectrum.internal;26public class GetTestName {27 public static String getTestName() {28 return DeclarationState.getCurrentTestName();29 }30}

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 Spectrum automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful