Best Spectrum code snippet using com.greghaskins.spectrum.internal.configuration.BlockConfiguration
Source:Suite.java
1package com.greghaskins.spectrum.internal;2import static com.greghaskins.spectrum.internal.configuration.BlockConfiguration.merge;3import com.greghaskins.spectrum.Block;4import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;5import com.greghaskins.spectrum.internal.configuration.ConfiguredBlock;6import com.greghaskins.spectrum.internal.configuration.TaggingFilterCriteria;7import com.greghaskins.spectrum.internal.hooks.Hook;8import com.greghaskins.spectrum.internal.hooks.HookContext;9import com.greghaskins.spectrum.internal.hooks.Hooks;10import org.junit.runner.Description;11import org.junit.runner.notification.Failure;12import java.util.ArrayList;13import java.util.HashSet;14import java.util.List;15import java.util.Set;16public class Suite implements Parent, Child {17 private Hooks hooks = new Hooks();18 protected final List<Child> children = new ArrayList<>();19 private final Set<Child> focusedChildren = new HashSet<>();20 private final ChildRunner childRunner;21 private final Description description;22 private final Parent parent;23 private boolean ignored;24 private final TaggingFilterCriteria tagging;25 private BlockConfiguration configuration = BlockConfiguration.defaultConfiguration();26 private NameSanitiser nameSanitiser = new NameSanitiser();27 /**28 * The strategy for running the children within the suite.29 */30 @FunctionalInterface31 interface ChildRunner {32 void runChildren(final Suite suite, final RunReporting<Description, Failure> reporting);33 }34 public static Suite rootSuite(final Description description) {35 return new Suite(description, Parent.NONE, Suite::defaultChildRunner,36 new TaggingFilterCriteria());37 }38 /**39 * Constructs a suite.40 *41 * @param description the JUnit description42 * @param parent parent item43 * @param childRunner which child running strategy to use - this will normally be44 * {@link #defaultChildRunner(Suite, RunReporting)} which runs them all but can be45 * substituted.46 * @param taggingFilterCriteria the state of tagging inherited from the parent47 */48 protected Suite(final Description description, final Parent parent, final ChildRunner childRunner,49 final TaggingFilterCriteria taggingFilterCriteria) {50 this.description = description;51 this.parent = parent;52 this.ignored = parent.isIgnored();53 this.childRunner = childRunner;54 this.tagging = taggingFilterCriteria;55 }56 public Suite addSuite(final String name) {57 return addSuite(name, Suite::defaultChildRunner);58 }59 private Suite addSuite(final String name, final ChildRunner childRunner) {60 final Suite suite = new Suite(Description.createSuiteDescription(sanitise(name)), this, childRunner,61 this.tagging.clone());62 suite.inheritConfigurationFromParent(configuration.forChild());63 return addedToThis(suite);64 }65 private Suite addedToThis(Suite suite) {66 addChild(suite);67 return suite;68 }69 public Suite addCompositeSuite(final String name) {70 final Suite suite =71 new CompositeTest(Description.createSuiteDescription(sanitise(name)), this,72 this.tagging.clone());73 return addedToThis(suite);74 }75 public Child addSpec(final String name, final Block block) {76 final Child spec = createSpec(name, block);77 addChild(spec);78 return spec;79 }80 private Child createSpec(final String name, final Block block) {81 final Description specDescription =82 Description.createTestDescription(this.description.getClassName(), sanitise(name));83 return configuredChild(new Spec(specDescription, block, this), block);84 }85 private void inheritConfigurationFromParent(final BlockConfiguration fromParent) {86 configuration = merge(fromParent, configuration);87 }88 private Child configuredChild(final Child child, final Block block) {89 merge(this.configuration.forChild(), ConfiguredBlock.configurationFromBlock(block))90 .applyTo(child, this.tagging);91 return child;92 }93 public void applyConfigurationFromBlock(Block block) {94 this.configuration = merge(this.configuration, ConfiguredBlock.configurationFromBlock(block));95 this.configuration.applyTo(this, this.tagging);96 }97 private void addChild(final Child child) {98 this.children.add(child);99 }...
Source:BlockConfigurationSpecs.java
...7import static org.hamcrest.MatcherAssert.assertThat;8import static org.hamcrest.Matchers.is;9import com.greghaskins.spectrum.Spectrum;10import com.greghaskins.spectrum.SpectrumHelper;11import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;12import org.junit.runner.Result;13import org.junit.runner.RunWith;14import java.util.function.Supplier;15/**16 * Demonstrate how to focus and ignore specs using17 * {@link BlockConfiguration}.18 */19@RunWith(Spectrum.class)20public class BlockConfigurationSpecs {21 {22 describe("The ignore() configuration", () -> {23 describe("at the suite level", () -> {24 Supplier<Result> result = let(() -> SpectrumHelper.run(() -> {25 describe("Has ignored suite", with(ignore(), () -> {26 it("will not run this spec", () -> {27 });28 it("or this spec", () -> {29 });30 }));31 }));32 it("marks all its specs as ignored", () -> {33 assertThat(result.get().getIgnoreCount(), is(2));34 });...
Source:BlockConfigurationChain.java
1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.configuration.BlockConfigurable;3import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;4import com.greghaskins.spectrum.internal.configuration.ConfiguredBlock;5import java.util.stream.Stream;6/**7 * Chainable configuration of a {@link ConfiguredBlock}.8 * Use the factory methods in {@link Spectrum} like {@link Configure#ignore()},9 * {@link Configure#focus()} or {@link Configure#tags(String...)} to add configuration10 * to a block. The result will be a {@link BlockConfigurationChain}. To add configurations together11 * you use {@link BlockConfigurationChain#and(BlockConfigurationChain)}. This is fluent12 * so ands can be chained together.<br><br>13 * e.g.<pre>with(ignore().and(tags("a","b","c")).and(tags("d","e","f"), () -> {...})</pre><br>14 * See also: {@link Configure#with(BlockConfigurationChain, Block)}15 */16public final class BlockConfigurationChain {17 private BlockConfiguration blockConfiguration = BlockConfiguration.defaultConfiguration();18 BlockConfigurationChain() {}19 /**20 * Fluent call to add a configurable to the configuration.21 * @param configurable to add.22 * @return this for fluent calling - users will use {@link #and(BlockConfigurationChain)}23 */24 BlockConfigurationChain with(BlockConfigurable<?> configurable) {25 blockConfiguration.add(configurable);26 return this;27 }28 /**29 * Add another configuration to the chain.30 * @param chain the configurable to add.31 * @return this for fluent calls32 */33 public BlockConfigurationChain and(BlockConfigurationChain chain) {34 chain.getConfigurables().forEach(this::with);35 return this;36 }37 BlockConfiguration getBlockConfiguration() {38 return this.blockConfiguration;39 }40 private Stream<BlockConfigurable<?>> getConfigurables() {41 return this.blockConfiguration.getConfigurables();42 }43}...
BlockConfiguration
Using AI Code Generation
1package com.greghaskins.spectrum;2import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;3import com.greghaskins.spectrum.internal.configuration.Configuration;4import com.greghaskins.spectrum.internal.configuration.ConfigurationBuilder;5public class ConfigurationBuilderTest {6 private ConfigurationBuilder builder;7 public void setUp() {8 builder = new ConfigurationBuilder();9 }10 public void configurationBuilderReturnsConfigurationWithNoBlocksWhenNoBlocksAreAdded() {11 Configuration configuration = builder.build();12 assertThat(configuration.getBlocks()).isEmpty();13 }14 public void configurationBuilderReturnsConfigurationWithOneBlockWhenOneBlockIsAdded() {15 BlockConfiguration block = new BlockConfiguration("description", null, null);16 builder.addBlock(block);17 Configuration configuration = builder.build();18 assertThat(configuration.getBlocks()).containsExactly(block);19 }20 public void configurationBuilderReturnsConfigurationWithTwoBlocksWhenTwoBlocksAreAdded() {21 BlockConfiguration block1 = new BlockConfiguration("description 1", null, null);22 BlockConfiguration block2 = new BlockConfiguration("description 2", null, null);23 builder.addBlock(block1);24 builder.addBlock(block2);25 Configuration configuration = builder.build();26 assertThat(configuration.getBlocks()).containsExactly(block1, block2);27 }28}29package com.greghaskins.spectrum.internal.configuration;30import com.greghaskins.spectrum.internal.Block;31import java.util.ArrayList;32import java.util.List;33public class ConfigurationBuilder {34 private final List<BlockConfiguration> blocks = new ArrayList<>();35 public void addBlock(BlockConfiguration block) {36 blocks.add(block);37 }38 public Configuration build() {39 return new Configuration(blocks);40 }41}42package com.greghaskins.spectrum.internal.configuration;43import com.greghaskins.spectrum.internal.Block;44import java.util.List;45public class Configuration {46 private final List<BlockConfiguration> blocks;47 public Configuration(List<BlockConfiguration> blocks) {48 this.blocks = blocks;49 }50 public List<BlockConfiguration> getBlocks() {51 return blocks;52 }53}54package com.greghaskins.spectrum.internal.configuration;55import com.greghaskins.spectrum.internal.Block;56public class BlockConfiguration {57 private final String description;58 private final Block block;
BlockConfiguration
Using AI Code Generation
1import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;2import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;3public class MyTest {4 public void test() {5 BlockConfiguration config = new BlockConfiguration();6 }7}
BlockConfiguration
Using AI Code Generation
1import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;2import com.greghaskins.spectrum.internal.configuration.BlockConfiguration.BlockConfigurationBuilder;3import java.util.function.Consumer;4public class BlockConfigurationTest {5 public static void main(String[] args) {6 BlockConfigurationBuilder builder = new BlockConfigurationBuilder();7 builder.addBlockConfiguration(new BlockConfiguration("test", null, null, null));8 builder.addBlockConfiguration(new BlockConfiguration("test1", null, null, null));9 builder.addBlockConfiguration(new BlockConfiguration("test2", null, null, null));10 builder.addBlockConfiguration(new BlockConfiguration("test3", null, null, null));11 builder.addBlockConfiguration(new BlockConfiguration("test4", null, null, null));12 builder.addBlockConfiguration(new BlockConfiguration("test5", null, null, null));13 builder.addBlockConfiguration(new BlockConfiguration("test6", null, null, null));14 builder.addBlockConfiguration(new BlockConfiguration("test7", null, null, null));15 builder.addBlockConfiguration(new BlockConfiguration("test8", null, null, null));16 builder.addBlockConfiguration(new BlockConfiguration("test9", null, null, null));17 builder.addBlockConfiguration(new BlockConfiguration("test10", null, null, null));18 builder.addBlockConfiguration(new BlockConfiguration("test11", null, null, null));19 builder.addBlockConfiguration(new BlockConfiguration("test12", null, null, null));20 builder.addBlockConfiguration(new BlockConfiguration("test13", null, null, null));21 builder.addBlockConfiguration(new BlockConfiguration("test14", null, null, null));22 builder.addBlockConfiguration(new BlockConfiguration("test15", null, null, null));23 builder.addBlockConfiguration(new BlockConfiguration("test16", null, null, null));24 builder.addBlockConfiguration(new BlockConfiguration("test17", null, null, null));25 builder.addBlockConfiguration(new BlockConfiguration("test18", null, null, null));26 builder.addBlockConfiguration(new BlockConfiguration("test19", null, null, null));27 builder.addBlockConfiguration(new BlockConfiguration("test20", null, null, null));28 builder.addBlockConfiguration(new BlockConfiguration("test21", null, null, null));29 builder.addBlockConfiguration(new BlockConfiguration("test22", null, null, null));30 builder.addBlockConfiguration(new BlockConfiguration("test23", null, null, null));
BlockConfiguration
Using AI Code Generation
1import com.greghaskins.spectrum.Spectrum;2import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;3import com.greghaskins.spectrum.internal.configuration.BlockConfiguration.BlockConfigurationBuilder;4public class BlockConfigurationTest {5 public static void main(String[] args) {6 BlockConfigurationBuilder blockConfigurationBuilder = BlockConfiguration.builder();7 blockConfigurationBuilder.setBlockConfiguration("com.greghaskins.spectrum.internal.configuration.BlockConfigurationTest$MyClass");8 BlockConfiguration blockConfiguration = blockConfigurationBuilder.build();9 System.out.println(blockConfiguration);10 }11 public static class MyClass {12 public static BlockConfiguration blockConfiguration() {13 return BlockConfiguration.builder().build();14 }15 }16}
BlockConfiguration
Using AI Code Generation
1import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;2import com.greghaskins.spectrum.internal.configuration.Configuration;3import com.greghaskins.spectrum.internal.configuration.ConfigurationHolder;4import com.greghaskins.spectrum.internal.configuration.ConfigurationHolder.ConfigurationHolderBuilder;5public class One {6 public static void main(String[] args) {7 ConfigurationHolderBuilder builder = ConfigurationHolder.builder();8 builder.setConfiguration(Configuration.builder().build());9 ConfigurationHolder holder = builder.build();10 ConfigurationHolder.setInstance(holder);11 ConfigurationHolder.getInstance().getConfiguration()12 .getBlocks()13 .forEach(b -> System.out.println(b.getClass().getName()));14 }15}16import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;17import com.greghaskins.spectrum.internal.configuration.Configuration;18import com.greghaskins.spectrum.internal.configuration.ConfigurationHolder;19import com.greghaskins.spectrum.internal.configuration.ConfigurationHolder.ConfigurationHolderBuilder;20public class Two {21 public static void main(String[] args) {22 ConfigurationHolderBuilder builder = ConfigurationHolder.builder();
BlockConfiguration
Using AI Code Generation
1import com.greghaskins.spectrum.internal.configuration.BlockConfiguration;2import com.greghaskins.spectrum.internal.configuration.Configuration;3import com.greghaskins.spectrum.internal.configuration.ConfigurationFactory;4import com.greghaskins.spectrum.internal.configuration.ConfigurationFactoryImpl;5import com.greghaskins.spectrum.internal.configuration.TestConfiguration;6import com.greghaskins.spectrum.internal.configuration.TestConfigurationImpl;7import com.greghaskins.spectrum.internal.configuration.TestStatus;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!