How to use AtLeastDiscrepancy method of org.mockito.internal.verification.checkers.AtLeastDiscrepancy class

Best Mockito code snippet using org.mockito.internal.verification.checkers.AtLeastDiscrepancy.AtLeastDiscrepancy

Source:AtLeast.java Github

copy

Full Screen

2 * Copyright (c) 2018 Mockito contributors3 * This program is made available under the terms of the MIT License.4 */5package org.mockito.internal.verification.within;6import org.mockito.internal.verification.checkers.AtLeastDiscrepancy;7import org.mockito.invocation.Invocation;8import org.mockito.invocation.Location;9import org.mockito.invocation.MatchableInvocation;10import static java.util.Collections.singletonList;11import static org.mockito.internal.exceptions.Reporter.tooLittleActualInvocations;12import static org.mockito.internal.verification.within.VerificationResult.FINISHED_SUCCESSFULL;13import static org.mockito.internal.verification.within.VerificationResult.GIVE_ME_THE_NEXT_INVOCATION;14public class AtLeast implements VerificationStrategy {15 private final int minInvocations;16 private int actualInvocations;17 private Invocation lastMatchingInvocation;18 public AtLeast(int minInvocations) {19 this.minInvocations = minInvocations;20 }21 @Override22 public VerificationResult verifyNotMatchingInvocation(Invocation notMatchingInvocation, MatchableInvocation wanted) {23 return GIVE_ME_THE_NEXT_INVOCATION;24 }25 @Override26 public VerificationResult verifyMatchingInvocation(Invocation matchingInvocation, MatchableInvocation wanted) {27 actualInvocations++;28 if (actualInvocations >= minInvocations) {29 return FINISHED_SUCCESSFULL;30 }31 lastMatchingInvocation = matchingInvocation;32 return GIVE_ME_THE_NEXT_INVOCATION;33 }34 @Override35 public void verifyAfterTimeElapsed(MatchableInvocation wanted) {36 if (actualInvocations >= minInvocations) {37 return;38 }39 AtLeastDiscrepancy discrepancy = new AtLeastDiscrepancy(minInvocations, actualInvocations);40 Location location;41 if (actualInvocations == 0) {42 location = null;43 } else {44 location = lastMatchingInvocation.getLocation();45 }46 throw tooLittleActualInvocations(discrepancy, wanted, singletonList(location));47 }48}...

Full Screen

Full Screen

Source:AtLeastDiscrepancy.java Github

copy

Full Screen

