How to use sanitise method of com.greghaskins.spectrum.internal.NameSanitiser class

Best Spectrum code snippet using com.greghaskins.spectrum.internal.NameSanitiser.sanitise

Source:Suite.java Github

copy

Full Screen

...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 }100 /**101 * Adds a hook to be the first one executed before the block. This is the default. Hooks should be102 * executed in the order they are declared in the test.103 *104 * @param hook to add105 */106 public void addHook(final HookContext hook) {107 this.hooks.add(hook);108 }109 private Hooks getHooksFor(final Child child) {110 Hooks allHooks = this.parent.getInheritableHooks().plus(this.hooks);111 return child.isAtomic() ? allHooks.forAtomic() : allHooks.forNonAtomic();112 }113 @Override114 public Hooks getInheritableHooks() {115 // only the atomic hooks can be used by the children of this suite,116 // all other hooks would be executed at suite level only - either for117 // each child of the suite, or once118 return this.parent.getInheritableHooks().plus(this.hooks.forAtomic());119 }120 /**121 * Set the suite to require certain tags of all tests below.122 *123 * @param tags required tags - suites must have at least one of these if any are specified124 */125 public void includeTags(final String... tags) {126 this.tagging.include(tags);127 }128 /**129 * Set the suite to exclude certain tags of all tests below.130 *131 * @param tags excluded tags - suites and specs must not have any of these if any are specified132 */133 public void excludeTags(final String... tags) {134 this.tagging.exclude(tags);135 }136 @Override137 public void focus(final Child child) {138 this.focusedChildren.add(child);139 focus();140 }141 @Override142 public void focus() {143 if (this.ignored) {144 return;145 }146 this.parent.focus(this);147 }148 @Override149 public void ignore() {150 this.ignored = true;151 }152 @Override153 public boolean isIgnored() {154 return this.ignored;155 }156 @Override157 public void run(final RunReporting<Description, Failure> reporting) {158 if (testCount() == 0) {159 reporting.fireTestIgnored(this.description);160 runChildren(reporting);161 } else {162 runSuite(reporting);163 }164 }165 private void runSuite(final RunReporting<Description, Failure> reporting) {166 if (isEffectivelyIgnored()) {167 runChildren(reporting);168 } else {169 this.hooks.once().sorted()170 .runAround(this.description, reporting, () -> runChildren(reporting));171 }172 }173 private void runChildren(final RunReporting<Description, Failure> reporting) {174 this.childRunner.runChildren(this, reporting);175 }176 protected void runChild(final Child child, final RunReporting<Description, Failure> reporting) {177 if (child.isEffectivelyIgnored()) {178 // running the child will make it act ignored179 child.run(reporting);180 } else if (childIsNotInFocus(child)) {181 reporting.fireTestIgnored(child.getDescription());182 } else {183 addLeafHook(this.hooks.forThisLevel().sorted(), child).runAround(child.getDescription(), reporting,184 () -> runChildWithHooks(child, reporting));185 }186 }187 private boolean childIsNotInFocus(Child child) {188 return !this.focusedChildren.isEmpty() && !this.focusedChildren.contains(child);189 }190 private void runChildWithHooks(final Child child, final RunReporting<Description, Failure> reporting) {191 getHooksFor(child).sorted().runAround(child.getDescription(), reporting,192 () -> child.run(reporting));193 }194 private Hooks addLeafHook(final Hooks hooks, final Child child) {195 if (child.isLeaf()) {196 hooks.add(testNotifier());197 }198 return hooks;199 }200 private HookContext testNotifier() {201 return new HookContext(testNotificationHook(), 0, HookContext.AppliesTo.ONCE,202 HookContext.Precedence.ROOT);203 }204 private Hook testNotificationHook() {205 return (description, notifier, block) -> {206 notifier.fireTestStarted(description);207 try {208 block.run();209 } finally {210 notifier.fireTestFinished(description);211 }212 };213 }214 @Override215 public Description getDescription() {216 final Description copy = this.description.childlessCopy();217 this.children.forEach((child) -> copy.addChild(child.getDescription()));218 return copy;219 }220 @Override221 public int testCount() {222 return this.children.stream().mapToInt(Child::testCount).sum();223 }224 public void removeAllChildren() {225 this.children.clear();226 }227 private static void defaultChildRunner(final Suite suite,228 final RunReporting<Description, Failure> reporting) {229 suite.children.forEach((child) -> suite.runChild(child, reporting));230 }231 private String sanitise(final String name) {232 return this.nameSanitiser.sanitise(name);233 }234 @Override235 public boolean isEffectivelyIgnored() {236 return this.ignored || !hasANonIgnoredChild();237 }238 private boolean hasANonIgnoredChild() {239 return this.children.stream()240 .anyMatch(child -> !child.isEffectivelyIgnored());241 }242}...

Full Screen

Full Screen

Source:NameSanitiser.java Github

copy

Full Screen

...13 * <p>Note: this function has side effects - sanitising a name will cause it to be remembered for future14 * deduplication purposes.15 *16 * @param name the spec name17 * @return a name unique to this sanitiser which has known bad characters removed.18 */19 public String sanitise(final String name) {20 String sanitised = name.replaceAll("\\(", "[")21 .replaceAll("\\)", "]");22 sanitised = sanitised.replaceAll("\\.", "_");23 int suffix = 1;24 String deDuplicated = sanitised;25 while (this.namesUsed.contains(deDuplicated)) {26 deDuplicated = sanitised + "_" + suffix++;27 }28 this.namesUsed.add(deDuplicated);29 return deDuplicated;30 }31}...

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2public class 1 {3 public static void main(String[] args) {4 String s = NameSanitiser.sanitise("Hello World");5 System.out.println(s);6 }7}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2public class SanitiseTest {3 public static void main(String[] args) {4 String name = "test";5 System.out.println(NameSanitiser.sanitise(name));6 }7}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2public class 1 {3 public static void main(String[] args) {4 String str = NameSanitiser.sanitise("Test 1");5 System.out.println(str);6 }7}8import com.greghaskins.spectrum.internal.NameSanitiser;9public class 2 {10 public static void main(String[] args) {11 String str = NameSanitiser.sanitise("Test 2");12 System.out.println(str);13 }14}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2public class Test {3 public static void main(String[] args) {4 String name = "Test Name";5 System.out.println("Sanitised Name: " + NameSanitiser.sanitise(name));6 }7}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2import java.lang.reflect.Method;3import java.lang.reflect.Modifier;4import java.util.Arrays;5import java.util.List;6import java.util.stream.Collectors;7public class TestSanitiser {8 public static void main(String[] args) throws NoSuchMethodException {9 final Method method = TestSanitiser.class.getDeclaredMethod("test method");10 final String sanitisedName = NameSanitiser.sanitise(method);11 System.out.println(sanitisedName);12 }13 public static void test method() {14 }15}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2public class 1 {3 public static void main(String[] args) {4 String name = "Test Name";5 System.out.println(NameSanitiser.sanitise(name));6 }7}8java -cp .;spectrum-0.7.10.jar 19java -cp .;spectrum-0.7.10.jar 1 "Test Name"10import com.greghaskins.spectrum.internal.NameSanitiser;11public class 1 {12 public static void main(String[] args) {13 String name = "Test Name";14 System.out.println(NameSanitiser.sanitise(name));15 }16}17java -cp .;spectrum-0.7.10.jar 1 "Test Name"18import com.greghaskins.spectrum.internal.NameSanitiser;19public class 1 {

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1public class NameSanitiserTest {2 public void testSanitise() {3 String name = "testName";4 String sanitisedName = NameSanitiser.sanitise(name);5 assertEquals("testName", sanitisedName);6 }7}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 String name = "test_1";4 String sanitisedName = NameSanitiser.sanitise(name);5 System.out.println(sanitisedName);6 }7}8public class 2 {9 public static void main(String[] args) {10 String name = "test_2";11 String sanitisedName = NameSanitiser.sanitise(name);12 System.out.println(sanitisedName);13 }14}

Full Screen

Full Screen

sanitise

Using AI Code Generation

copy

Full Screen

1import com.greghaskins.spectrum.internal.NameSanitiser;2public class 1 {3 public static void main(String[] args) {4 String methodName = NameSanitiser.sanitise("test method 2 (with parentheses)");5 System.out.println(methodName);6 }7}

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.

Most used method in NameSanitiser

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful