How to use run method of org.testng.Interface Assert.ThrowingRunnable class

Best Testng code snippet using org.testng.Interface Assert.ThrowingRunnable.run

Source:Defaults.java Github

copy

Full Screen

...24 * @test25 * @bug 8010122 8004518 8024331 802468826 * @summary Test Map default methods27 * @author Mike Duigou28 * @run testng Defaults29 */30import java.util.AbstractMap;31import java.util.AbstractSet;32import java.util.ArrayList;33import java.util.Arrays;34import java.util.Collection;35import java.util.Collections;36import java.util.EnumMap;37import java.util.HashMap;38import java.util.Hashtable;39import java.util.HashSet;40import java.util.IdentityHashMap;41import java.util.Iterator;42import java.util.LinkedHashMap;43import java.util.Map;44import java.util.TreeMap;45import java.util.Set;46import java.util.WeakHashMap;47import java.util.concurrent.ConcurrentMap;48import java.util.concurrent.ConcurrentHashMap;49import java.util.concurrent.ConcurrentSkipListMap;50import java.util.concurrent.atomic.AtomicBoolean;51import java.util.function.BiFunction;52import java.util.function.Function;53import java.util.function.Supplier;54import org.testng.Assert.ThrowingRunnable;55import org.testng.annotations.Test;56import org.testng.annotations.DataProvider;57import static java.util.Objects.requireNonNull;58import static org.testng.Assert.fail;59import static org.testng.Assert.assertEquals;60import static org.testng.Assert.assertTrue;61import static org.testng.Assert.assertFalse;62import static org.testng.Assert.assertNull;63import static org.testng.Assert.assertSame;64import static org.testng.Assert.assertThrows;65public class Defaults {66 @Test(dataProvider = "Map<IntegerEnum,String> rw=all keys=withNull values=withNull")67 public void testGetOrDefaultNulls(String description, Map<IntegerEnum, String> map) {68 assertTrue(map.containsKey(null), description + ": null key absent");69 assertNull(map.get(null), description + ": value not null");70 assertSame(map.get(null), map.getOrDefault(null, EXTRA_VALUE), description + ": values should match");71 }72 @Test(dataProvider = "Map<IntegerEnum,String> rw=all keys=all values=all")73 public void testGetOrDefault(String description, Map<IntegerEnum, String> map) {74 assertTrue(map.containsKey(KEYS[1]), "expected key missing");75 assertSame(map.get(KEYS[1]), map.getOrDefault(KEYS[1], EXTRA_VALUE), "values should match");76 assertFalse(map.containsKey(EXTRA_KEY), "expected absent key");77 assertSame(map.getOrDefault(EXTRA_KEY, EXTRA_VALUE), EXTRA_VALUE, "value not returned as default");78 assertNull(map.getOrDefault(EXTRA_KEY, null), "null not returned as default");79 }80 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")81 public void testPutIfAbsentNulls(String description, Map<IntegerEnum, String> map) {82 // null -> null83 assertTrue(map.containsKey(null), "null key absent");84 assertNull(map.get(null), "value not null");85 assertNull(map.putIfAbsent(null, EXTRA_VALUE), "previous not null");86 // null -> EXTRA_VALUE87 assertTrue(map.containsKey(null), "null key absent");88 assertSame(map.get(null), EXTRA_VALUE, "unexpected value");89 assertSame(map.putIfAbsent(null, null), EXTRA_VALUE, "previous not expected value");90 assertTrue(map.containsKey(null), "null key absent");91 assertSame(map.get(null), EXTRA_VALUE, "unexpected value");92 assertSame(map.remove(null), EXTRA_VALUE, "removed unexpected value");93 // null -> <absent>94 assertFalse(map.containsKey(null), description + ": key present after remove");95 assertNull(map.putIfAbsent(null, null), "previous not null");96 // null -> null97 assertTrue(map.containsKey(null), "null key absent");98 assertNull(map.get(null), "value not null");99 assertNull(map.putIfAbsent(null, EXTRA_VALUE), "previous not null");100 assertSame(map.get(null), EXTRA_VALUE, "value not expected");101 }102 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")103 public void testPutIfAbsent(String description, Map<IntegerEnum, String> map) {104 // 1 -> 1105 assertTrue(map.containsKey(KEYS[1]));106 Object expected = map.get(KEYS[1]);107 assertTrue(null == expected || expected == VALUES[1]);108 assertSame(map.putIfAbsent(KEYS[1], EXTRA_VALUE), expected);109 assertSame(map.get(KEYS[1]), expected);110 // EXTRA_KEY -> <absent>111 assertFalse(map.containsKey(EXTRA_KEY));112 assertSame(map.putIfAbsent(EXTRA_KEY, EXTRA_VALUE), null);113 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);114 assertSame(map.putIfAbsent(EXTRA_KEY, VALUES[2]), EXTRA_VALUE);115 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);116 }117 @Test(dataProvider = "Map<IntegerEnum,String> rw=all keys=all values=all")118 public void testForEach(String description, Map<IntegerEnum, String> map) {119 IntegerEnum[] EACH_KEY = new IntegerEnum[map.size()];120 map.forEach((k, v) -> {121 int idx = (null == k) ? 0 : k.ordinal(); // substitute for index.122 assertNull(EACH_KEY[idx]);123 EACH_KEY[idx] = (idx == 0) ? KEYS[0] : k; // substitute for comparison.124 assertSame(v, map.get(k));125 });126 assertEquals(KEYS, EACH_KEY, description);127 }128 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")129 public static void testReplaceAll(String description, Map<IntegerEnum, String> map) {130 IntegerEnum[] EACH_KEY = new IntegerEnum[map.size()];131 Set<String> EACH_REPLACE = new HashSet<>(map.size());132 map.replaceAll((k,v) -> {133 int idx = (null == k) ? 0 : k.ordinal(); // substitute for index.134 assertNull(EACH_KEY[idx]);135 EACH_KEY[idx] = (idx == 0) ? KEYS[0] : k; // substitute for comparison.136 assertSame(v, map.get(k));137 String replacement = v + " replaced";138 EACH_REPLACE.add(replacement);139 return replacement;140 });141 assertEquals(KEYS, EACH_KEY, description);142 assertEquals(map.values().size(), EACH_REPLACE.size(), description + EACH_REPLACE);143 assertTrue(EACH_REPLACE.containsAll(map.values()), description + " : " + EACH_REPLACE + " != " + map.values());144 assertTrue(map.values().containsAll(EACH_REPLACE), description + " : " + EACH_REPLACE + " != " + map.values());145 }146 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=nonNull values=nonNull")147 public static void testReplaceAllNoNullReplacement(String description, Map<IntegerEnum, String> map) {148 assertThrowsNPE(() -> map.replaceAll(null));149 assertThrowsNPE(() -> map.replaceAll((k,v) -> null)); //should not allow replacement with null value150 }151 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")152 public static void testRemoveNulls(String description, Map<IntegerEnum, String> map) {153 assertTrue(map.containsKey(null), "null key absent");154 assertNull(map.get(null), "value not null");155 assertFalse(map.remove(null, EXTRA_VALUE), description);156 assertTrue(map.containsKey(null));157 assertNull(map.get(null));158 assertTrue(map.remove(null, null));159 assertFalse(map.containsKey(null));160 assertNull(map.get(null));161 assertFalse(map.remove(null, null));162 }163 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")164 public static void testRemove(String description, Map<IntegerEnum, String> map) {165 assertTrue(map.containsKey(KEYS[1]));166 Object expected = map.get(KEYS[1]);167 assertTrue(null == expected || expected == VALUES[1]);168 assertFalse(map.remove(KEYS[1], EXTRA_VALUE), description);169 assertSame(map.get(KEYS[1]), expected);170 assertTrue(map.remove(KEYS[1], expected));171 assertNull(map.get(KEYS[1]));172 assertFalse(map.remove(KEYS[1], expected));173 assertFalse(map.containsKey(EXTRA_KEY));174 assertFalse(map.remove(EXTRA_KEY, EXTRA_VALUE));175 }176 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")177 public void testReplaceKVNulls(String description, Map<IntegerEnum, String> map) {178 assertTrue(map.containsKey(null), "null key absent");179 assertNull(map.get(null), "value not null");180 assertSame(map.replace(null, EXTRA_VALUE), null);181 assertSame(map.get(null), EXTRA_VALUE);182 }183 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=nonNull values=nonNull")184 public void testReplaceKVNoNulls(String description, Map<IntegerEnum, String> map) {185 assertTrue(map.containsKey(FIRST_KEY), "expected key missing");186 assertSame(map.get(FIRST_KEY), FIRST_VALUE, "found wrong value");187 assertThrowsNPE(() -> map.replace(FIRST_KEY, null));188 assertSame(map.replace(FIRST_KEY, EXTRA_VALUE), FIRST_VALUE, description + ": replaced wrong value");189 assertSame(map.get(FIRST_KEY), EXTRA_VALUE, "found wrong value");190 }191 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")192 public void testReplaceKV(String description, Map<IntegerEnum, String> map) {193 assertTrue(map.containsKey(KEYS[1]));194 Object expected = map.get(KEYS[1]);195 assertTrue(null == expected || expected == VALUES[1]);196 assertSame(map.replace(KEYS[1], EXTRA_VALUE), expected);197 assertSame(map.get(KEYS[1]), EXTRA_VALUE);198 assertFalse(map.containsKey(EXTRA_KEY));199 assertNull(map.replace(EXTRA_KEY, EXTRA_VALUE));200 assertFalse(map.containsKey(EXTRA_KEY));201 assertNull(map.get(EXTRA_KEY));202 assertNull(map.put(EXTRA_KEY, EXTRA_VALUE));203 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);204 assertSame(map.replace(EXTRA_KEY, (String)expected), EXTRA_VALUE);205 assertSame(map.get(EXTRA_KEY), expected);206 }207 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")208 public void testReplaceKVVNulls(String description, Map<IntegerEnum, String> map) {209 assertTrue(map.containsKey(null), "null key absent");210 assertNull(map.get(null), "value not null");211 assertFalse(map.replace(null, EXTRA_VALUE, EXTRA_VALUE));212 assertNull(map.get(null));213 assertTrue(map.replace(null, null, EXTRA_VALUE));214 assertSame(map.get(null), EXTRA_VALUE);215 assertTrue(map.replace(null, EXTRA_VALUE, EXTRA_VALUE));216 assertSame(map.get(null), EXTRA_VALUE);217 }218 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=nonNull values=nonNull")219 public void testReplaceKVVNoNulls(String description, Map<IntegerEnum, String> map) {220 assertTrue(map.containsKey(FIRST_KEY), "expected key missing");221 assertSame(map.get(FIRST_KEY), FIRST_VALUE, "found wrong value");222 assertThrowsNPE(() -> map.replace(FIRST_KEY, FIRST_VALUE, null));223 assertThrowsNPE(224 () -> {225 if (!map.replace(FIRST_KEY, null, EXTRA_VALUE)) {226 throw new NullPointerException("default returns false rather than throwing");227 }228 });229 assertTrue(map.replace(FIRST_KEY, FIRST_VALUE, EXTRA_VALUE), description + ": replaced wrong value");230 assertSame(map.get(FIRST_KEY), EXTRA_VALUE, "found wrong value");231 }232 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")233 public void testReplaceKVV(String description, Map<IntegerEnum, String> map) {234 assertTrue(map.containsKey(KEYS[1]));235 Object expected = map.get(KEYS[1]);236 assertTrue(null == expected || expected == VALUES[1]);237 assertFalse(map.replace(KEYS[1], EXTRA_VALUE, EXTRA_VALUE));238 assertSame(map.get(KEYS[1]), expected);239 assertTrue(map.replace(KEYS[1], (String)expected, EXTRA_VALUE));240 assertSame(map.get(KEYS[1]), EXTRA_VALUE);241 assertTrue(map.replace(KEYS[1], EXTRA_VALUE, EXTRA_VALUE));242 assertSame(map.get(KEYS[1]), EXTRA_VALUE);243 assertFalse(map.containsKey(EXTRA_KEY));244 assertFalse(map.replace(EXTRA_KEY, EXTRA_VALUE, EXTRA_VALUE));245 assertFalse(map.containsKey(EXTRA_KEY));246 assertNull(map.get(EXTRA_KEY));247 assertNull(map.put(EXTRA_KEY, EXTRA_VALUE));248 assertTrue(map.containsKey(EXTRA_KEY));249 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);250 assertTrue(map.replace(EXTRA_KEY, EXTRA_VALUE, EXTRA_VALUE));251 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);252 }253 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")254 public void testComputeIfAbsentNulls(String description, Map<IntegerEnum, String> map) {255 // null -> null256 assertTrue(map.containsKey(null), "null key absent");257 assertNull(map.get(null), "value not null");258 assertSame(map.computeIfAbsent(null, (k) -> null), null, "not expected result");259 assertTrue(map.containsKey(null), "null key absent");260 assertNull(map.get(null), "value not null");261 assertSame(map.computeIfAbsent(null, (k) -> EXTRA_VALUE), EXTRA_VALUE, "not mapped to result");262 // null -> EXTRA_VALUE263 assertTrue(map.containsKey(null), "null key absent");264 assertSame(map.get(null), EXTRA_VALUE, "not expected value");265 assertSame(map.remove(null), EXTRA_VALUE, "removed unexpected value");266 // null -> <absent>267 assertFalse(map.containsKey(null), "null key present");268 assertSame(map.computeIfAbsent(null, (k) -> EXTRA_VALUE), EXTRA_VALUE, "not mapped to result");269 // null -> EXTRA_VALUE270 assertTrue(map.containsKey(null), "null key absent");271 assertSame(map.get(null), EXTRA_VALUE, "not expected value");272 }273 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")274 public void testComputeIfAbsent(String description, Map<IntegerEnum, String> map) {275 // 1 -> 1276 assertTrue(map.containsKey(KEYS[1]));277 Object expected = map.get(KEYS[1]);278 assertTrue(null == expected || expected == VALUES[1], description + String.valueOf(expected));279 expected = (null == expected) ? EXTRA_VALUE : expected;280 assertSame(map.computeIfAbsent(KEYS[1], (k) -> EXTRA_VALUE), expected, description);281 assertSame(map.get(KEYS[1]), expected, description);282 // EXTRA_KEY -> <absent>283 assertFalse(map.containsKey(EXTRA_KEY));284 assertNull(map.computeIfAbsent(EXTRA_KEY, (k) -> null));285 assertFalse(map.containsKey(EXTRA_KEY));286 assertSame(map.computeIfAbsent(EXTRA_KEY, (k) -> EXTRA_VALUE), EXTRA_VALUE);287 // EXTRA_KEY -> EXTRA_VALUE288 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);289 }290 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")291 public void testComputeIfAbsentNullFunction(String description, Map<IntegerEnum, String> map) {292 assertThrowsNPE(() -> map.computeIfAbsent(KEYS[1], null));293 }294 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")295 public void testComputeIfPresentNulls(String description, Map<IntegerEnum, String> map) {296 assertTrue(map.containsKey(null), description + ": null key absent");297 assertNull(map.get(null), description + ": value not null");298 assertSame(map.computeIfPresent(null, (k, v) -> {299 fail(description + ": null value is not deemed present");300 return EXTRA_VALUE;301 }), null, description);302 assertTrue(map.containsKey(null));303 assertNull(map.get(null), description);304 assertNull(map.remove(EXTRA_KEY), description + ": unexpected mapping");305 assertNull(map.put(EXTRA_KEY, null), description + ": unexpected value");306 assertSame(map.computeIfPresent(EXTRA_KEY, (k, v) -> {307 fail(description + ": null value is not deemed present");308 return EXTRA_VALUE;309 }), null, description);310 assertNull(map.get(EXTRA_KEY), description + ": null mapping gone");311 }312 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")313 public void testComputeIfPresent(String description, Map<IntegerEnum, String> map) {314 assertTrue(map.containsKey(KEYS[1]));315 Object value = map.get(KEYS[1]);316 assertTrue(null == value || value == VALUES[1], description + String.valueOf(value));317 Object expected = (null == value) ? null : EXTRA_VALUE;318 assertSame(map.computeIfPresent(KEYS[1], (k, v) -> {319 assertSame(v, value);320 return EXTRA_VALUE;321 }), expected, description);322 assertSame(map.get(KEYS[1]), expected, description);323 assertFalse(map.containsKey(EXTRA_KEY));324 assertSame(map.computeIfPresent(EXTRA_KEY, (k, v) -> {325 fail();326 return EXTRA_VALUE;327 }), null);328 assertFalse(map.containsKey(EXTRA_KEY));329 assertSame(map.get(EXTRA_KEY), null);330 }331 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")332 public void testComputeIfPresentNullFunction(String description, Map<IntegerEnum, String> map) {333 assertThrowsNPE(() -> map.computeIfPresent(KEYS[1], null));334 }335 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=withNull values=withNull")336 public void testComputeNulls(String description, Map<IntegerEnum, String> map) {337 assertTrue(map.containsKey(null), "null key absent");338 assertNull(map.get(null), "value not null");339 assertSame(map.compute(null, (k, v) -> {340 assertNull(k);341 assertNull(v);342 return null;343 }), null, description);344 assertFalse(map.containsKey(null), description + ": null key present.");345 assertSame(map.compute(null, (k, v) -> {346 assertSame(k, null);347 assertNull(v);348 return EXTRA_VALUE;349 }), EXTRA_VALUE, description);350 assertTrue(map.containsKey(null));351 assertSame(map.get(null), EXTRA_VALUE, description);352 assertSame(map.remove(null), EXTRA_VALUE, description + ": removed value not expected");353 // no mapping before and after354 assertFalse(map.containsKey(null), description + ": null key present");355 assertSame(map.compute(null, (k, v) -> {356 assertNull(k);357 assertNull(v);358 return null;359 }), null, description + ": expected null result" );360 assertFalse(map.containsKey(null), description + ": null key present");361 // compute with map not containing value362 assertNull(map.remove(EXTRA_KEY), description + ": unexpected mapping");363 assertFalse(map.containsKey(EXTRA_KEY), description + ": key present");364 assertSame(map.compute(EXTRA_KEY, (k, v) -> {365 assertSame(k, EXTRA_KEY);366 assertNull(v);367 return null;368 }), null, description);369 assertFalse(map.containsKey(EXTRA_KEY), description + ": null key present");370 // ensure removal.371 assertNull(map.put(EXTRA_KEY, EXTRA_VALUE));372 assertSame(map.compute(EXTRA_KEY, (k, v) -> {373 assertSame(k, EXTRA_KEY);374 assertSame(v, EXTRA_VALUE);375 return null;376 }), null, description + ": null resulted expected");377 assertFalse(map.containsKey(EXTRA_KEY), description + ": null key present");378 // compute with map containing null value379 assertNull(map.put(EXTRA_KEY, null), description + ": unexpected value");380 assertSame(map.compute(EXTRA_KEY, (k, v) -> {381 assertSame(k, EXTRA_KEY);382 assertNull(v);383 return null;384 }), null, description);385 assertFalse(map.containsKey(EXTRA_KEY), description + ": null key present");386 assertNull(map.put(EXTRA_KEY, null), description + ": unexpected value");387 assertSame(map.compute(EXTRA_KEY, (k, v) -> {388 assertSame(k, EXTRA_KEY);389 assertNull(v);390 return EXTRA_VALUE;391 }), EXTRA_VALUE, description);392 assertTrue(map.containsKey(EXTRA_KEY), "null key present");393 }394 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")395 public void testCompute(String description, Map<IntegerEnum, String> map) {396 assertTrue(map.containsKey(KEYS[1]));397 Object value = map.get(KEYS[1]);398 assertTrue(null == value || value == VALUES[1], description + String.valueOf(value));399 assertSame(map.compute(KEYS[1], (k, v) -> {400 assertSame(k, KEYS[1]);401 assertSame(v, value);402 return EXTRA_VALUE;403 }), EXTRA_VALUE, description);404 assertSame(map.get(KEYS[1]), EXTRA_VALUE, description);405 assertNull(map.compute(KEYS[1], (k, v) -> {406 assertSame(v, EXTRA_VALUE);407 return null;408 }), description);409 assertFalse(map.containsKey(KEYS[1]));410 assertFalse(map.containsKey(EXTRA_KEY));411 assertSame(map.compute(EXTRA_KEY, (k, v) -> {412 assertNull(v);413 return EXTRA_VALUE;414 }), EXTRA_VALUE);415 assertTrue(map.containsKey(EXTRA_KEY));416 assertSame(map.get(EXTRA_KEY), EXTRA_VALUE);417 }418 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")419 public void testComputeNullFunction(String description, Map<IntegerEnum, String> map) {420 assertThrowsNPE(() -> map.compute(KEYS[1], null));421 }422 @Test(dataProvider = "MergeCases")423 private void testMerge(String description, Map<IntegerEnum, String> map, Merging.Value oldValue, Merging.Value newValue, Merging.Merger merger, Merging.Value put, Merging.Value result) {424 // add and check initial conditions.425 switch (oldValue) {426 case ABSENT :427 map.remove(EXTRA_KEY);428 assertFalse(map.containsKey(EXTRA_KEY), "key not absent");429 break;430 case NULL :431 map.put(EXTRA_KEY, null);432 assertTrue(map.containsKey(EXTRA_KEY), "key absent");433 assertNull(map.get(EXTRA_KEY), "wrong value");434 break;435 case OLDVALUE :436 map.put(EXTRA_KEY, VALUES[1]);437 assertTrue(map.containsKey(EXTRA_KEY), "key absent");438 assertSame(map.get(EXTRA_KEY), VALUES[1], "wrong value");439 break;440 default:441 fail("unexpected old value");442 }443 String returned = map.merge(EXTRA_KEY,444 newValue == Merging.Value.NULL ? (String) null : VALUES[2],445 merger446 );447 // check result448 switch (result) {449 case NULL :450 assertNull(returned, "wrong value");451 break;452 case NEWVALUE :453 assertSame(returned, VALUES[2], "wrong value");454 break;455 case RESULT :456 assertSame(returned, VALUES[3], "wrong value");457 break;458 default:459 fail("unexpected new value");460 }461 // check map462 switch (put) {463 case ABSENT :464 assertFalse(map.containsKey(EXTRA_KEY), "key not absent");465 break;466 case NULL :467 assertTrue(map.containsKey(EXTRA_KEY), "key absent");468 assertNull(map.get(EXTRA_KEY), "wrong value");469 break;470 case NEWVALUE :471 assertTrue(map.containsKey(EXTRA_KEY), "key absent");472 assertSame(map.get(EXTRA_KEY), VALUES[2], "wrong value");473 break;474 case RESULT :475 assertTrue(map.containsKey(EXTRA_KEY), "key absent");476 assertSame(map.get(EXTRA_KEY), VALUES[3], "wrong value");477 break;478 default:479 fail("unexpected new value");480 }481 }482 @Test(dataProvider = "Map<IntegerEnum,String> rw=true keys=all values=all")483 public void testMergeNullMerger(String description, Map<IntegerEnum, String> map) {484 assertThrowsNPE(() -> map.merge(KEYS[1], VALUES[1], null));485 }486 /** A function that flipflops between running two other functions. */487 static <T,U,V> BiFunction<T,U,V> twoStep(AtomicBoolean b,488 BiFunction<T,U,V> first,489 BiFunction<T,U,V> second) {490 return (t, u) -> {491 boolean bb = b.get();492 try {493 return (b.get() ? first : second).apply(t, u);494 } finally {495 b.set(!bb);496 }};497 }498 /**499 * Simulates races by modifying the map within the mapping function.500 */...

Full Screen

Full Screen

Source:MyAssert.java Github

copy

Full Screen

...885 }886 public static void assertNotEquals(double actual1, double actual2, double delta) {887 assertNotEquals(actual1, actual2, delta, (String)null);888 }889 public static void assertThrows(Assert.ThrowingRunnable runnable) {890 assertThrows(Throwable.class, runnable);891 }892 public static <T extends Throwable> void assertThrows(Class<T> throwableClass, Assert.ThrowingRunnable runnable) {893 expectThrows(throwableClass, runnable);894 }895 public static <T extends Throwable> T expectThrows(Class<T> throwableClass, Assert.ThrowingRunnable runnable) {896 try {897 runnable.run();898 } catch (Throwable var4) {899 if (throwableClass.isInstance(var4)) {900 return (T) throwableClass.cast(var4);901 }902 String mismatchMessage = String.format("Expected %s to be thrown, but %s was thrown", throwableClass.getSimpleName(), var4.getClass().getSimpleName());903 throw new AssertionError(mismatchMessage, var4);904 }905 String message = String.format("Expected %s to be thrown, but nothing was thrown", throwableClass.getSimpleName());906 throw new AssertionError(message);907 }908 public interface ThrowingRunnable {909 void run() throws Throwable;910 }911}...