...3 * This program is made available under the terms of the MIT License.4 */5package org.mockito.internal.verification.checkers;6import org.mockito.internal.reporting.Discrepancy;7public class AtLeastDiscrepancy extends Discrepancy {8 public AtLeastDiscrepancy(int wantedCount, int actualCount) {9 super(wantedCount, actualCount);10 }11 @Override12 public String getPluralizedWantedCount() {13 return "*at least* " + super.getPluralizedWantedCount();14 }15}...

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import org.mockito.internal.invocation.InvocationMatcher;3import org.mockito.internal.invocation.InvocationsFinder;4import org.mockito.internal.verification.api.VerificationData;5import org.mockito.verification.VerificationMode;6import java.util.List;7public class AtLeastDiscrepancy implements VerificationMode {8 private final int wantedNumberOfInvocations;9 public AtLeastDiscrepancy(int wantedNumberOfInvocations) {10 this.wantedNumberOfInvocations = wantedNumberOfInvocations;11 }12 public void verify(VerificationData data) {13 InvocationMatcher wanted = data.getWanted();14 List<InvocationMatcher> invocations = new InvocationsFinder().findInvocations(data.getAllInvocations(), wanted);15 int actual = invocations.size();16 if (actual < wantedNumberOfInvocations) {17 throw new AssertionError("Wanted at least " + wantedNumberOfInvocations + " times but was " + actual);18 }19 }20}21package org.mockito.internal.verification.checkers;22import org.mockito.internal.invocation.InvocationMatcher;23import org.mockito.internal.invocation.InvocationsFinder;24import org.mockito.internal.verification.api.VerificationData;25import org.mockito.verification.VerificationMode;26import java.util.List;27public class AtLeastDiscrepancy implements VerificationMode {28 private final int wantedNumberOfInvocations;29 public AtLeastDiscrepancy(int wantedNumberOfInvocations) {30 this.wantedNumberOfInvocations = wantedNumberOfInvocations;31 }32 public void verify(VerificationData data) {33 InvocationMatcher wanted = data.getWanted();34 List<InvocationMatcher> invocations = new InvocationsFinder().findInvocations(data.getAllInvocations(), wanted);35 int actual = invocations.size();36 if (actual < wantedNumberOfInvocations) {37 throw new AssertionError("Wanted at least " + wantedNumberOfInvocations + " times but was " + actual);38 }39 }40}41package org.mockito.internal.verification.checkers;42import org.mockito.internal.invocation.InvocationMatcher;43import org.mockito.internal.invocation.InvocationsFinder;44import org.mockito.internal.verification.api

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import org.mockito.internal.invocation.InvocationMatcher;3import org.mockito.internal.invocation.InvocationsFinder;4import org.mockito.internal.verification.api.VerificationData;5import org.mockito.internal.verification.checkers.AtLeastDiscrepancy;6import org.mockito.exceptions.verification.TooLittleActualInvocations;7public class AtLeastDiscrepancy implements Discrepancy {8 private final int wantedCount;9 private final int actualCount;10 public AtLeastDiscrepancy(int wantedCount, int actualCount) {11 this.wantedCount = wantedCount;12 this.actualCount = actualCount;13 }14 public void validateWantedCountIsLessThanActualCount() {15 if (wantedCount > actualCount) {16 throw new TooLittleActualInvocations(wantedCount, actualCount);17 }18 }19 public static Discrepancy create(VerificationData data, InvocationsFinder finder) {20 InvocationMatcher wanted = data.getWanted();21 int wantedCount = wanted.getCount();22 int actualCount = finder.findInvocations(data.getAllInvocations(), wanted).size();23 return new AtLeastDiscrepancy(wantedCount, actualCount);24 }25}26package org.mockito.internal.verification.checkers;27import org.mockito.internal.invocation.InvocationMatcher;28import org.mockito.internal.invocation.InvocationsFinder;29import org.mockito.internal.verification.api.VerificationData;30public interface Discrepancy {31 void validateWantedCountIsLessThanActualCount();32 static Discrepancy create(VerificationData data, InvocationsFinder finder) {33 InvocationMatcher wanted = data.getWanted();34 int wantedCount = wanted.getCount();35 int actualCount = finder.findInvocations(data.getAllInvocations(), wanted).size();36 return new AtLeastDiscrepancy(wantedCount, actualCount);37 }38}39package org.mockito.internal.verification.checkers;40import org.mockito.internal.invocation.InvocationMatcher;41import org.mockito.internal.invocation.InvocationsFinder;42import org.mockito.internal.verification.api.VerificationData;43public interface Discrepancy {

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import org.mockito.exceptions.Reporter;3import org.mockito.internal.invocation.InvocationMatcher;4import org.mockito.internal.invocation.InvocationsFinder;5import org.mockito.internal.invocation.InvocationsFinderImpl;6import org.mockito.internal.progress.VerificationModeImpl;7import org.mockito.internal.verification.api.VerificationData;8import org.mockito.internal.verification.api.VerificationInOrderMode;9import org.mockito.internal.verification.api.VerificationMode;10import org.mockito.verification.VerificationModeFactory;11import java.util.List;12public class AtLeastDiscrepancy implements Discrepancy {13 private final Reporter reporter;14 private final InvocationsFinder finder;15 public AtLeastDiscrepancy() {16 this(new Reporter(), new InvocationsFinderImpl());17 }18 AtLeastDiscrepancy(Reporter reporter, InvocationsFinder finder) {19 this.reporter = reporter;20 this.finder = finder;21 }22 public void validateDiscrepancy(VerificationData data) {23 VerificationMode mode = data.getWanted().getVerificationMode();24 List<InvocationMatcher> invocations = data.getAllInvocations();25 List<InvocationMatcher> actualInvocations = finder.findInvocations(invocations, data.getWanted());26 if (mode instanceof VerificationInOrderMode) {27 verifyInOrder(data, actualInvocations);28 } else if (mode instanceof VerificationModeImpl) {29 verifyInAnyOrder(data, actualInvocations);30 } else {31 throw new RuntimeException("Unknown verification mode: " + mode);32 }33 }34 private void verifyInOrder(VerificationData data, List<InvocationMatcher> actualInvocations) {35 VerificationInOrderMode mode = (VerificationInOrderMode) data.getWanted().getVerificationMode();36 int wantedCount = mode.getCount();37 int actualCount = actualInvocations.size();38 if (wantedCount > actualCount) {39 reporter.tooLittleActualInvocationsInOrder(wantedCount, actualCount, actualInvocations, data.getWanted());40 }41 }42 private void verifyInAnyOrder(VerificationData data, List<InvocationMatcher> actualInvocations) {43 VerificationModeImpl mode = (VerificationModeImpl) data.getWanted().getVerificationMode();44 int wantedCount = mode.getCount();45 int actualCount = actualInvocations.size();46 if (wantedCount > actualCount) {

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import org.mockito.exceptions.Reporter;3import org.mockito.internal.invocation.Invocation;4import org.mockito.internal.invocation.InvocationsFinder;5import org.mockito.internal.reporting.Discrepancy;6import org.mockito.internal.reporting.DiscrepancyFinder;7import org.mockito.internal.reporting.WantedCount;8import org.mockito.internal.verification.api.VerificationData;9import org.mockito.verification.VerificationMode;10public class AtLeastDiscrepancy implements VerificationMode {11 private final int wantedCount;12 public AtLeastDiscrepancy(int wantedCount) {13 this.wantedCount = wantedCount;14 }15 public void verify(VerificationData data) {16 InvocationsFinder finder = new InvocationsFinder();17 Discrepancy discrepancy = new DiscrepancyFinder().findDiscrepancy(finder.findInvocations(data.getAllInvocations(), data.getWanted()), new WantedCount(wantedCount));18 if (discrepancy != null) {19 new Reporter().atLeastWantedButNotInvoked(discrepancy);20 }21 }22 public int wantedCount() {23 return wantedCount;24 }25 public int actualCount(Invocation invocation) {26 throw new UnsupportedOperationException();27 }28 public boolean isVerified(Invocation invocation, Discrepancy discrepancy) {29 throw new UnsupportedOperationException();30 }31}32package org.mockito.internal.verification.checkers;33import org.mockito.exceptions.Reporter;34import org.mockito.internal.invocation.Invocation;35import org.mockito.internal.invocation.InvocationsFinder;36import org.mockito.internal.reporting.Discrepancy;37import org.mockito.internal.reporting.DiscrepancyFinder;38import org.mockito.internal.reporting.WantedCount;39import org.mockito.internal.verification.api.VerificationData;40import org.mockito.verification.VerificationMode;41public class AtLeastDiscrepancy implements VerificationMode {42 private final int wantedCount;43 public AtLeastDiscrepancy(int wantedCount) {44 this.wantedCount = wantedCount;45 }46 public void verify(VerificationData data) {47 InvocationsFinder finder = new InvocationsFinder();48 Discrepancy discrepancy = new DiscrepancyFinder().findDiscrepancy(finder.findInvocations(data.getAllInvocations(), data.getWanted()), new WantedCount(w

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import java.util.List;3import org.mockito.exceptions.base.MockitoAssertionError;4import org.mockito.internal.invocation.InvocationMatcher;5import org.mockito.internal.invocation.InvocationsFinder;6import org.mockito.internal.invocation.InvocationsFinderImpl;7import org.mockito.internal.progress.VerificationModeImpl;8import org.mockito.internal.verification.api.VerificationData;9import org.mockito.internal.verification.api.VerificationInOrderMode;10import org.mockito.internal.verification.checkers.Discrepancy;11import org.mockito.internal.verification.checkers.MissingInvocationChecker;12import org.mockito.internal.verification.checkers.TooLittleActualInvocationsChecker;13import org.mockito.internal.verification.checkers.TooManyActualInvocationsChecker;14import org.mockito.internal.verification.checkers.TooManyActualInvocationsInOrderChecker;15import org.mockito.internal.verification.checkers.TooLittleActualInvocationsInOrderChecker;16import org.mockito.internal.verification.checkers.TooLittleActualInvocationsInOrderChecker;17import org.mockito.internal.verification.checkers.TooManyActualInvocationsInOrderChecker;18import org.mockito.internal.verification.checkers.Discrepancy;19import org.mockito.internal.verification.checkers.MissingInvocationChecker;20import org.mockito.internal.verification.checkers.TooLittleActualInvocationsChecker;21import org.mockito.internal.verification.checkers.TooManyActualInvocationsChecker;22import org.mockito.internal.verification.checkers.TooManyActualInvocationsInOrderChecker;23import org.mockito.internal.verification.checkers.TooLittleActualInvocationsInOrderChecker;24import org.mockito.internal.verification.checkers.TooLittleActualInvocationsInOrderChecker;25import org.mockito.internal.verification.checkers.TooManyActualInvocationsInOrderChecker;26import org.mockito.internal.verification.checkers.Discrepancy;27import org.mockito.internal.verification.checkers.MissingInvocationChecker;28import org.mockito.internal.verification.checkers.TooLittleActualInvocationsChecker;29import org.mockito.internal.verification.checkers.TooManyActualInvocationsChecker;30import org.mockito.internal.verification.checkers.TooManyActualInvocationsInOrderChecker;31import org.mockito.internal.verification.checkers.TooLittleActualInvocationsInOrderChecker;32import org.mockito.internal.verification.checkers.TooLittleActualInvocationsInOrderChecker;33import org.mockito.internal.verification.checkers.TooManyActualInvocationsInOrderChecker;34public class AtLeastDiscrepancy implements Discrepancy {

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import java.util.List;3import org.mockito.exceptions.base.MockitoAssertionError;4import org.mockito.exceptions.verification.TooLittleActualInvocations;5import org.mockito.internal.invocation.Invocation;6import org.mockito.internal.invocation.InvocationMatcher;7import org.mockito.internal.invocation.InvocationsFinder;8import org.mockito.internal.invocation.InvocationsMarker;9import org.mockito.internal.reporting.Discrepancy;10import org.mockito.internal.reporting.DiscrepancyFinder;11import org.mockito.internal.reporting.DiscrepancyFinder.DiscrepancyType;12import org.mockito.internal.verification.api.VerificationData;13import org.mockito.verification.VerificationMode;14public class AtLeastDiscrepancy implements VerificationMode {15 private final int wantedCount;16 public AtLeastDiscrepancy(int wantedNumberOfInvocations) {17 if (wantedNumberOfInvocations < 0) {18 throw new IllegalArgumentException("Negative value is not allowed here");19 }20 this.wantedCount = wantedNumberOfInvocations;21 }22 public void verify(VerificationData data) {23 List<Invocation> invocations = data.getAllInvocations();24 InvocationMatcher wanted = data.getWanted();25 InvocationsFinder finder = new InvocationsFinder();26 List<Invocation> actualInvocations = finder.findInvocations(invocations, wanted);27 Discrepancy discrepancy = new DiscrepancyFinder().getDiscrepancy(actualInvocations, wantedCount, DiscrepancyType.AT_LEAST);28 if (discrepancy != null) {29 throw new TooLittleActualInvocations(discrepancy.getMessage(), wanted, actualInvocations);30 }31 new InvocationsMarker().markVerified(actualInvocations, wanted);32 }33 public int wantedCount() {34 return wantedCount;35 }36 public MockitoAssertionError lastError() {37 return null;38 }39}40package org.mockito.internal.verification.checkers;41import java.util.ArrayList;42import java.util.List;43import org.mockito.internal.invocation.Invocation;44import org.mockito.internal.invocation.InvocationMatcher;45import org.mockito.internal.reporting.Discrepancy;46import org.mockito.internal.reporting.DiscrepancyFinder;47import org.mockito.internal.reporting.DiscrepancyFinder.DiscrepancyType;48import org.mockito.internal.verification.api

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.verification.checkers.AtLeastDiscrepancy;2import org.mockito.internal.invocation.InvocationMatcher;3import org.mockito.internal.verification.api.InOrderContext;4import org.mockito.internal.invocation.InvocationsFinder;5import org.mockito.internal.verification.api.VerificationData;6import org.mockito.exceptions.verification.TooLittleActualInvocations;7import org.mockito.exceptions.verification.TooManyActualInvocations;8import org.mockito.internal.invocation.InvocationBuilder;9import org.mockito.internal.invocation.InvocationMatcher;10import org.mockito.internal.invocation.Invocation;11import java.util.List;12import java.util.LinkedList;13import org.mockito.internal.invocation.InvocationsFinder;14import org.mockito.internal.verification.api.VerificationData;15import org.mockito.exceptions.verification.TooLittleActualInvocations;16import org.mockito.exceptions.verification.TooManyActualInvocations;17import org.mockito.internal.invocation.InvocationBuilder;18import org.mockito.internal.invocation.InvocationMatcher;19import org.mockito.internal.invocation.Invocation;20import java.util.List;21import java.util.LinkedList;22import org.mockito.internal.invocation.InvocationsFinder;23import org.mockito.internal.verification.api.VerificationData;24import org.mockito.exceptions.verification.TooLittleActualInvocations;25import org.mockito.exceptions.verification.TooManyActualInvocations;26import org.mockito.internal.invocation.InvocationBuilder;27import org.mockito.internal.invocation.InvocationMatcher;28import org.mockito.internal.invocation.Invocation;29import java.util.List;30import java.util.LinkedList;31import org.mockito.internal.invocation.InvocationsFinder;32import org.mockito.internal.verification.api.VerificationData;33import org.mockito.exceptions.verification.TooLittleActualInvocations;34import org.mockito.exceptions.verification.TooManyActualInvocations;35import org.mockito.internal.invocation.InvocationBuilder;36import org.mockito.internal.invocation.InvocationMatcher;37import org.mockito.internal.invocation.Invocation;38import java.util.List;39import java.util.LinkedList;40import org.mockito.internal.invocation.InvocationsFinder;41import org.mockito.internal.verification.api.VerificationData;42import org.mockito.exceptions.verification.TooLittleActualInvocations;43import org.mockito.exceptions.verification.TooManyActualInvocations;44import org.mockito.internal.invocation.InvocationBuilder;45import org.mockito.internal.invocation.InvocationMatcher;46import org.mockito.internal.invocation.Invocation;47import java.util.List;48import java.util.LinkedList;49import org.mockito.internal.invocation.InvocationsFinder;50import org.mockito.internal.verification.api.VerificationData;51import org.mockito.exceptions.verification.TooLittleActualInv

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import org.mockito.internal.invocation.InvocationMatcher;3import org.mockito.internal.invocation.InvocationsFinder;4import org.mockito.internal.invocation.InvocationsMarker;5import org.mockito.internal.progress.VerificationModeImpl;6import org.mockito.internal.verification.api.VerificationData;7import org.mockito.verification.VerificationMode;8import java.util.List;9public class AtLeastDiscrepancy extends Discrepancy {10 private final int wantedCount;11 private final VerificationModeImpl mode;12 public AtLeastDiscrepancy(int wantedCount, VerificationModeImpl mode) {13 this.wantedCount = wantedCount;14 this.mode = mode;15 }16 public void validate(List<InvocationMatcher> wanted, VerificationData data) {17 InvocationsFinder finder = new InvocationsFinder();18 List<InvocationMatcher> actual = finder.findInvocations(wanted, data.getAllInvocations());19 InvocationsMarker.markVerifiedInOrder(actual, wanted, mode);20 int actualCount = actual.size();21 if (actualCount < wantedCount) {22 throw new AssertionError(23 formatWantedCount(wantedCount, wanted, actualCount, actual, data.getInvocations()));24 }25 }26 public VerificationMode description() {27 return VerificationModeFactory.atLeast(wantedCount);28 }29}30package org.mockito.internal.verification.checkers;31import org.mockito.internal.invocation.InvocationMatcher;32import org.mockito.internal.invocation.InvocationsFinder;33import org.mockito.internal.invocation.InvocationsMarker;34import org.mockito.internal.progress.VerificationModeImpl;35import org.mockito.internal.verification.api.VerificationData;36import org.mockito.verification.VerificationMode;37import java.util.List;38public class AtLeastDiscrepancy extends Discrepancy {39 private final int wantedCount;40 private final VerificationModeImpl mode;41 public AtLeastDiscrepancy(int wantedCount, VerificationModeImpl mode) {42 this.wantedCount = wantedCount;43 this.mode = mode;44 }45 public void validate(List<InvocationMatcher> wanted, VerificationData data) {46 InvocationsFinder finder = new InvocationsFinder();47 List<InvocationMatcher> actual = finder.findInvocations(wanted, data.getAllInvocations());48 InvocationsMarker.markVerifiedInOrder(actual, wanted, mode);49 int actualCount = actual.size();50 if (actual

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.verification.checkers.AtLeastDiscrepancy;2import org.mockito.invocation.Invocation;3import org.mockito.invocation.InvocationMatcher;4import org.mockito.invocation.MatchableInvocation;5import org.mockito.invocation.InvocationBuilder;6import org.mockito.invocation.MockHandler;7import org.mockito.invocation.MockHandlerFactory;8import org.mockito.invocation.InvocationContainer;9import org.mockito.stubbing.Answer;10import org.mockito.stubbing.Stubber;11import org.mockito.stubbing.VoidMethodStubbable;12import org.mockito.stubbing.VoidMethodStubbableImpl;13import org.mockito.stubbing.OngoingStubbing;14import org.mockito.stubbing.Stubbing;15import org.mockito.exceptions.misusing.*;16import org.mockito.exceptions.misusing.cannotverify.*;17import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyMock;18import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyMethod;19import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithAtLeastX;20import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithAtMostX;21import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithExactNumberOfInvocations;22import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithMoreThanX;23import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithNever;24import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithNoMoreInteractions;25import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithNumberOfInvocations;26import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithVerificationAfterTimeout;27import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithVerificationInOrder;28import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithVerificationInOrderMode;29import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithVerificationMode;30import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithX;31import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithXAndY;32import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithXOrY;33import org.mockito.exceptions.misusing.cannotverify.CannotVerifyStubOnlyWithXXAndYY;34import

Full Screen

Full Screen

AtLeastDiscrepancy

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.verification.checkers;2import java.util.List;3import org.mockito.exceptions.base.MockitoException;4import org.mockito.internal.invocation.Invocation;5import org.mockito.internal.invocation.InvocationsFinder;6import org.mockito.internal.invocation.InvocationsFinderImpl;7import org.mockito.internal.invocation.InvocationsFinderStubber;8import org.mockito.internal.invocation.InvocationsFinderStubberImpl;9import org.mockito.internal.verification.api.VerificationData;10import org.mockito.internal.verification.checkers.AtLeastDiscrepancy;11import org.mockito.verification.VerificationMode;12public class AtLeastDiscrepancy implements VerificationMode {13 private final int wantedCount;14 public AtLeastDiscrepancy(int wantedCount) {15 if (wantedCount < 0) {16 throw new MockitoException("Negative value is not allowed here");17 }18 this.wantedCount = wantedCount;19 }20 public void verify(VerificationData data) {21 List<Invocation> invocations = data.getAllInvocations();22 Invocation wanted = data.getTarget();23 InvocationsFinder finder = new InvocationsFinderImpl();24 InvocationsFinderStubber stubber = new InvocationsFinderStubberImpl();25 int actualCount = finder.findInvocations(invocations, wanted).size();26 int actualCountForStubbing = stubber.findStubbedInvocations(invocations, wanted).size();27 int discrepancy = actualCount - (actualCountForStubbing - wantedCount);28 if (discrepancy < 0) {29 throw data.getWanted().discrepancy(new Discrepancy(wantedCount, actualCount, actualCountForStubbing));30 }31 }32 public int wantedCount() {33 return wantedCount;34 }35 public VerificationMode description(String description) {36 return this;37 }38 public String toString() {39 return "atLeast(" + wantedCount + ")";40 }41}42package org.mockito.internal.verification.checkers;43import java.util.List;44import org.mockito.exceptions.base.MockitoException;45import org.mockito.internal.invocation.Invocation;46import org.mockito.internal.invocation.InvocationsFinder;47import org.mockito.internal.invocation.InvocationsFinderImpl;48import org

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

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

Most used method in AtLeastDiscrepancy

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful