Best Mockito code snippet using org.mockito.exceptions.verification.NeverWantedButInvoked.MoreThanAllowedActualInvocations
Source:Reporter.java
...12import org.mockito.exceptions.base.MockitoAssertionError;13import org.mockito.exceptions.base.MockitoException;14import org.mockito.exceptions.base.MockitoInitializationException;15import org.mockito.exceptions.misusing.*;16import org.mockito.exceptions.verification.MoreThanAllowedActualInvocations;17import org.mockito.exceptions.verification.NeverWantedButInvoked;18import org.mockito.exceptions.verification.NoInteractionsWanted;19import org.mockito.exceptions.verification.SmartNullPointerException;20import org.mockito.exceptions.verification.TooFewActualInvocations;21import org.mockito.exceptions.verification.TooManyActualInvocations;22import org.mockito.exceptions.verification.VerificationInOrderFailure;23import org.mockito.exceptions.verification.WantedButNotInvoked;24import org.mockito.internal.debugging.LocationImpl;25import org.mockito.internal.exceptions.util.ScenarioPrinter;26import org.mockito.internal.junit.ExceptionFactory;27import org.mockito.internal.matchers.LocalizedMatcher;28import org.mockito.internal.util.MockUtil;29import org.mockito.invocation.DescribedInvocation;30import org.mockito.invocation.Invocation;31import org.mockito.invocation.InvocationOnMock;32import org.mockito.invocation.Location;33import org.mockito.listeners.InvocationListener;34import org.mockito.mock.SerializableMode;35/**36 * Reports verification and misusing errors.37 * <p>38 * One of the key points of mocking library is proper verification/exception39 * messages. All messages in one place makes it easier to tune and amend them.40 * <p>41 * Reporter can be injected and therefore is easily testable.42 * <p>43 * Generally, exception messages are full of line breaks to make them easy to44 * read (xunit plugins take only fraction of screen on modern IDEs).45 */46public class Reporter {47 private static final String NON_PUBLIC_PARENT =48 "Mocking methods declared on non-public parent classes is not supported.";49 private Reporter() {}50 public static MockitoException checkedExceptionInvalid(Throwable t) {51 return new MockitoException(52 join("Checked exception is invalid for this method!", "Invalid: " + t));53 }54 public static MockitoException cannotStubWithNullThrowable() {55 return new MockitoException(join("Cannot stub with null throwable!"));56 }57 public static MockitoException unfinishedStubbing(Location location) {58 return new UnfinishedStubbingException(59 join(60 "Unfinished stubbing detected here:",61 location,62 "",63 "E.g. thenReturn() may be missing.",64 "Examples of correct stubbing:",65 " when(mock.isOk()).thenReturn(true);",66 " when(mock.isOk()).thenThrow(exception);",67 " doThrow(exception).when(mock).someVoidMethod();",68 "Hints:",69 " 1. missing thenReturn()",70 " 2. you are trying to stub a final method, which is not supported",71 " 3. you are stubbing the behaviour of another mock inside before 'thenReturn' instruction is completed",72 ""));73 }74 public static MockitoException incorrectUseOfApi() {75 return new MockitoException(76 join(77 "Incorrect use of API detected here:",78 new LocationImpl(),79 "",80 "You probably stored a reference to OngoingStubbing returned by when() and called stubbing methods like thenReturn() on this reference more than once.",81 "Examples of correct usage:",82 " when(mock.isOk()).thenReturn(true).thenReturn(false).thenThrow(exception);",83 " when(mock.isOk()).thenReturn(true, false).thenThrow(exception);",84 ""));85 }86 public static MockitoException missingMethodInvocation() {87 return new MissingMethodInvocationException(88 join(89 "when() requires an argument which has to be 'a method call on a mock'.",90 "For example:",91 " when(mock.getArticles()).thenReturn(articles);",92 "",93 "Also, this error might show up because:",94 "1. you stub either of: final/private/equals()/hashCode() methods.",95 " Those methods *cannot* be stubbed/verified.",96 " " + NON_PUBLIC_PARENT,97 "2. inside when() you don't call method on mock but on some other object.",98 ""));99 }100 public static MockitoException unfinishedVerificationException(Location location) {101 return new UnfinishedVerificationException(102 join(103 "Missing method call for verify(mock) here:",104 location,105 "",106 "Example of correct verification:",107 " verify(mock).doSomething()",108 "",109 "Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.",110 "Those methods *cannot* be stubbed/verified.",111 NON_PUBLIC_PARENT,112 ""));113 }114 public static MockitoException notAMockPassedToVerify(Class<?> type) {115 return new NotAMockException(116 join(117 "Argument passed to verify() is of type "118 + type.getSimpleName()119 + " and is not a mock!",120 "Make sure you place the parenthesis correctly!",121 "See the examples of correct verifications:",122 " verify(mock).someMethod();",123 " verify(mock, times(10)).someMethod();",124 " verify(mock, atLeastOnce()).someMethod();"));125 }126 public static MockitoException nullPassedToVerify() {127 return new NullInsteadOfMockException(128 join(129 "Argument passed to verify() should be a mock but is null!",130 "Examples of correct verifications:",131 " verify(mock).someMethod();",132 " verify(mock, times(10)).someMethod();",133 " verify(mock, atLeastOnce()).someMethod();",134 " not: verify(mock.someMethod());",135 "Also, if you use @Mock annotation don't miss openMocks()"));136 }137 public static MockitoException notAMockPassedToWhenMethod() {138 return new NotAMockException(139 join(140 "Argument passed to when() is not a mock!",141 "Example of correct stubbing:",142 " doThrow(new RuntimeException()).when(mock).someMethod();"));143 }144 public static MockitoException nullPassedToWhenMethod() {145 return new NullInsteadOfMockException(146 join(147 "Argument passed to when() is null!",148 "Example of correct stubbing:",149 " doThrow(new RuntimeException()).when(mock).someMethod();",150 "Also, if you use @Mock annotation don't miss openMocks()"));151 }152 public static MockitoException mocksHaveToBePassedToVerifyNoMoreInteractions() {153 return new MockitoException(154 join(155 "Method requires argument(s)!",156 "Pass mocks that should be verified, e.g:",157 " verifyNoMoreInteractions(mockOne, mockTwo);",158 " verifyNoInteractions(mockOne, mockTwo);",159 ""));160 }161 public static MockitoException notAMockPassedToVerifyNoMoreInteractions() {162 return new NotAMockException(163 join(164 "Argument(s) passed is not a mock!",165 "Examples of correct verifications:",166 " verifyNoMoreInteractions(mockOne, mockTwo);",167 " verifyNoInteractions(mockOne, mockTwo);",168 ""));169 }170 public static MockitoException nullPassedToVerifyNoMoreInteractions() {171 return new NullInsteadOfMockException(172 join(173 "Argument(s) passed is null!",174 "Examples of correct verifications:",175 " verifyNoMoreInteractions(mockOne, mockTwo);",176 " verifyNoInteractions(mockOne, mockTwo);"));177 }178 public static MockitoException notAMockPassedWhenCreatingInOrder() {179 return new NotAMockException(180 join(181 "Argument(s) passed is not a mock!",182 "Pass mocks that require verification in order.",183 "For example:",184 " InOrder inOrder = inOrder(mockOne, mockTwo);"));185 }186 public static MockitoException nullPassedWhenCreatingInOrder() {187 return new NullInsteadOfMockException(188 join(189 "Argument(s) passed is null!",190 "Pass mocks that require verification in order.",191 "For example:",192 " InOrder inOrder = inOrder(mockOne, mockTwo);"));193 }194 public static MockitoException mocksHaveToBePassedWhenCreatingInOrder() {195 return new MockitoException(196 join(197 "Method requires argument(s)!",198 "Pass mocks that require verification in order.",199 "For example:",200 " InOrder inOrder = inOrder(mockOne, mockTwo);"));201 }202 public static MockitoException inOrderRequiresFamiliarMock() {203 return new MockitoException(204 join(205 "InOrder can only verify mocks that were passed in during creation of InOrder.",206 "For example:",207 " InOrder inOrder = inOrder(mockOne);",208 " inOrder.verify(mockOne).doStuff();"));209 }210 public static MockitoException invalidUseOfMatchers(211 int expectedMatchersCount, List<LocalizedMatcher> recordedMatchers) {212 return new InvalidUseOfMatchersException(213 join(214 "Invalid use of argument matchers!",215 expectedMatchersCount216 + " matchers expected, "217 + recordedMatchers.size()218 + " recorded:"219 + locationsOf(recordedMatchers),220 "",221 "This exception may occur if matchers are combined with raw values:",222 " //incorrect:",223 " someMethod(any(), \"raw String\");",224 "When using matchers, all arguments have to be provided by matchers.",225 "For example:",226 " //correct:",227 " someMethod(any(), eq(\"String by matcher\"));",228 "",229 "For more info see javadoc for Matchers class.",230 ""));231 }232 public static MockitoException incorrectUseOfAdditionalMatchers(233 String additionalMatcherName,234 int expectedSubMatchersCount,235 Collection<LocalizedMatcher> matcherStack) {236 return new InvalidUseOfMatchersException(237 join(238 "Invalid use of argument matchers inside additional matcher "239 + additionalMatcherName240 + " !",241 new LocationImpl(),242 "",243 expectedSubMatchersCount244 + " sub matchers expected, "245 + matcherStack.size()246 + " recorded:",247 locationsOf(matcherStack),248 "",249 "This exception may occur if matchers are combined with raw values:",250 " //incorrect:",251 " someMethod(AdditionalMatchers.and(isNotNull(), \"raw String\");",252 "When using matchers, all arguments have to be provided by matchers.",253 "For example:",254 " //correct:",255 " someMethod(AdditionalMatchers.and(isNotNull(), eq(\"raw String\"));",256 "",257 "For more info see javadoc for Matchers and AdditionalMatchers classes.",258 ""));259 }260 public static MockitoException stubPassedToVerify(Object mock) {261 return new CannotVerifyStubOnlyMock(262 join(263 "Argument \""264 + MockUtil.getMockName(mock)265 + "\" passed to verify is a stubOnly() mock which cannot be verified.",266 "If you intend to verify invocations on this mock, don't use stubOnly() in its MockSettings."));267 }268 public static MockitoException reportNoSubMatchersFound(String additionalMatcherName) {269 return new InvalidUseOfMatchersException(270 join(271 "No matchers found for additional matcher " + additionalMatcherName,272 new LocationImpl(),273 ""));274 }275 private static Object locationsOf(Collection<LocalizedMatcher> matchers) {276 List<String> description = new ArrayList<>();277 for (LocalizedMatcher matcher : matchers) {278 description.add(matcher.getLocation().toString());279 }280 return join(description.toArray());281 }282 public static AssertionError argumentsAreDifferent(283 String wanted, List<String> actualCalls, List<Location> actualLocations) {284 if (actualCalls == null285 || actualLocations == null286 || actualCalls.size() != actualLocations.size()) {287 throw new IllegalArgumentException("actualCalls and actualLocations list must match");288 }289 StringBuilder actualBuilder = new StringBuilder();290 StringBuilder messageBuilder = new StringBuilder();291 messageBuilder292 .append("\n")293 .append("Argument(s) are different! Wanted:\n")294 .append(wanted)295 .append("\n")296 .append(new LocationImpl())297 .append("\n")298 .append("Actual invocations have different arguments:\n");299 for (int i = 0; i < actualCalls.size(); i++) {300 actualBuilder.append(actualCalls.get(i)).append("\n");301 messageBuilder302 .append(actualCalls.get(i))303 .append("\n")304 .append(actualLocations.get(i))305 .append("\n");306 }307 return ExceptionFactory.createArgumentsAreDifferentException(308 messageBuilder.toString(), wanted, actualBuilder.toString());309 }310 public static MockitoAssertionError wantedButNotInvoked(DescribedInvocation wanted) {311 return new WantedButNotInvoked(createWantedButNotInvokedMessage(wanted));312 }313 public static MockitoAssertionError wantedButNotInvoked(314 DescribedInvocation wanted, List<? extends DescribedInvocation> invocations) {315 String allInvocations;316 if (invocations.isEmpty()) {317 allInvocations = "Actually, there were zero interactions with this mock.\n";318 } else {319 StringBuilder sb =320 new StringBuilder("\nHowever, there ")321 .append(were_exactly_x_interactions(invocations.size()))322 .append(" with this mock:\n");323 for (DescribedInvocation i : invocations) {324 sb.append(i).append("\n").append(i.getLocation()).append("\n\n");325 }326 allInvocations = sb.toString();327 }328 String message = createWantedButNotInvokedMessage(wanted);329 return new WantedButNotInvoked(message + allInvocations);330 }331 private static String createWantedButNotInvokedMessage(DescribedInvocation wanted) {332 return join("Wanted but not invoked:", wanted.toString(), new LocationImpl(), "");333 }334 public static MockitoAssertionError wantedButNotInvokedInOrder(335 DescribedInvocation wanted, DescribedInvocation previous) {336 return new VerificationInOrderFailure(337 join(338 "Verification in order failure",339 "Wanted but not invoked:",340 wanted.toString(),341 new LocationImpl(),342 "Wanted anywhere AFTER following interaction:",343 previous.toString(),344 previous.getLocation(),345 ""));346 }347 public static MockitoAssertionError tooManyActualInvocations(348 int wantedCount,349 int actualCount,350 DescribedInvocation wanted,351 List<Location> locations) {352 String message =353 createTooManyInvocationsMessage(wantedCount, actualCount, wanted, locations);354 return new TooManyActualInvocations(message);355 }356 private static String createTooManyInvocationsMessage(357 int wantedCount,358 int actualCount,359 DescribedInvocation wanted,360 List<Location> invocations) {361 return join(362 wanted.toString(),363 "Wanted " + pluralize(wantedCount) + ":",364 new LocationImpl(),365 "But was " + pluralize(actualCount) + ":",366 createAllLocationsMessage(invocations),367 "");368 }369 public static MockitoAssertionError neverWantedButInvoked(370 DescribedInvocation wanted, List<Invocation> invocations) {371 return new NeverWantedButInvoked(372 join(373 wanted.toString(),374 "Never wanted here:",375 new LocationImpl(),376 "But invoked here:",377 createAllLocationsArgsMessage(invocations)));378 }379 public static MockitoAssertionError tooManyActualInvocationsInOrder(380 int wantedCount,381 int actualCount,382 DescribedInvocation wanted,383 List<Location> invocations) {384 String message =385 createTooManyInvocationsMessage(wantedCount, actualCount, wanted, invocations);386 return new VerificationInOrderFailure(join("Verification in order failure:" + message));387 }388 private static String createAllLocationsMessage(List<Location> locations) {389 if (locations == null) {390 return "\n";391 }392 StringBuilder sb = new StringBuilder();393 for (Location location : locations) {394 sb.append(location).append("\n");395 }396 return sb.toString();397 }398 private static String createAllLocationsArgsMessage(List<Invocation> invocations) {399 StringBuilder sb = new StringBuilder();400 for (Invocation invocation : invocations) {401 Location location = invocation.getLocation();402 if (location == null) {403 continue;404 }405 sb.append(location)406 .append(" with arguments: ")407 .append(Arrays.toString(invocation.getArguments()))408 .append("\n");409 }410 return sb.toString();411 }412 private static String createTooFewInvocationsMessage(413 org.mockito.internal.reporting.Discrepancy discrepancy,414 DescribedInvocation wanted,415 List<Location> locations) {416 return join(417 wanted.toString(),418 "Wanted "419 + discrepancy.getPluralizedWantedCount()420 + (discrepancy.getWantedCount() == 0 ? "." : ":"),421 new LocationImpl(),422 "But was "423 + discrepancy.getPluralizedActualCount()424 + (discrepancy.getActualCount() == 0 ? "." : ":"),425 createAllLocationsMessage(locations));426 }427 public static MockitoAssertionError tooFewActualInvocations(428 org.mockito.internal.reporting.Discrepancy discrepancy,429 DescribedInvocation wanted,430 List<Location> allLocations) {431 String message = createTooFewInvocationsMessage(discrepancy, wanted, allLocations);432 return new TooFewActualInvocations(message);433 }434 public static MockitoAssertionError tooFewActualInvocationsInOrder(435 org.mockito.internal.reporting.Discrepancy discrepancy,436 DescribedInvocation wanted,437 List<Location> locations) {438 String message = createTooFewInvocationsMessage(discrepancy, wanted, locations);439 return new VerificationInOrderFailure(join("Verification in order failure:" + message));440 }441 public static MockitoAssertionError noMoreInteractionsWanted(442 Invocation undesired, List<VerificationAwareInvocation> invocations) {443 ScenarioPrinter scenarioPrinter = new ScenarioPrinter();444 String scenario = scenarioPrinter.print(invocations);445 return new NoInteractionsWanted(446 join(447 "No interactions wanted here:",448 new LocationImpl(),449 "But found this interaction on mock '"450 + MockUtil.getMockName(undesired.getMock())451 + "':",452 undesired.getLocation(),453 scenario));454 }455 public static MockitoAssertionError noMoreInteractionsWantedInOrder(Invocation undesired) {456 return new VerificationInOrderFailure(457 join(458 "No interactions wanted here:",459 new LocationImpl(),460 "But found this interaction on mock '"461 + MockUtil.getMockName(undesired.getMock())462 + "':",463 undesired.getLocation()));464 }465 public static MockitoAssertionError noInteractionsWanted(466 Object mock, List<VerificationAwareInvocation> invocations) {467 ScenarioPrinter scenarioPrinter = new ScenarioPrinter();468 String scenario = scenarioPrinter.print(invocations);469 List<Location> locations = new ArrayList<>();470 for (VerificationAwareInvocation invocation : invocations) {471 locations.add(invocation.getLocation());472 }473 return new NoInteractionsWanted(474 join(475 "No interactions wanted here:",476 new LocationImpl(),477 "But found these interactions on mock '"478 + MockUtil.getMockName(mock)479 + "':",480 join("", locations),481 scenario));482 }483 public static MockitoException cannotMockClass(Class<?> clazz, String reason) {484 return new MockitoException(485 join(486 "Cannot mock/spy " + clazz,487 "Mockito cannot mock/spy because :",488 " - " + reason));489 }490 public static MockitoException cannotStubVoidMethodWithAReturnValue(String methodName) {491 return new CannotStubVoidMethodWithReturnValue(492 join(493 "'"494 + methodName495 + "' is a *void method* and it *cannot* be stubbed with a *return value*!",496 "Voids are usually stubbed with Throwables:",497 " doThrow(exception).when(mock).someVoidMethod();",498 "If you need to set the void method to do nothing you can use:",499 " doNothing().when(mock).someVoidMethod();",500 "For more information, check out the javadocs for Mockito.doNothing().",501 "***",502 "If you're unsure why you're getting above error read on.",503 "Due to the nature of the syntax above problem might occur because:",504 "1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version.",505 "2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods.",506 "3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - ",507 " - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.",508 "4. " + NON_PUBLIC_PARENT,509 ""));510 }511 public static MockitoException onlyVoidMethodsCanBeSetToDoNothing() {512 return new MockitoException(513 join(514 "Only void methods can doNothing()!",515 "Example of correct use of doNothing():",516 " doNothing().",517 " doThrow(new RuntimeException())",518 " .when(mock).someVoidMethod();",519 "Above means:",520 "someVoidMethod() does nothing the 1st time but throws an exception the 2nd time is called"));521 }522 public static MockitoException wrongTypeOfReturnValue(523 String expectedType, String actualType, String methodName) {524 return new WrongTypeOfReturnValue(525 join(526 actualType + " cannot be returned by " + methodName + "()",527 methodName + "() should return " + expectedType,528 "***",529 "If you're unsure why you're getting above error read on.",530 "Due to the nature of the syntax above problem might occur because:",531 "1. This exception *might* occur in wrongly written multi-threaded tests.",532 " Please refer to Mockito FAQ on limitations of concurrency testing.",533 "2. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies - ",534 " - with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.",535 ""));536 }537 public static MockitoException wrongTypeReturnedByDefaultAnswer(538 Object mock, String expectedType, String actualType, String methodName) {539 return new WrongTypeOfReturnValue(540 join(541 "Default answer returned a result with the wrong type:",542 actualType + " cannot be returned by " + methodName + "()",543 methodName + "() should return " + expectedType,544 "",545 "The default answer of "546 + MockUtil.getMockName(mock)547 + " that was configured on the mock is probably incorrectly implemented.",548 ""));549 }550 public static MoreThanAllowedActualInvocations wantedAtMostX(551 int maxNumberOfInvocations, int foundSize) {552 return new MoreThanAllowedActualInvocations(553 join(554 "Wanted at most "555 + pluralize(maxNumberOfInvocations)556 + " but was "557 + foundSize));558 }559 public static MockitoException misplacedArgumentMatcher(List<LocalizedMatcher> lastMatchers) {560 return new InvalidUseOfMatchersException(561 join(562 "Misplaced or misused argument matcher detected here:",563 locationsOf(lastMatchers),564 "",565 "You cannot use argument matchers outside of verification or stubbing.",566 "Examples of correct usage of argument matchers:",...
MoreThanAllowedActualInvocations
Using AI Code Generation
1import org.mockito.exceptions.verification.NeverWantedButInvoked;2import org.mockito.exceptions.verification.NoInteractionsWanted;3import org.mockito.exceptions.verification.NoMoreInteractionsWanted;4import org.mockito.exceptions.verification.TooLittleActualInvocations;5import org.mockito.exceptions.verification.VerificationInOrderFailure;6import org.mockito.exceptions.verification.WantedButNotInvoked;7public class MockitoExceptionsVerification {8 public static void main(String[] args) {9 List<String> mockedList = mock(List.class);10 mockedList.add("one");11 mockedList.add("two");12 mockedList.add("two");13 mockedList.add("three");14 mockedList.add("three");15 mockedList.add("three");16 mockedList.add("four");17 mockedList.add("four");18 mockedList.add("four");19 mockedList.add("four");20 verify(mockedList, times(2)).add("one");21 verify(mockedList, times(3)).add("two");22 verify(mockedList, times(4)).add("three");23 verify(mockedList, times(5)).add("four");24 verify(mockedList, times(1)).add("five");25 verify(mockedList, never()).add("six");26 verify(mockedList, atLeast(1)).add("seven");27 verify(mockedList, atLeast(2)).add("eight");28 verify(mockedList, atLeast(3)).add("nine");29 verify(mockedList, atLeast(4)).add("ten");30 verify(mockedList, atLeast(5)).add("eleven");31 verify(mockedList, atLeast(6)).add("twelve");32 verify(mock
MoreThanAllowedActualInvocations
Using AI Code Generation
1public class NeverWantedButInvoked extends MockitoAssertionError {2 private static final long serialVersionUID = 1L;3 private final Invocation wanted;4 private final Invocation actual;5 private final int actualInvocationsCount;6 private final int wantedCount;7 public NeverWantedButInvoked(Invocation wanted, Invocation actual, int actualInvocationsCount, int wantedCount) {8 this.wanted = wanted;9 this.actual = actual;10 this.actualInvocationsCount = actualInvocationsCount;11 this.wantedCount = wantedCount;12 }13 public String getMessage() {14 return String.format("Never wanted here:15%d time(s)", wanted.getLocation(), actual.getLocation(), actualInvocationsCount);16 }17 public int getActualInvocationsCount() {18 return actualInvocationsCount;19 }20 public int getWantedCount() {21 return wantedCount;22 }23}24public interface OngoingStubbing<T> extends OngoingStubbing<T> {25 * See {@link OngoingStubbing#thenThrow(Throwable...)}26 OngoingStubbing<T> thenThrow(Throwable... toBeThrown);27 * See {@link OngoingStubbing#thenAnswer(Answer)}28 OngoingStubbing<T> thenAnswer(Answer<?> answer);29 * See {@link OngoingStubbing#then(Answer)}30 OngoingStubbing<T> then(Answer<?> answer);31 * See {@link OngoingStubbing#thenCallRealMethod()}32 OngoingStubbing<T> thenCallRealMethod();33 * See {@link OngoingStubbing#thenCallRealMethod(Object)}34 OngoingStubbing<T> thenCallRealMethod(Object toCall);35 * See {@link OngoingStubbing#thenReturn(Object)}36 OngoingStubbing<T> thenReturn(T toBeReturned);37 * See {@link OngoingStubbing#thenThrow(Class)}38 OngoingStubbing<T> thenThrow(Class<? extends Throwable> toBeThrown);39 * See {@link OngoingStubbing#thenThrow(Class, Class)}
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!!