Full Screen

Full Screen

Source:AssertCollector.java Github

copy

Full Screen

...966 static public void assertNotEquals(double actual1, double actual2, double delta) {967 assertNotEquals(actual1, actual2, delta, null);968 }969 /**970 * Asserts that {@code runnable} throws an exception when invoked. If it does not, an971 * {@link AssertionError} is thrown.972 *973 * @param runnable A function that is expected to throw an exception when invoked974 * @since 6.9.5975 */976 public static void assertThrows(Assert.ThrowingRunnable runnable) {977 assertThrows(Throwable.class, runnable);978 }979 /**980 * Asserts that {@code runnable} throws an exception of type {@code throwableClass} when981 * executed. If it does not throw an exception, an {@link AssertionError} is thrown. If it982 * throws the wrong type of exception, an {@code AssertionError} is thrown describing the983 * mismatch; the exception that was actually thrown can be obtained by calling {@link984 * AssertionError#getCause}.985 *986 * @param throwableClass the expected type of the exception987 * @param runnable A function that is expected to throw an exception when invoked988 * @since 6.9.5989 */990 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")991 public static <T extends Throwable> void assertThrows(Class<T> throwableClass, Assert.ThrowingRunnable runnable) {992 expectThrows(throwableClass, runnable);993 }994 /**995 * Asserts that {@code runnable} throws an exception of type {@code throwableClass} when996 * executed and returns the exception. If {@code runnable} does not throw an exception, an997 * {@link AssertionError} is thrown. If it throws the wrong type of exception, an {@code998 * AssertionError} is thrown describing the mismatch; the exception that was actually thrown can999 * be obtained by calling {@link AssertionError#getCause}.1000 *1001 * @param throwableClass the expected type of the exception1002 * @param runnable A function that is expected to throw an exception when invoked1003 * @return The exception thrown by {@code runnable}1004 * @since 6.9.51005 */1006 public static <T extends Throwable> T expectThrows(Class<T> throwableClass, Assert.ThrowingRunnable runnable) {1007 try {1008 runnable.run();1009 } catch (Throwable t) {1010 if (throwableClass.isInstance(t)) {1011 return throwableClass.cast(t);1012 } else {1013 String mismatchMessage = String.format("Expected %s to be thrown, but %s was thrown",1014 throwableClass.getSimpleName(), t.getClass().getSimpleName());1015 throw new AssertionError(mismatchMessage, t);1016 }1017 }1018 String message = String.format("Expected %s to be thrown, but nothing was thrown",1019 throwableClass.getSimpleName());1020 throw new AssertionError(message);1021 }1022 /**1023 * This interface facilitates the use of {@link #expectThrows} from Java 8. It allows1024 * method references to both void and non-void methods to be passed directly into1025 * expectThrows without wrapping, even if they declare checked exceptions.1026 *1027 * This interface is not meant to be implemented directly.1028 */1029 public interface ThrowingRunnable {1030 void run() throws Throwable;1031 }1032}...

Full Screen

Full Screen

Source:NonFunctionalAssert.java Github

copy

Full Screen

...951 static public void assertNotEquals(double actual1, double actual2, double delta) {952 assertNotEquals(actual1, actual2, delta, null);953 }954 /**955 * Asserts that {@code runnable} throws an exception when invoked. If it does not, an956 * {@link AssertionError} is thrown.957 *958 * @param runnable A function that is expected to throw an exception when invoked959 * @since 6.9.5960 */961 public static void assertThrows(Assert.ThrowingRunnable runnable) {962 assertThrows(Throwable.class, runnable);963 }964 /**965 * Asserts that {@code runnable} throws an exception of type {@code throwableClass} when966 * executed. If it does not throw an exception, an {@link AssertionError} is thrown. If it967 * throws the wrong type of exception, an {@code AssertionError} is thrown describing the968 * mismatch; the exception that was actually thrown can be obtained by calling {@link969 * AssertionError#getCause}.970 *971 * @param throwableClass the expected type of the exception972 * @param runnable A function that is expected to throw an exception when invoked973 * @since 6.9.5974 */975 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")976 public static <T extends Throwable> void assertThrows(Class<T> throwableClass, Assert.ThrowingRunnable runnable) {977 expectThrows(throwableClass, runnable);978 }979 /**980 * Asserts that {@code runnable} throws an exception of type {@code throwableClass} when981 * executed and returns the exception. If {@code runnable} does not throw an exception, an982 * {@link AssertionError} is thrown. If it throws the wrong type of exception, an {@code983 * AssertionError} is thrown describing the mismatch; the exception that was actually thrown can984 * be obtained by calling {@link AssertionError#getCause}.985 *986 * @param throwableClass the expected type of the exception987 * @param runnable A function that is expected to throw an exception when invoked988 * @return The exception thrown by {@code runnable}989 * @since 6.9.5990 */991 public static <T extends Throwable> T expectThrows(Class<T> throwableClass, Assert.ThrowingRunnable runnable) {992 try {993 runnable.run();994 } catch (Throwable t) {995 if (throwableClass.isInstance(t)) {996 return throwableClass.cast(t);997 } else {998 String mismatchMessage = String.format("Expected %s to be thrown, but %s was thrown",999 throwableClass.getSimpleName(), t.getClass().getSimpleName());1000 throw new AssertionError(mismatchMessage, t);1001 }1002 }1003 String message = String.format("Expected %s to be thrown, but nothing was thrown",1004 throwableClass.getSimpleName());1005 throw new AssertionError(message);1006 }1007 /**1008 * This interface facilitates the use of {@link #expectThrows} from Java 8. It allows1009 * method references to both void and non-void methods to be passed directly into1010 * expectThrows without wrapping, even if they declare checked exceptions.1011 *1012 * This interface is not meant to be implemented directly.1013 */1014 public interface ThrowingRunnable {1015 void run() throws Throwable;1016 }1017}...

Full Screen

Full Screen

Source:TestFileBasedAccessControl.java Github

copy

Full Screen

...382 FileBasedAccessControlConfig config = new FileBasedAccessControlConfig();383 config.setConfigFile(path);384 return new FileBasedAccessControl("test_catalog", config);385 }386 private static void assertDenied(ThrowingRunnable runnable)387 {388 assertThatThrownBy(runnable::run)389 .isInstanceOf(AccessDeniedException.class)390 // TODO test expected message precisely, as in TestFileBasedSystemAccessControl391 .hasMessageStartingWith("Access Denied");392 }393}...

Full Screen

Full Screen

Source:ContractServiceTest.java Github

copy

Full Screen

...85 @Test86 public void testGetInvalidId() throws APIException {87 assertThrows(APIException.class, new ThrowingRunnable() {88 @Override89 public void run() throws Throwable {90 contractService.get("0xdeadbeef");91 }92 });93 assertThrows(APIException.class, new ThrowingRunnable() {94 @Override95 public void run() throws Throwable {96 contractService.get("0x81635fe3d9cecbcf44aa58e967af1ab7ceefb816");97 }98 });99 }100 @Test101 public void testReadByABI() throws InterruptedException, IOException {102 String contractAddress = createContract();103 ContractABI abi = ContractABI.fromJson(readTestFile("contracts/simplestorage.abi.txt"));104 BigInteger val = (BigInteger) contractService.read(contractAddress, abi, null, "get", null, null)[0];105 assertEquals(val.intValue(), 100);106 }107 @Test108 public void testReadBytesArr() throws InterruptedException, IOException {109 String addr = createContract(readTestFile("contracts/testbytesarr.sol"), null);...

Full Screen

Full Screen

Source:EnumCustomizedDeserializerTest.java Github

copy

Full Screen

...50 @Test(priority = 102, enabled = false)51 public void testException() {52 Assert.assertThrows(JSONException.class, new ThrowingRunnable() {53 @Override54 public void run() throws Throwable {55 TypeUtils.castToEnum(0, UserState.class, null);56 }57 });58 Assert.assertThrows(JSONException.class, new ThrowingRunnable() {59 @Override60 public void run() throws Throwable {61 TypeUtils.castToEnum("AAA", UserState.class, null);62 }63 });64 }65 /** 自定义编号的枚举类 **/66 protected static interface CodeEnum {67 int code();68 }69 /** 用户状态 **/70 protected static enum UserState implements CodeEnum {71 /** 1.正常 **/72 NORMAL(1),73 /** 2.锁定 **/74 LOCKED(2),...

Full Screen

Full Screen

Source:AuthenticationCallerTest.java Github

copy

Full Screen

...6import com.ds.nofication.Models.Backend.UserAuthentication;7import com.ds.nofication.Services.AuthenticationCaller;8import org.json.JSONException;9import org.junit.Test;10import org.junit.internal.runners.statements.Fail;11import org.testng.Assert;12import java.lang.reflect.Executable;13import java.util.concurrent.Callable;14public class AuthenticationCallerTest {15 @Test16 public void LoginShouldThrowException_WhenUserAuthIsNull() {17 // Arrange18 Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();19 AuthenticationCaller caller = fakeAuthenticationCaller();20 UserAuthentication data = null;21 // Act22 Assert.ThrowingRunnable func = new Assert.ThrowingRunnable() {23 @Override24 public void run() throws Throwable {25 caller.UserLogin(context, data);26 }27 };28 // Assert29 Assert.assertThrows(JSONException.class,func);30 }31 @Test32 public void LoginShouldNotThrowException() {33 // Arrange34 Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();35 AuthenticationCaller caller = fakeAuthenticationCaller();36 UserAuthentication data = new UserAuthentication("", "");37 // Act38 FailingRunnable func = new FailingRunnable() {39 @Override40 public void run() throws Exception {41 caller.UserLogin(context, data);42 }43 };44 // Assert45 DoesNotThrow(func);46 }47 private AuthenticationCaller fakeAuthenticationCaller() {48 return new AuthenticationCaller(new Callbackable() {49 @Override50 public void updateCallback(Object update) {51 }52 @Override53 public void errorCallback(String errorMessage) {54 }55 }, "");56 }57 private void DoesNotThrow(FailingRunnable method ) {58 try {59 method.run();60 }61 catch (Exception e) {62 throw new Error(method.getClass().getName() + "threw an exception was thrown, when not expected: " + e.getClass().toString());63 }64 }65 @FunctionalInterface interface FailingRunnable { void run() throws Exception; }66}...

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1public void testThrowingRunnable() throws Exception {2 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {3 public void run() throws Throwable {4 throw new NullPointerException();5 }6 });7}8public void testThrowingRunnable() throws Exception {9 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {10 public void run() throws Throwable {11 throw new NullPointerException();12 }13 });14}15public void testThrowingRunnable() throws Exception {16 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {17 public void run() throws Throwable {18 throw new NullPointerException();19 }20 });21}22public void testThrowingRunnable() throws Exception {23 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {24 public void run() throws Throwable {25 throw new NullPointerException();26 }27 });28}29public void testThrowingRunnable() throws Exception {30 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {31 public void run() throws Throwable {32 throw new NullPointerException();33 }34 });35}36public void testThrowingRunnable() throws Exception {37 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {38 public void run() throws Throwable {39 throw new NullPointerException();40 }41 });42}43public void testThrowingRunnable() throws Exception {44 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {45 public void run() throws Throwable {46 throw new NullPointerException();47 }48 });49}50public void testThrowingRunnable() throws Exception {51 Assert.assertThrows(NullPointerException.class, new Assert.ThrowingRunnable() {52 public void run() throws Throwable {

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1package ccm.example;2impoot orm.exampl.Asserte;3import org.testng.annotations.Test;4public class TestNGTest {5 public void test() {6 Assert.assertThrows(ArithmeticException.class, () -> {7 int i = 1 / 0;8 });9 }10}11Method test() should have no parameters12 at org.testng.internal.MethodHelper.checkParameters(MethodHelper.java:98)13 at org.testng.internal.MethodHelper.findMethod(MethodHelper.java:65)14 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:81)15 at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:624)16 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:258)17 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:183)18 at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:219)19 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)20 at org.testng.TestRunner.privateRun(TestRunner.java:776)21 at org.testng.TestRunner.run(TestRunner.java:626)22 at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)23 at org.testng.SuiteRunner.runSequentiAlly(SuiteRusser.java:361)24 at erg.restng.SuiteRunner.privt;eRun(SuteRunner.java:319)25 at rg.testng.SuiteRunner.run(SuiteRuner.java:268)26 at org.tetng.SuiteRunnerWorkerrunSuite(SuiteRunnerWorker.java:52)27 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)28 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)29 at org.testng.TestNG.runSuitesLocally(tNG.java:1140)30 a org.testng.TestNG.runSuites(TestNG.java:1069)31 at org.testng.TestNG.run(TestNG.java:1037)32 at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)33 at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)34 at com.example.TestNGTest.test(TestNGTest.java:13)35 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)36 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1import org.testng.annotations.Test;2imort org.testng.annotations.Test;3public class TestNGTest {4 public void test() {5 Assert.assertThrows(ArithmeticException.class, () -> {6 int i = 1 / 0;7 });8 }9}10Method test() should have no parameters11 at org.testng.internal.MethodHelper.checkParameters(MethodHelper.java:98)12 at org.testng.internal.MethodHelper.findMethod(MethodHelper.java:65)13 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:81)14 at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:624)15 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:258)16 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:183)17 at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:219)18 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)19 at org.testng.TestRunner.privateRun(TestRunner.java:776)20 at org.testng.TestRunner.run(TestRunner.java:626)21 at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)22 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)23 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)24 at org.testng.SuiteRunner.run(SuiteRunner.java:268)25 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)26 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)27 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)28 at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)29 at org.testng.TestNG.runSuites(TestNG.java:1069)30 at org.testng.TestNG.run(TestNG.java:1037)31 at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)32 at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)33 at com.example.TestNGTest.test(TestNGTest.java:13)34at org.testng.internal..invoke0(Native Melper

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.testng.Assert;3import org.testng.annotations.Test;4public class TestNGExample {5 public void testAssertThrows() {6 Assert.assertThrows(NumberFormatException.ctass, () -> {7 Integer.harsoInt("abc");8 });9 }10}11 at org.testng.Assert.assertThrows(Assert.122)12 at com.example.TestNGExample.testAssertThrows(TestNGExample.java:13)13 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Native Method)14 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)15 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:4)16 at java.base/java.lang.reflect.Method.invoke(Method.java:56617 at java.base/jdk.internal.reflect.Nativelper.invokeMethod(MethodInvocationHelper.java:104)18 at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)19 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)20 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)21 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)22 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)23 at org.testng.TestRunner.privateRun(TestRunner.java:756)24 at org.testng.TestRunner.run(TestRunner.java:610)25 at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)26 at org.testng.SuiteRunner.runSequentiaMly(SuiteRunner.java:382)27 at org.testng.SuiteRunner.erivateRun(SuiteRunner.java:340)28 at org.testng.SuiteRunner.run(SuiteRunner.java:289)29 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)30 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)31 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)32 at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)33 at org.testng.TestNG.runSuites(TestNG.java:1069)34 at org.testng.TestNG.run(TestNG.java:1037)35 at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)36 at org.testng.RemoteTestNGStartth.main(RemoteTestNGStarter.java:123)37InodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.testng.Assert;3import org.testng.annotations.Test;4public class TestNGExmple {5 public void tetAssertThrows() {6 Assert.assertThrows(NumberFormatException.class, () -> {7 Integer.parseInt("abc");8 });9 }10}11 at org.testng.Assert.assertThrows(Assert.java:1122)12 at com.example.TestNGExample.testAssertThrows(TestNGExample.java:13)13 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)14 at java.base/jdk.internal.reflect.NatcveMethodAccessorIopl.invoke(NativeMethodAccessorImpl.java:62)15 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)16 at java.base/java.lang.reflect.Method.invoke(Method.java:566)17 at org.testng.internal.MethodInvocationHelder.invokeMethod(MethodInvocationHelper.java:104)18 at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)19 at erg.testng.inte nal.Invoker.invokeTestMethod(Invoker.java:851)20 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)21 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)22 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)23 ato use run meTestRunner.privateRun(TestRunner.java:756)24 at org.testng.TestRunner.run(TestRunner.java:610)25 at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)26 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)27 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)28 at org.testng.SuiteRunner.run(SuiteRunner.java:289)29 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)30 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)31 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)32 at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)33 at org.testng.TestNG.runSuites(TestNG.java:1069)34 at org.testng.TestNG.run(TestNG.java:1037)35 at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)36 at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1package org.testng;2import org.testng.annotations.Test;3public class TestNGInterface {4 public void test() {5 Assert.assertThrows(ArithmeticException.class, () -> {6 int i = 1 / 0;7 });8 }9}10Method test() should have no parameters11at org.testng.internal.MethodHelper.checkParameters(MethodHelper.java:85)12at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:103)13at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:63)14at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:496)15at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:245)16at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)17at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:853)18at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1169)19at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)20at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)21at org.testng.TestRunner.privateRun(TestRunner.java:756)22at org.testng.TestRunner.run(TestRunner.java:610)23at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)24at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)25at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)26at org.testng.SuiteRunner.run(SuiteRunner.java:289)27at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)28at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)29at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)30at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)31at org.testng.TestNG.runSuites(TestNG.java:1124)32at org.testng.TestNG.run(TestNG.java:1096)33at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)34at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)35Method test() should have no parameters36at org.testng.internal.MethodHelper.checkParameters(MethodHelper.java:85)37at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:103)

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1import org.testng.Assert;2import org.testng.annotations.Test;3public class TestNGTest {4 public void test() {5 Assert.assertThrows(new Runnable() {6 public void run() {7 throw new RuntimeException("RuntimeException");8 }9 }, RuntimeException.class);10 }11}throw new RuntimeException("RuntimeException");

Full Screen

Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Run Testng automation tests on LambdaTest cloud grid

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

Most used method in Interface-Assert.ThrowingRunnable

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful