How to use AdditionalMatchers class of org.mockito package

Best Mockito code snippet using org.mockito.AdditionalMatchers

Source:AdditionalMatchers.java Github

copy

Full Screen

...16import org.mockito.internal.progress.ThreadSafeMockingProgress;17/**18 * See {@link Matchers} for general info about matchers.19 * <p>20 * AdditionalMatchers provides rarely used matchers, kept only for somewhat compatibility with EasyMock. 21 * Use additional matchers very judiciously because they may impact readability of a test.22 * It is recommended to use matchers from {@link Matchers} and keep stubbing and verification simple.23 * <p>24 * Example of using logical and(), not(), or() matchers: 25 * 26 * <pre>27 * //anything but not "ejb"28 * mock.someMethod(not(eq("ejb")));29 * 30 * //not "ejb" and not "michael jackson"31 * mock.someMethod(and(not(eq("ejb")), not(eq("michael jackson"))));32 * 33 * //1 or 1034 * mock.someMethod(or(eq(1), eq(10)));35 * </pre>36 * 37 * Scroll down to see all methods - full list of matchers.38 */39public class AdditionalMatchers {40 41 private static MockingProgress mockingProgress = new ThreadSafeMockingProgress();42 /**43 * argument greater than or equal the given value.44 * <p>45 * See examples in javadoc for {@link AdditionalMatchers} class46 * 47 * @param value48 * the given value.49 * @return <code>null</code>.50 */51 public static <T extends Comparable<T>> T geq(Comparable<T> value) {52 return reportMatcher(new GreaterOrEqual<T>(value)).<T>returnNull();53 }54 /**55 * byte argument greater than or equal to the given value.56 * <p>57 * See examples in javadoc for {@link AdditionalMatchers} class58 * 59 * @param value60 * the given value.61 * @return <code>0</code>.62 */63 public static byte geq(byte value) {64 return reportMatcher(new GreaterOrEqual<Byte>(value)).returnZero();65 }66 /**67 * double argument greater than or equal to the given value.68 * <p>69 * See examples in javadoc for {@link AdditionalMatchers} class70 * 71 * @param value72 * the given value.73 * @return <code>0</code>.74 */75 public static double geq(double value) {76 return reportMatcher(new GreaterOrEqual<Double>(value)).returnZero();77 }78 /**79 * float argument greater than or equal to the given value.80 * <p>81 * See examples in javadoc for {@link AdditionalMatchers} class82 * 83 * @param value84 * the given value.85 * @return <code>0</code>.86 */87 public static float geq(float value) {88 return reportMatcher(new GreaterOrEqual<Float>(value)).returnZero();89 }90 /**91 * int argument greater than or equal to the given value.92 * <p>93 * See examples in javadoc for {@link AdditionalMatchers} class94 * 95 * @param value96 * the given value.97 * @return <code>0</code>.98 */99 public static int geq(int value) {100 return reportMatcher(new GreaterOrEqual<Integer>(value)).returnZero();101 }102 /**103 * long argument greater than or equal to the given value.104 * <p>105 * See examples in javadoc for {@link AdditionalMatchers} class106 * 107 * @param value108 * the given value.109 * @return <code>0</code>.110 */111 public static long geq(long value) {112 return reportMatcher(new GreaterOrEqual<Long>(value)).returnZero();113 }114 /**115 * short argument greater than or equal to the given value.116 * <p>117 * See examples in javadoc for {@link AdditionalMatchers} class118 * 119 * @param value120 * the given value.121 * @return <code>0</code>.122 */123 public static short geq(short value) {124 return reportMatcher(new GreaterOrEqual<Short>(value)).returnZero();125 }126 /**127 * comparable argument less than or equal the given value details.128 * <p>129 * See examples in javadoc for {@link AdditionalMatchers} class130 * 131 * @param value132 * the given value.133 * @return <code>null</code>.134 */135 public static <T extends Comparable<T>> T leq(Comparable<T> value) {136 return reportMatcher(new LessOrEqual<T>(value)).<T>returnNull();137 }138 /**139 * byte argument less than or equal to the given value.140 * <p>141 * See examples in javadoc for {@link AdditionalMatchers} class142 * 143 * @param value144 * the given value.145 * @return <code>0</code>.146 */147 public static byte leq(byte value) {148 return reportMatcher(new LessOrEqual<Byte>(value)).returnZero();149 }150 /**151 * double argument less than or equal to the given value.152 * <p>153 * See examples in javadoc for {@link AdditionalMatchers} class154 * 155 * @param value156 * the given value.157 * @return <code>0</code>.158 */159 public static double leq(double value) {160 return reportMatcher(new LessOrEqual<Double>(value)).returnZero();161 }162 /**163 * float argument less than or equal to the given value.164 * <p>165 * See examples in javadoc for {@link AdditionalMatchers} class166 * 167 * @param value168 * the given value.169 * @return <code>0</code>.170 */171 public static float leq(float value) {172 return reportMatcher(new LessOrEqual<Float>(value)).returnZero();173 }174 /**175 * int argument less than or equal to the given value.176 * <p>177 * See examples in javadoc for {@link AdditionalMatchers} class178 * 179 * @param value180 * the given value.181 * @return <code>0</code>.182 */183 public static int leq(int value) {184 return reportMatcher(new LessOrEqual<Integer>(value)).returnZero();185 }186 /**187 * long argument less than or equal to the given value.188 * <p>189 * See examples in javadoc for {@link AdditionalMatchers} class190 * 191 * @param value192 * the given value.193 * @return <code>0</code>.194 */195 public static long leq(long value) {196 return reportMatcher(new LessOrEqual<Long>(value)).returnZero();197 }198 /**199 * short argument less than or equal to the given value.200 * <p>201 * See examples in javadoc for {@link AdditionalMatchers} class 202 * 203 * @param value204 * the given value.205 * @return <code>0</code>.206 */207 public static short leq(short value) {208 return reportMatcher(new LessOrEqual<Short>(value)).returnZero();209 }210 /**211 * comparable argument greater than the given value.212 * <p>213 * See examples in javadoc for {@link AdditionalMatchers} class214 * 215 * @param value216 * the given value.217 * @return <code>null</code>.218 */219 public static <T extends Comparable<T>> T gt(Comparable<T> value) {220 return reportMatcher(new GreaterThan<T>(value)).<T>returnNull();221 }222 /**223 * byte argument greater than the given value.224 * <p>225 * See examples in javadoc for {@link AdditionalMatchers} class226 * 227 * @param value228 * the given value.229 * @return <code>0</code>.230 */231 public static byte gt(byte value) {232 return reportMatcher(new GreaterThan<Byte>(value)).returnZero();233 }234 /**235 * double argument greater than the given value.236 * <p>237 * See examples in javadoc for {@link AdditionalMatchers} class238 * 239 * @param value240 * the given value.241 * @return <code>0</code>.242 */243 public static double gt(double value) {244 return reportMatcher(new GreaterThan<Double>(value)).returnZero();245 }246 /**247 * float argument greater than the given value.248 * <p>249 * See examples in javadoc for {@link AdditionalMatchers} class250 * 251 * @param value252 * the given value.253 * @return <code>0</code>.254 */255 public static float gt(float value) {256 return reportMatcher(new GreaterThan<Float>(value)).returnZero();257 }258 /**259 * int argument greater than the given value.260 * <p>261 * See examples in javadoc for {@link AdditionalMatchers} class262 * 263 * @param value264 * the given value.265 * @return <code>0</code>.266 */267 public static int gt(int value) {268 return reportMatcher(new GreaterThan<Integer>(value)).returnZero();269 }270 /**271 * long argument greater than the given value.272 * <p>273 * See examples in javadoc for {@link AdditionalMatchers} class274 * 275 * @param value276 * the given value.277 * @return <code>0</code>.278 */279 public static long gt(long value) {280 return reportMatcher(new GreaterThan<Long>(value)).returnZero();281 }282 /**283 * short argument greater than the given value.284 * <p>285 * See examples in javadoc for {@link AdditionalMatchers} class286 * 287 * @param value288 * the given value.289 * @return <code>0</code>.290 */291 public static short gt(short value) {292 return reportMatcher(new GreaterThan<Short>(value)).returnZero();293 }294 /**295 * comparable argument less than the given value.296 * <p>297 * See examples in javadoc for {@link AdditionalMatchers} class298 * 299 * @param value300 * the given value.301 * @return <code>null</code>.302 */303 public static <T extends Comparable<T>> T lt(Comparable<T> value) {304 return reportMatcher(new LessThan<T>(value)).<T>returnNull();305 }306 /**307 * byte argument less than the given value.308 * <p>309 * See examples in javadoc for {@link AdditionalMatchers} class310 * 311 * @param value312 * the given value.313 * @return <code>0</code>.314 */315 public static byte lt(byte value) {316 return reportMatcher(new LessThan<Byte>(value)).returnZero();317 }318 /**319 * double argument less than the given value.320 * <p>321 * See examples in javadoc for {@link AdditionalMatchers} class322 * 323 * @param value324 * the given value.325 * @return <code>0</code>.326 */327 public static double lt(double value) {328 return reportMatcher(new LessThan<Double>(value)).returnZero();329 }330 /**331 * float argument less than the given value.332 * <p>333 * See examples in javadoc for {@link AdditionalMatchers} class334 * 335 * @param value336 * the given value.337 * @return <code>0</code>.338 */339 public static float lt(float value) {340 return reportMatcher(new LessThan<Float>(value)).returnZero();341 }342 /**343 * int argument less than the given value.344 * <p>345 * See examples in javadoc for {@link AdditionalMatchers} class346 * 347 * @param value348 * the given value.349 * @return <code>0</code>.350 */351 public static int lt(int value) {352 return reportMatcher(new LessThan<Integer>(value)).returnZero();353 }354 /**355 * long argument less than the given value.356 * <p>357 * See examples in javadoc for {@link AdditionalMatchers} class358 * 359 * @param value360 * the given value.361 * @return <code>0</code>.362 */363 public static long lt(long value) {364 return reportMatcher(new LessThan<Long>(value)).returnZero();365 }366 /**367 * short argument less than the given value.368 * <p>369 * See examples in javadoc for {@link AdditionalMatchers} class370 * 371 * @param value372 * the given value.373 * @return <code>0</code>.374 */375 public static short lt(short value) {376 return reportMatcher(new LessThan<Short>(value)).returnZero();377 }378 /**379 * comparable argument equals to the given value according to their380 * compareTo method.381 * <p>382 * See examples in javadoc for {@link AdditionalMatchers} class383 * 384 * @param value385 * the given value.386 * @return <code>null</code>.387 */388 public static <T extends Comparable<T>> T cmpEq(Comparable<T> value) {389 return reportMatcher(new CompareEqual<T>(value)).<T>returnNull();390 }391 /**392 * String argument that contains a substring that matches the given regular393 * expression.394 * 395 * @param regex396 * the regular expression.397 * @return <code>null</code>.398 */399 public static String find(String regex) {400 return reportMatcher(new Find(regex)).<String>returnNull();401 }402 /**403 * Object array argument that is equal to the given array, i.e. it has to404 * have the same type, length, and each element has to be equal.405 * <p>406 * See examples in javadoc for {@link AdditionalMatchers} class407 * 408 * @param <T>409 * the type of the array, it is passed through to prevent casts.410 * @param value411 * the given array.412 * @return <code>null</code>.413 */414 public static <T> T[] aryEq(T[] value) {415 return reportMatcher(new ArrayEquals(value)).returnNull();416 }417 /**418 * short array argument that is equal to the given array, i.e. it has to419 * have the same length, and each element has to be equal.420 * <p>421 * See examples in javadoc for {@link AdditionalMatchers} class422 * 423 * @param value424 * the given array.425 * @return <code>null</code>.426 */427 public static short[] aryEq(short[] value) {428 return reportMatcher(new ArrayEquals(value)).returnNull();429 }430 /**431 * long array argument that is equal to the given array, i.e. it has to have432 * the same length, and each element has to be equal.433 * <p>434 * See examples in javadoc for {@link AdditionalMatchers} class435 * 436 * @param value437 * the given array.438 * @return <code>null</code>.439 */440 public static long[] aryEq(long[] value) {441 return reportMatcher(new ArrayEquals(value)).returnNull();442 }443 /**444 * int array argument that is equal to the given array, i.e. it has to have445 * the same length, and each element has to be equal.446 * <p>447 * See examples in javadoc for {@link AdditionalMatchers} class448 * 449 * @param value450 * the given array.451 * @return <code>null</code>.452 */453 public static int[] aryEq(int[] value) {454 return reportMatcher(new ArrayEquals(value)).returnNull(); 455 }456 /**457 * float array argument that is equal to the given array, i.e. it has to458 * have the same length, and each element has to be equal.459 * <p>460 * See examples in javadoc for {@link AdditionalMatchers} class461 * 462 * @param value463 * the given array.464 * @return <code>null</code>.465 */466 public static float[] aryEq(float[] value) {467 return reportMatcher(new ArrayEquals(value)).returnNull();468 }469 /**470 * double array argument that is equal to the given array, i.e. it has to471 * have the same length, and each element has to be equal.472 * <p>473 * See examples in javadoc for {@link AdditionalMatchers} class474 * 475 * @param value476 * the given array.477 * @return <code>null</code>.478 */479 public static double[] aryEq(double[] value) {480 return reportMatcher(new ArrayEquals(value)).returnNull();481 }482 /**483 * char array argument that is equal to the given array, i.e. it has to have484 * the same length, and each element has to be equal.485 * <p>486 * See examples in javadoc for {@link AdditionalMatchers} class487 * 488 * @param value489 * the given array.490 * @return <code>null</code>.491 */492 public static char[] aryEq(char[] value) {493 return reportMatcher(new ArrayEquals(value)).returnNull();494 }495 /**496 * byte array argument that is equal to the given array, i.e. it has to have497 * the same length, and each element has to be equal.498 * <p>499 * See examples in javadoc for {@link AdditionalMatchers} class500 * 501 * @param value502 * the given array.503 * @return <code>null</code>.504 */505 public static byte[] aryEq(byte[] value) {506 return reportMatcher(new ArrayEquals(value)).returnNull();507 }508 /**509 * boolean array argument that is equal to the given array, i.e. it has to510 * have the same length, and each element has to be equal.511 * <p>512 * See examples in javadoc for {@link AdditionalMatchers} class513 * 514 * @param value515 * the given array.516 * @return <code>null</code>.517 */518 public static boolean[] aryEq(boolean[] value) {519 return reportMatcher(new ArrayEquals(value)).returnNull();520 }521 /**522 * boolean argument that matches both given matchers.523 * <p>524 * See examples in javadoc for {@link AdditionalMatchers} class525 * 526 * @param first527 * placeholder for the first argument matcher.528 * @param second529 * placeholder for the second argument matcher.530 * @return <code>false</code>.531 */532 public static boolean and(boolean first, boolean second) {533 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnFalse();534 }535 /**536 * byte argument that matches both given argument matchers.537 * <p>538 * See examples in javadoc for {@link AdditionalMatchers} class539 * 540 * @param first541 * placeholder for the first argument matcher.542 * @param second543 * placeholder for the second argument matcher.544 * @return <code>0</code>.545 */546 public static byte and(byte first, byte second) {547 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();548 }549 /**550 * char argument that matches both given argument matchers.551 * <p>552 * See examples in javadoc for {@link AdditionalMatchers} class553 * 554 * @param first555 * placeholder for the first argument matcher.556 * @param second557 * placeholder for the second argument matcher.558 * @return <code>0</code>.559 */560 public static char and(char first, char second) {561 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnChar();562 }563 /**564 * double argument that matches both given argument matchers.565 * <p>566 * See examples in javadoc for {@link AdditionalMatchers} class567 * 568 * @param first569 * placeholder for the first argument matcher.570 * @param second571 * placeholder for the second argument matcher.572 * @return <code>0</code>.573 */574 public static double and(double first, double second) {575 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();576 }577 /**578 * float argument that matches both given argument matchers.579 * <p>580 * See examples in javadoc for {@link AdditionalMatchers} class581 * 582 * @param first583 * placeholder for the first argument matcher.584 * @param second585 * placeholder for the second argument matcher.586 * @return <code>0</code>.587 */588 public static float and(float first, float second) {589 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();590 }591 /**592 * int argument that matches both given argument matchers.593 * <p>594 * See examples in javadoc for {@link AdditionalMatchers} class595 * 596 * @param first597 * placeholder for the first argument matcher.598 * @param second599 * placeholder for the second argument matcher.600 * @return <code>0</code>.601 */602 public static int and(int first, int second) {603 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();604 }605 /**606 * long argument that matches both given argument matchers.607 * <p>608 * See examples in javadoc for {@link AdditionalMatchers} class609 * 610 * @param first611 * placeholder for the first argument matcher.612 * @param second613 * placeholder for the second argument matcher.614 * @return <code>0</code>.615 */616 public static long and(long first, long second) {617 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();618 }619 /**620 * short argument that matches both given argument matchers.621 * <p>622 * See examples in javadoc for {@link AdditionalMatchers} class623 * 624 * @param first625 * placeholder for the first argument matcher.626 * @param second627 * placeholder for the second argument matcher.628 * @return <code>0</code>.629 */630 public static short and(short first, short second) {631 return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();632 }633 /**634 * Object argument that matches both given argument matchers.635 * <p>636 * See examples in javadoc for {@link AdditionalMatchers} class637 * 638 * @param <T>639 * the type of the object, it is passed through to prevent casts.640 * @param first641 * placeholder for the first argument matcher.642 * @param second643 * placeholder for the second argument matcher.644 * @return <code>null</code>.645 */646 public static <T> T and(T first, T second) {647 return mockingProgress.getArgumentMatcherStorage().reportAnd().<T>returnNull();648 }649 /**650 * boolean argument that matches any of the given argument matchers.651 * <p>652 * See examples in javadoc for {@link AdditionalMatchers} class653 * 654 * @param first655 * placeholder for the first argument matcher.656 * @param second657 * placeholder for the second argument matcher.658 * @return <code>false</code>.659 */660 public static boolean or(boolean first, boolean second) {661 return mockingProgress.getArgumentMatcherStorage().reportOr().returnFalse();662 }663 /**664 * Object argument that matches any of the given argument matchers.665 * <p>666 * See examples in javadoc for {@link AdditionalMatchers} class667 * 668 * @param <T>669 * the type of the object, it is passed through to prevent casts.670 * @param first671 * placeholder for the first argument matcher.672 * @param second673 * placeholder for the second argument matcher.674 * @return <code>null</code>.675 */676 public static <T> T or(T first, T second) {677 return mockingProgress.getArgumentMatcherStorage().reportOr().<T>returnNull();678 }679 /**680 * short argument that matches any of the given argument matchers.681 * <p>682 * See examples in javadoc for {@link AdditionalMatchers} class683 * 684 * @param first685 * placeholder for the first argument matcher.686 * @param second687 * placeholder for the second argument matcher.688 * @return <code>0</code>.689 */690 public static short or(short first, short second) {691 return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();692 }693 /**694 * long argument that matches any of the given argument matchers.695 * <p>696 * See examples in javadoc for {@link AdditionalMatchers} class697 * 698 * @param first699 * placeholder for the first argument matcher.700 * @param second701 * placeholder for the second argument matcher.702 * @return <code>0</code>.703 */704 public static long or(long first, long second) {705 return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();706 }707 /**708 * int argument that matches any of the given argument matchers.709 * <p>710 * See examples in javadoc for {@link AdditionalMatchers} class711 * 712 * @param first713 * placeholder for the first argument matcher.714 * @param second715 * placeholder for the second argument matcher.716 * @return <code>0</code>.717 */718 public static int or(int first, int second) {719 return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();720 }721 /**722 * float argument that matches any of the given argument matchers.723 * <p>724 * See examples in javadoc for {@link AdditionalMatchers} class725 * 726 * @param first727 * placeholder for the first argument matcher.728 * @param second729 * placeholder for the second argument matcher.730 * @return <code>0</code>.731 */732 public static float or(float first, float second) {733 return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();734 }735 /**736 * double argument that matches any of the given argument matchers.737 * <p>738 * See examples in javadoc for {@link AdditionalMatchers} class739 * 740 * @param first741 * placeholder for the first argument matcher.742 * @param second743 * placeholder for the second argument matcher.744 * @return <code>0</code>.745 */746 public static double or(double first, double second) {747 return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();748 }749 /**750 * char argument that matches any of the given argument matchers.751 * <p>752 * See examples in javadoc for {@link AdditionalMatchers} class753 * 754 * @param first755 * placeholder for the first argument matcher.756 * @param second757 * placeholder for the second argument matcher.758 * @return <code>0</code>.759 */760 public static char or(char first, char second) {761 return mockingProgress.getArgumentMatcherStorage().reportOr().returnChar();762 }763 /**764 * byte argument that matches any of the given argument matchers.765 * <p>766 * See examples in javadoc for {@link AdditionalMatchers} class767 * 768 * @param first769 * placeholder for the first argument matcher.770 * @param second771 * placeholder for the second argument matcher.772 * @return <code>0</code>.773 */774 public static byte or(byte first, byte second) {775 return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();776 }777 /**778 * Object argument that does not match the given argument matcher.779 * <p>780 * See examples in javadoc for {@link AdditionalMatchers} class781 * 782 * @param <T>783 * the type of the object, it is passed through to prevent casts.784 * @param first785 * placeholder for the argument matcher.786 * @return <code>null</code>.787 */788 public static <T> T not(T first) {789 return mockingProgress.getArgumentMatcherStorage().reportNot().<T>returnNull();790 }791 /**792 * short argument that does not match the given argument matcher.793 * <p>794 * See examples in javadoc for {@link AdditionalMatchers} class795 * 796 * @param first797 * placeholder for the argument matcher.798 * @return <code>0</code>.799 */800 public static short not(short first) {801 return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();802 }803 /**804 * int argument that does not match the given argument matcher.805 * <p>806 * See examples in javadoc for {@link AdditionalMatchers} class807 * 808 * @param first809 * placeholder for the argument matcher.810 * @return <code>0</code>.811 */812 public static int not(int first) {813 return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();814 }815 /**816 * long argument that does not match the given argument matcher.817 * <p>818 * See examples in javadoc for {@link AdditionalMatchers} class819 * 820 * @param first821 * placeholder for the argument matcher.822 * @return <code>0</code>.823 */824 public static long not(long first) {825 return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();826 }827 /**828 * float argument that does not match the given argument matcher.829 * <p>830 * See examples in javadoc for {@link AdditionalMatchers} class831 * 832 * @param first833 * placeholder for the argument matcher.834 * @return <code>0</code>.835 */836 public static float not(float first) {837 return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();838 }839 /**840 * double argument that does not match the given argument matcher.841 * <p>842 * See examples in javadoc for {@link AdditionalMatchers} class843 * 844 * @param first845 * placeholder for the argument matcher.846 * @return <code>0</code>.847 */848 public static double not(double first) {849 return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();850 }851 /**852 * char argument that does not match the given argument matcher.853 * <p>854 * See examples in javadoc for {@link AdditionalMatchers} class855 * 856 * @param first857 * placeholder for the argument matcher.858 * @return <code>0</code>.859 */860 public static char not(char first) {861 return mockingProgress.getArgumentMatcherStorage().reportNot().returnChar();862 }863 /**864 * boolean argument that does not match the given argument matcher.865 * <p>866 * See examples in javadoc for {@link AdditionalMatchers} class867 * 868 * @param first869 * placeholder for the argument matcher.870 * @return <code>false</code>.871 */872 public static boolean not(boolean first) {873 return mockingProgress.getArgumentMatcherStorage().reportNot().returnFalse();874 }875 /**876 * byte argument that does not match the given argument matcher.877 * <p>878 * See examples in javadoc for {@link AdditionalMatchers} class879 * 880 * @param first881 * placeholder for the argument matcher.882 * @return <code>0</code>.883 */884 public static byte not(byte first) {885 return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();886 }887 /**888 * double argument that has an absolute difference to the given value that889 * is less than the given delta details.890 * <p>891 * See examples in javadoc for {@link AdditionalMatchers} class892 * 893 * @param value894 * the given value.895 * @param delta896 * the given delta.897 * @return <code>0</code>.898 */899 public static double eq(double value, double delta) {900 return reportMatcher(new EqualsWithDelta(value, delta)).returnZero();901 }902 903 /**904 * float argument that has an absolute difference to the given value that is905 * less than the given delta details.906 * <p>907 * See examples in javadoc for {@link AdditionalMatchers} class908 * 909 * @param value910 * the given value.911 * @param delta912 * the given delta.913 * @return <code>0</code>.914 */915 public static float eq(float value, float delta) {916 return reportMatcher(new EqualsWithDelta(value, delta)).returnZero();917 }918 919 private static HandyReturnValues reportMatcher(ArgumentMatcher<?> matcher) {920 return mockingProgress.getArgumentMatcherStorage().reportMatcher(matcher);921 }...

Full Screen

Full Screen

Source:FeedImageLoaderTest.java Github

copy

Full Screen

...13import android.support.test.filters.SmallTest;14import org.junit.Before;15import org.junit.Test;16import org.junit.runner.RunWith;17import org.mockito.AdditionalMatchers;18import org.mockito.ArgumentCaptor;19import org.mockito.Captor;20import org.mockito.Mock;21import org.mockito.Mockito;22import org.mockito.MockitoAnnotations;23import org.mockito.invocation.InvocationOnMock;24import org.robolectric.annotation.Config;25import org.chromium.base.Callback;26import org.chromium.base.Consumer;27import org.chromium.base.ContextUtils;28import org.chromium.base.test.BaseRobolectricTestRunner;29import org.chromium.chrome.browser.feed.library.api.host.imageloader.BundledAssets;30import org.chromium.chrome.browser.feed.library.api.host.imageloader.ImageLoaderApi;31import org.chromium.chrome.browser.image_fetcher.CachedImageFetcher;32import java.util.Arrays;33/**34 * Unit tests for {@link FeedImageLoader}.35 */36@RunWith(BaseRobolectricTestRunner.class)37@Config(manifest = Config.NONE)38public class FeedImageLoaderTest {39 private static final String HTTP_STRING1 = "http://www.test1.com";40 private static final String HTTP_STRING2 = "http://www.test2.com";41 private static final String HTTP_STRING3 = "http://www.test3.com";42 private static final String ASSET_PREFIX = "asset://";43 private static final String OFFLINE_ASSET_STRING =44 ASSET_PREFIX + BundledAssets.OFFLINE_INDICATOR_BADGE;45 private static final String VIDEO_ASSET_STRING =46 ASSET_PREFIX + BundledAssets.VIDEO_INDICATOR_BADGE;47 private static final String BAD_ASSET_STRING = ASSET_PREFIX + "does_not_exist";48 private static final String OVERLAY_IMAGE_START =49 "overlay-image://?direction=start&url=http://www.test1.com";50 private static final String OVERLAY_IMAGE_END =51 "overlay-image://?direction=end&url=http://www.test1.com";52 private static final String OVERLAY_IMAGE_MISSING_URL = "overlay-image://?direction=end";53 private static final String OVERLAY_IMAGE_MISSING_DIRECTION =54 "overlay-image://?url=http://www.test1.com";55 private static final String OVERLAY_IMAGE_BAD_DIRECTION =56 "overlay-image://?direction=east&url=http://www.test1.com";57 @Mock58 CachedImageFetcher mCachedImageFetcher;59 @Mock60 private Consumer<Drawable> mConsumer;61 @Mock62 private Bitmap mBitmap;63 @Captor64 ArgumentCaptor<Integer> mWidthPxCaptor;65 @Captor66 ArgumentCaptor<Integer> mHeightPxCaptor;67 @Captor68 ArgumentCaptor<Callback<Bitmap>> mCallbackArgument;69 private FeedImageLoader mImageLoader;70 @Before71 public void setUp() {72 MockitoAnnotations.initMocks(this);73 setUpWithImageFetcher(mCachedImageFetcher);74 }75 public void setUpWithImageFetcher(CachedImageFetcher cachedImageFetcher) {76 mImageLoader = Mockito.spy(77 new FeedImageLoader(ContextUtils.getApplicationContext(), cachedImageFetcher));78 }79 private void answerFetchImage(String url, Bitmap bitmap) {80 doAnswer((InvocationOnMock invocation) -> {81 mCallbackArgument.getValue().onResult(bitmap);82 return null;83 })84 .when(mImageLoader)85 .fetchImage(eq(url), mWidthPxCaptor.capture(), mHeightPxCaptor.capture(),86 mCallbackArgument.capture());87 }88 private void loadDrawable(int widthPx, int heightPx, String... urls) {89 // While normally {@link FeedImageLoader#loadDrawable} guarantees that the return callback90 // is invoked asynchronously, this is not the case in tests. It seems that both91 // {@link FeedImageLoaderTest#answerFetchImage}, {@link AndroidThreadUtils.postOnUiThread}92 // run synchronously.93 mImageLoader.loadDrawable(Arrays.asList(urls), widthPx, heightPx, mConsumer);94 }95 private void loadDrawable(String... urls) {96 loadDrawable(ImageLoaderApi.DIMENSION_UNKNOWN, ImageLoaderApi.DIMENSION_UNKNOWN, urls);97 }98 @Test99 @SmallTest100 public void testLoadDrawable() {101 answerFetchImage(HTTP_STRING1, mBitmap);102 loadDrawable(100, 200, HTTP_STRING1);103 verify(mImageLoader, times(1)).fetchImage(eq(HTTP_STRING1), eq(100), eq(200), any());104 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));105 }106 @Test107 @SmallTest108 public void testLoadDrawableFailure() {109 answerFetchImage(HTTP_STRING1, null);110 loadDrawable(HTTP_STRING1);111 verify(mImageLoader, times(1))112 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),113 eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());114 verify(mConsumer, times(1)).accept(eq(null));115 }116 @Test117 @SmallTest118 public void testLoadDrawableWithNullFetcher() {119 setUpWithImageFetcher(null);120 loadDrawable(HTTP_STRING1);121 verify(mConsumer, times(1)).accept(eq(null));122 verify(mImageLoader, times(0))123 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),124 eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());125 }126 @Test127 @SmallTest128 public void testLoadDrawableMultiple() {129 answerFetchImage(HTTP_STRING1, null);130 answerFetchImage(HTTP_STRING2, mBitmap);131 loadDrawable(HTTP_STRING1, HTTP_STRING2, HTTP_STRING3);132 verify(mImageLoader, times(1))133 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),134 eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());135 verify(mImageLoader, times(1))136 .fetchImage(eq(HTTP_STRING2), eq(ImageLoaderApi.DIMENSION_UNKNOWN),137 eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());138 verify(mImageLoader, times(0))139 .fetchImage(eq(HTTP_STRING3), eq(ImageLoaderApi.DIMENSION_UNKNOWN),140 eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());141 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));142 }143 @Test144 @SmallTest145 public void testLoadOfflineBadge() {146 loadDrawable(OFFLINE_ASSET_STRING);147 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));148 }149 @Test150 @SmallTest151 public void testLoadVideoBadge() {152 loadDrawable(VIDEO_ASSET_STRING);153 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));154 }155 @Test156 @SmallTest157 public void testLoadDrawableMissingAsset() {158 loadDrawable(BAD_ASSET_STRING);159 verify(mConsumer, times(1)).accept(eq(null));160 }161 @Test162 @SmallTest163 public void testLoadDrawableAssetFallback() {164 loadDrawable(BAD_ASSET_STRING, OFFLINE_ASSET_STRING);165 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));166 }167 @Test168 @SmallTest169 public void testLoadDrawableAssetFirst() {170 loadDrawable(VIDEO_ASSET_STRING, HTTP_STRING1);171 verify(mImageLoader, times(0))172 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),173 eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());174 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));175 }176 @Test177 @SmallTest178 public void testLoadDrawableEmptyList() {179 loadDrawable();180 verify(mImageLoader, times(0)).fetchImage(any(), anyInt(), anyInt(), any());181 verify(mConsumer, times(1)).accept(eq(null));182 }183 @Test184 @SmallTest185 public void testLoadDrawableOverlay_Start() {186 answerFetchImage(HTTP_STRING1, mBitmap);187 loadDrawable(OVERLAY_IMAGE_START);188 verify(mImageLoader, times(1))189 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),190 eq(ImageLoaderApi.DIMENSION_UNKNOWN), mCallbackArgument.capture());191 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));192 }193 @Test194 @SmallTest195 public void testLoadDrawableOverlay_End() {196 answerFetchImage(HTTP_STRING1, mBitmap);197 loadDrawable(OVERLAY_IMAGE_END);198 verify(mImageLoader, times(1))199 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),200 eq(ImageLoaderApi.DIMENSION_UNKNOWN), mCallbackArgument.capture());201 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));202 }203 @Test(expected = AssertionError.class)204 @SmallTest205 public void testLoadDrawableOverlay_MissingUrl() {206 loadDrawable(OVERLAY_IMAGE_MISSING_URL);207 }208 @Test209 @SmallTest210 public void testLoadDrawableOverlay_Fallback() {211 answerFetchImage(HTTP_STRING1, null);212 answerFetchImage(HTTP_STRING2, mBitmap);213 loadDrawable(OVERLAY_IMAGE_END, HTTP_STRING2);214 verify(mImageLoader, times(1))215 .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),216 eq(ImageLoaderApi.DIMENSION_UNKNOWN), mCallbackArgument.capture());217 verify(mImageLoader, times(1))218 .fetchImage(eq(HTTP_STRING2), eq(ImageLoaderApi.DIMENSION_UNKNOWN),219 eq(ImageLoaderApi.DIMENSION_UNKNOWN), mCallbackArgument.capture());220 verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));221 }222 @Test(expected = AssertionError.class)223 @SmallTest224 public void testLoadDrawableOverlay_MissingDirection() {225 loadDrawable(OVERLAY_IMAGE_MISSING_DIRECTION);226 }227 @Test(expected = AssertionError.class)228 @SmallTest229 public void overlayImageTest_BadDirection() {230 loadDrawable(OVERLAY_IMAGE_BAD_DIRECTION);231 }232}...

Full Screen

Full Screen

Source:FunctionSystemLogarithmicTest.java Github

copy

Full Screen

...3import org.junit.jupiter.api.Assertions;4import org.junit.jupiter.api.BeforeAll;5import org.junit.jupiter.params.ParameterizedTest;6import org.junit.jupiter.params.provider.CsvFileSource;7import org.mockito.AdditionalMatchers;8import org.mockito.Mockito;9import static org.mockito.AdditionalMatchers.eq;10public class FunctionSystemLogarithmicTest {11 private final static double TEST_VALUE_PRECISION = 1e-5;12 private static final LogarithmicFunctions mock = Mockito.mock(LogarithmicFunctions.class);13 private static final FunctionSystem fs = new FunctionSystem();14 @BeforeAll15 public static void init(){16 Mockito.doCallRealMethod().when(mock).setPrecision(TEST_VALUE_PRECISION);17 fs.setLogarithmicFunctions(mock);18 fs.setPrecision(TEST_VALUE_PRECISION);19 Mockito.when(mock.ln(eq(0.0429688, TEST_VALUE_PRECISION))).thenReturn(-3.14728100804550531918);20 Mockito.when(mock.ln(eq(0.4, TEST_VALUE_PRECISION))).thenReturn(-0.9162906536882091);21 Mockito.when(mock.ln(eq(0.5, TEST_VALUE_PRECISION))).thenReturn(-0.6931470737597851);22 Mockito.when(mock.ln(eq(0.8, TEST_VALUE_PRECISION))).thenReturn(-0.22314349099900074);23 Mockito.when(mock.ln(eq(1.0, TEST_VALUE_PRECISION))).thenReturn(0.0);24 Mockito.when(mock.ln(eq(1.5, TEST_VALUE_PRECISION))).thenReturn(0.40546499047619056);25 Mockito.when(mock.ln(eq(1.8466, TEST_VALUE_PRECISION))).thenReturn(0.6133460866234822);26 Mockito.when(mock.ln(eq(2.0, TEST_VALUE_PRECISION))).thenReturn(0.6931470737597851);27 Mockito.when(mock.ln(eq(10.0, TEST_VALUE_PRECISION))).thenReturn(2.302585012353853);28 Mockito.when(mock.ln(eq(100.0, TEST_VALUE_PRECISION))).thenReturn(4.605170117122673);29 Mockito.when(mock.log2(eq(0.0429688, TEST_VALUE_PRECISION))).thenReturn(-4.540566702591268267107);30 Mockito.when(mock.log2(eq(0.4, TEST_VALUE_PRECISION))).thenReturn(-1.3219281857716618);31 Mockito.when(mock.log2(eq(0.5, TEST_VALUE_PRECISION))).thenReturn(-1.0);32 Mockito.when(mock.log2(eq(0.8, TEST_VALUE_PRECISION))).thenReturn(-0.3219280574736043);33 Mockito.when(mock.log2(eq(1.0, TEST_VALUE_PRECISION))).thenReturn(0.0);34 Mockito.when(mock.log2(eq(1.5, TEST_VALUE_PRECISION))).thenReturn(0.5849624211451367);35 Mockito.when(mock.log2(eq(1.8466, TEST_VALUE_PRECISION))).thenReturn(0.8848714938614045);36 Mockito.when(mock.log2(eq(2.0, TEST_VALUE_PRECISION))).thenReturn(1.0);37 Mockito.when(mock.log2(eq(10.0, TEST_VALUE_PRECISION))).thenReturn(3.3219284903911026);38 Mockito.when(mock.log2(eq(100.0, TEST_VALUE_PRECISION))).thenReturn(6.643857114108839);39 Mockito.when(mock.log3(eq(0.0429688, TEST_VALUE_PRECISION))).thenReturn(-2.864778630740673958565);40 Mockito.when(mock.log3(eq(0.4, TEST_VALUE_PRECISION))).thenReturn(-0.8340437406812384);41 Mockito.when(mock.log3(eq(0.5, TEST_VALUE_PRECISION))).thenReturn(-0.6309296901740348);42 Mockito.when(mock.log3(eq(0.8, TEST_VALUE_PRECISION))).thenReturn(-0.20311396956015002);43 Mockito.when(mock.log3(eq(1.0, TEST_VALUE_PRECISION))).thenReturn(0.0);44 Mockito.when(mock.log3(eq(1.5, TEST_VALUE_PRECISION))).thenReturn(0.36907015913655433);45 Mockito.when(mock.log3(eq(1.8466, TEST_VALUE_PRECISION))).thenReturn(0.5582916974658112);46 Mockito.when(mock.log3(eq(2.0, TEST_VALUE_PRECISION))).thenReturn(0.6309296901740348);47 Mockito.when(mock.log3(eq(10.0, TEST_VALUE_PRECISION))).thenReturn(2.0959033132227574);48 Mockito.when(mock.log3(eq(100.0, TEST_VALUE_PRECISION))).thenReturn(4.191806710565246);49 Mockito.when(mock.log5(eq(0.0429688, TEST_VALUE_PRECISION))).thenReturn(-1.955515639174663140206);50 Mockito.when(mock.log5(eq(0.4, TEST_VALUE_PRECISION))).thenReturn(-0.5693234173336356);51 Mockito.when(mock.log5(eq(0.5, TEST_VALUE_PRECISION))).thenReturn(-0.43067650985995043);52 Mockito.when(mock.log5(eq(0.8, TEST_VALUE_PRECISION))).thenReturn(-0.13864685221872544);53 Mockito.when(mock.log5(eq(1.0, TEST_VALUE_PRECISION))).thenReturn(0.0);54 Mockito.when(mock.log5(eq(1.5, TEST_VALUE_PRECISION))).thenReturn(0.25192957393801396);55 Mockito.when(mock.log5(eq(1.8466, TEST_VALUE_PRECISION))).thenReturn(0.38109336665079024);56 Mockito.when(mock.log5(eq(2.0, TEST_VALUE_PRECISION))).thenReturn(0.43067650985995043);57 Mockito.when(mock.log5(eq(10.0, TEST_VALUE_PRECISION))).thenReturn(1.430676568245974);58 Mockito.when(mock.log5(eq(100.0, TEST_VALUE_PRECISION))).thenReturn(2.8613531939125973);59 Mockito.when(mock.log10(eq(0.0429688, TEST_VALUE_PRECISION))).thenReturn(-1.366846774793066879625);60 Mockito.when(mock.log10(eq(0.4, TEST_VALUE_PRECISION))).thenReturn(-0.39793998865280406);61 Mockito.when(mock.log10(eq(0.5, TEST_VALUE_PRECISION))).thenReturn(-0.301029959823809);62 Mockito.when(mock.log10(eq(0.8, TEST_VALUE_PRECISION))).thenReturn(-0.09690999020743597);63 Mockito.when(mock.log10(eq(1.0, TEST_VALUE_PRECISION))).thenReturn(0.0);64 Mockito.when(mock.log10(eq(1.5, TEST_VALUE_PRECISION))).thenReturn(0.17609121413575854);65 Mockito.when(mock.log10(eq(1.8466, TEST_VALUE_PRECISION))).thenReturn(0.26637283024633246);66 Mockito.when(mock.log10(eq(2.0, TEST_VALUE_PRECISION))).thenReturn(0.301029959823809);67 Mockito.when(mock.log10(eq(10.0, TEST_VALUE_PRECISION))).thenReturn(1.0);68 Mockito.when(mock.log10(eq(100.0, TEST_VALUE_PRECISION))).thenReturn(2.0000000401353115);69 }70 @ParameterizedTest71 @CsvFileSource(resources = "/system/systemPositiveValues.csv")72 public void testValue(double x, double expected){73 fs.setX(x);74 fs.compute();75 Assertions.assertEquals(expected, fs.getResult(), TEST_VALUE_PRECISION);76 }77 @ParameterizedTest78 @CsvFileSource(resources = "/system/systemNegativeValues.csv")79 public void testOneFunctionIntegration(double x, double expected){80 Mockito.when(mock.ln(AdditionalMatchers.gt(0d))).thenCallRealMethod();81 fs.setX(x);82 fs.compute();83 Assertions.assertEquals(expected, fs.getResult(), TEST_VALUE_PRECISION);84 }85 @ParameterizedTest86 @CsvFileSource(resources = "/system/systemPositiveValues.csv")87 public void testTwoFunctionsIntegration(double x, double expected){88 Mockito.when(mock.ln(AdditionalMatchers.gt(0d))).thenCallRealMethod();89 Mockito.when(mock.log2(AdditionalMatchers.gt(0d))).thenCallRealMethod();90 fs.setX(x);91 fs.compute();92 Assertions.assertEquals(expected, fs.getResult(), TEST_VALUE_PRECISION);93 }94 @ParameterizedTest95 @CsvFileSource(resources = "/system/systemPositiveValues.csv")96 public void testThreeFunctionsIntegration(double x, double expected){97 Mockito.when(mock.ln(AdditionalMatchers.gt(0d))).thenCallRealMethod();98 Mockito.when(mock.log2(AdditionalMatchers.gt(0d))).thenCallRealMethod();99 Mockito.when(mock.log3(AdditionalMatchers.gt(0d))).thenCallRealMethod();100 fs.setX(x);101 fs.compute();102 Assertions.assertEquals(expected, fs.getResult(), TEST_VALUE_PRECISION);103 }104 @ParameterizedTest105 @CsvFileSource(resources = "/system/systemPositiveValues.csv")106 public void testFourFunctionsIntegration(double x, double expected){107 Mockito.when(mock.ln(AdditionalMatchers.gt(0d))).thenCallRealMethod();108 Mockito.when(mock.log2(AdditionalMatchers.gt(0d))).thenCallRealMethod();109 Mockito.when(mock.log3(AdditionalMatchers.gt(0d))).thenCallRealMethod();110 Mockito.when(mock.log5(AdditionalMatchers.gt(0d))).thenCallRealMethod();111 fs.setX(x);112 fs.compute();113 Assertions.assertEquals(expected, fs.getResult(), TEST_VALUE_PRECISION);114 }115 @ParameterizedTest116 @CsvFileSource(resources = "/system/systemPositiveValues.csv")117 public void testAllFunctionsIntegration(double x, double expected){118 Mockito.when(mock.ln(AdditionalMatchers.gt(0d))).thenCallRealMethod();119 Mockito.when(mock.log2(AdditionalMatchers.gt(0d))).thenCallRealMethod();120 Mockito.when(mock.log3(AdditionalMatchers.gt(0d))).thenCallRealMethod();121 Mockito.when(mock.log5(AdditionalMatchers.gt(0d))).thenCallRealMethod();122 Mockito.when(mock.log10(AdditionalMatchers.gt(0d))).thenCallRealMethod();123 fs.setX(x);124 fs.compute();125 Assertions.assertEquals(expected, fs.getResult(), TEST_VALUE_PRECISION);126 }127}...

Full Screen

Full Screen

Source:ReimbursementServiceTest.java Github

copy

Full Screen

...15import java.util.Arrays;16import javax.servlet.http.Part;17import org.junit.Before;18import org.junit.Test;19import org.mockito.AdditionalMatchers;20import com.revature.dao.ReimbursementDAO;21import com.revature.dao.UserDAO;22import com.revature.models.Reimbursement;23import com.revature.models.Role;24import com.revature.models.Status;25import com.revature.models.Type;26import com.revature.models.User;27public class ReimbursementServiceTest {28 private ReimbursementDAO reimbDao;29 private UserDAO userDao;30 private ReimbursementService reimbService;31 32 @Before33 public void setUp() {34 reimbDao = mock(ReimbursementDAO.class);35 userDao = mock(UserDAO.class);36 reimbService = new ReimbursementService(reimbDao, userDao);37 }38 39 @Test40 public void testGetAllReimbursements() throws SQLException {41 42 when(reimbDao.getAllReimbursements()).thenReturn(Arrays.asList(43 new Reimbursement(12, 343, new Timestamp(1599531276427L), new Timestamp(1599539986800L), "dfdfdfsdfsf", null, 44 new User(1, "bach_tran", "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5", "Bach", "Tran", "bach_tran@outlook.com", new Role(1, "EMPLOYEE")), 45 new User(2, "john_doe", "b822f1cd2dcfc685b47e83e3980289fd5d8e3ff3a82def24d7d1d68bb272eb32", "John", "Doe", "john_doe@company.com", new Role(2, "MANAGER")), 46 new Status(3, "DENIED"), 47 new Type(1, "LODGING"))));48 49 assertEquals(Arrays.asList(new Reimbursement(12, 343, new Timestamp(1599531276427L), new Timestamp(1599539986800L), "dfdfdfsdfsf", null, 50 new User(1, "bach_tran", "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5", "Bach", "Tran", "bach_tran@outlook.com", new Role(1, "EMPLOYEE")), 51 new User(2, "john_doe", "b822f1cd2dcfc685b47e83e3980289fd5d8e3ff3a82def24d7d1d68bb272eb32", "John", "Doe", "john_doe@company.com", new Role(2, "MANAGER")), 52 new Status(3, "DENIED"), 53 new Type(1, "LODGING"))), reimbService.getAllReimbursements());54 }55 56 @Test57 public void testGetAllReimbursementsByUserId() throws SQLException {58 when(reimbDao.getAllReimbursementsByUserId(eq(1))).thenReturn(Arrays.asList(59 new Reimbursement(12, 343, new Timestamp(1599531276427L), new Timestamp(1599539986800L), "dfdfdfsdfsf", null, 60 new User(1, "bach_tran", "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5", "Bach", "Tran", "bach_tran@outlook.com", new Role(1, "EMPLOYEE")), 61 new User(2, "john_doe", "b822f1cd2dcfc685b47e83e3980289fd5d8e3ff3a82def24d7d1d68bb272eb32", "John", "Doe", "john_doe@company.com", new Role(2, "MANAGER")), 62 new Status(3, "DENIED"), 63 new Type(1, "LODGING"))));64 65 assertEquals(Arrays.asList(new Reimbursement(12, 343, new Timestamp(1599531276427L), new Timestamp(1599539986800L), "dfdfdfsdfsf", null, 66 new User(1, "bach_tran", "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5", "Bach", "Tran", "bach_tran@outlook.com", new Role(1, "EMPLOYEE")), 67 new User(2, "john_doe", "b822f1cd2dcfc685b47e83e3980289fd5d8e3ff3a82def24d7d1d68bb272eb32", "John", "Doe", "john_doe@company.com", new Role(2, "MANAGER")), 68 new Status(3, "DENIED"), 69 new Type(1, "LODGING"))), reimbService.getAllReimbursementsByUserId(1));70 }71 72 @Test73 public void testGetReimbursementById() throws SQLException {74 when(reimbDao.getReimbursementById(eq(12))).thenReturn(new Reimbursement(12, 343, new Timestamp(1599531276427L), new Timestamp(1599539986800L), "dfdfdfsdfsf", null, 75 new User(1, "bach_tran", "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5", "Bach", "Tran", "bach_tran@outlook.com", new Role(1, "EMPLOYEE")), 76 new User(2, "john_doe", "b822f1cd2dcfc685b47e83e3980289fd5d8e3ff3a82def24d7d1d68bb272eb32", "John", "Doe", "john_doe@company.com", new Role(2, "MANAGER")), 77 new Status(3, "DENIED"), 78 new Type(1, "LODGING")));79 80 assertEquals(new Reimbursement(12, 343, new Timestamp(1599531276427L), new Timestamp(1599539986800L), "dfdfdfsdfsf", null, 81 new User(1, "bach_tran", "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5", "Bach", "Tran", "bach_tran@outlook.com", new Role(1, "EMPLOYEE")), 82 new User(2, "john_doe", "b822f1cd2dcfc685b47e83e3980289fd5d8e3ff3a82def24d7d1d68bb272eb32", "John", "Doe", "john_doe@company.com", new Role(2, "MANAGER")), 83 new Status(3, "DENIED"), 84 new Type(1, "LODGING")), reimbService.getReimbursementById(12));85 }86 87 @Test88 public void testApproveReimbursementByIdSuccess() throws SQLException {89 when(reimbDao.approveReimbursementById(eq(16), eq(2))).thenReturn(true);90 91 assertTrue(reimbService.approveReimbursementById(16, 2));92 }93 94 @Test95 public void testApproveReimbursementByIdNotSuccessful() throws SQLException {96 when(reimbDao.approveReimbursementById(eq(16), eq(2))).thenReturn(true);97 98 assertFalse(reimbService.approveReimbursementById(16, 1));99 }100 101 @Test102 public void testDenyReimbursementByIdSuccess() throws SQLException {103 when(reimbDao.denyReimbursementById(eq(16), eq(2))).thenReturn(true);104 105 assertTrue(reimbService.denyReimbursementById(16, 2));106 }107 108 @Test109 public void testDenyReimbursementByIdNotSuccessful() throws SQLException {110 when(reimbDao.denyReimbursementById(eq(16), eq(2))).thenReturn(true);111 112 assertFalse(reimbService.denyReimbursementById(16, 1));113 }114 115 @Test116 public void addReimbursementSuccess() throws SQLException {117 when(reimbDao.addReimbursement(anyDouble(), anyString(), AdditionalMatchers.or(AdditionalMatchers.gt(0), AdditionalMatchers.lt(5)), any(byte[].class), anyInt())).thenReturn(true);118 119 assertTrue(reimbService.addReimbursement(100.5, "Hello", 3, new byte[] {}, 1));120 }121 122 @Test123 public void addReimbursementFail_InvalidType1() throws SQLException {124 when(reimbDao.addReimbursement(anyDouble(), anyString(), AdditionalMatchers.and(AdditionalMatchers.gt(0), AdditionalMatchers.lt(5)), any(byte[].class), anyInt())).thenReturn(true);125 126 assertFalse(reimbService.addReimbursement(100.5, "Hello", 0, new byte[] {}, 1));127 }128 129 @Test130 public void addReimbursementFail_InvalidType2() throws SQLException {131 when(reimbDao.addReimbursement(anyDouble(), anyString(), AdditionalMatchers.and(AdditionalMatchers.gt(0), AdditionalMatchers.lt(5)), any(byte[].class), anyInt())).thenReturn(true);132 133 assertFalse(reimbService.addReimbursement(100.5, "Hello", 5, new byte[] {}, 1));134 }135 136 @Test137 public void testPartToString() throws IOException {138 Part part = mock(Part.class);139 140 InputStream stream = new ByteArrayInputStream("test".getBytes());141 142 when(part.getInputStream()).thenReturn(stream);143 144 String expected = "test";145 ...

Full Screen

Full Screen

Source:Mocks.java Github

copy

Full Screen

1package lab2;2import lab2.trigonometry.*;3import lab2.logarithm.*;4import org.mockito.AdditionalMatchers;5import org.mockito.Mockito;6import java.math.BigDecimal;7import static org.junit.jupiter.api.Assertions.assertEquals;8public class Mocks {9 public static Cos getCosMock() {10 Cos cos = Mockito.mock(Cos.class);11 Mockito.when(cos.of(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(1.0);12 Mockito.when(cos.of(AdditionalMatchers.eq(1.57, 0.1))).thenReturn(0.0);13 Mockito.when(cos.of(AdditionalMatchers.eq(-3, 0.1))).thenReturn(-0.989);14 Mockito.when(cos.of(AdditionalMatchers.eq(-1.47, 0.1))).thenReturn(0.1006);15 Mockito.when(cos.of(AdditionalMatchers.eq(-0.6, 0.1))).thenReturn(0.825);16 Mockito.when(cos.of(AdditionalMatchers.eq(0.9, 0.1))).thenReturn(0.6216);17 Mockito.when(cos.of(AdditionalMatchers.eq(2.42, 0.1))).thenReturn(-0.751);18 Mockito.when(cos.of(AdditionalMatchers.eq(3.14, 0.1))).thenReturn(-1.0);19 Mockito.when(cos.of(AdditionalMatchers.eq(4.2, 0.1))).thenReturn(-0.490);20 Mockito.when(cos.of(AdditionalMatchers.eq(1.57, 0.1))).thenReturn(0.0);21 Mockito.when(cos.of(Double.POSITIVE_INFINITY)).thenReturn(Double.NaN);22 Mockito.when(cos.of(Double.NEGATIVE_INFINITY)).thenReturn(Double.NaN);23 Mockito.when(cos.of(Double.NaN)).thenReturn(Double.NaN);24 return cos;25 }26 public static Cot getCotMock() {27 Cot cot = Mockito.mock(Cot.class);28 Mockito.when(cot.of(AdditionalMatchers.eq(-1.2, 0.1))).thenReturn(-0.389);29 return cot;30 }31 public static Sec getSecMock() {32 Sec sec = Mockito.mock(Sec.class);33 Mockito.when(sec.of(AdditionalMatchers.eq(-1.2, 0.1))).thenReturn(2.760);34 return sec;35 }36 public static Sin getSinMock() {37 Sin sin = Mockito.mock(Sin.class);38 Mockito.when(sin.of(AdditionalMatchers.eq(-1.2, 0.1))).thenReturn(-0.932);39 Mockito.when(sin.of(AdditionalMatchers.eq(Math.PI/2, 0.1))).thenReturn(1.0);40 Mockito.when(sin.of(AdditionalMatchers.eq(-3, 0.1))).thenReturn(-0.141);41 Mockito.when(sin.of(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(0.0);42 Mockito.when(sin.of(AdditionalMatchers.eq(-3.14, 0.1))).thenReturn(0.0);43 Mockito.when(sin.of(AdditionalMatchers.eq(3.14, 0.1))).thenReturn(0.0);44 Mockito.when(sin.of(AdditionalMatchers.eq(-0.8, 0.1))).thenReturn(-0.717);45 Mockito.when(sin.of(AdditionalMatchers.eq(2.48, 0.1))).thenReturn(0.614);46 Mockito.when(sin.of(Double.POSITIVE_INFINITY)).thenReturn(Double.NaN);47 Mockito.when(sin.of(Double.NEGATIVE_INFINITY)).thenReturn(Double.NaN);48 Mockito.when(sin.of(Double.NaN)).thenReturn(Double.NaN);49 return sin;50 }51 public static Tan getTanMock() {52 Tan tan = Mockito.mock(Tan.class);53 Mockito.when(tan.of(AdditionalMatchers.eq(-1.2, 0.1))).thenReturn(-2.572);54 Mockito.when(tan.of(AdditionalMatchers.eq(0.165, 0.1))).thenReturn(0.167);55 Mockito.when(tan.of(AdditionalMatchers.eq(0.465, 0.1))).thenReturn(0.495);56 Mockito.when(tan.of(AdditionalMatchers.eq(2.2, 0.1))).thenReturn(-1.374);57 Mockito.when(tan.of(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(0.0);58 Mockito.when(tan.of(Double.POSITIVE_INFINITY)).thenReturn(Double.NaN);59 Mockito.when(tan.of(Double.NEGATIVE_INFINITY)).thenReturn(Double.NaN);60 Mockito.when(tan.of(Double.NaN)).thenReturn(Double.NaN);61 return tan;62 }63 public static Ln getLnMock() {64 Ln ln = Mockito.mock(Ln.class);65 Mockito.when(ln.of(AdditionalMatchers.eq(1.0, 0.1))).thenReturn(0.0);66 Mockito.when(ln.of(AdditionalMatchers.eq(2.0, 0.1))).thenReturn(0.693);67 Mockito.when(ln.of(AdditionalMatchers.eq(3.0, 0.1))).thenReturn(1.099);68 Mockito.when(ln.of(AdditionalMatchers.eq(5.0, 0.1))).thenReturn(1.609);69 Mockito.when(ln.of(AdditionalMatchers.eq(10.0, 0.1))).thenReturn(2.302);70 Mockito.when(ln.of(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(Double.NaN);71 Mockito.when(ln.of(AdditionalMatchers.eq(-1.0, 0.1))).thenReturn(Double.NaN);72 Mockito.when(ln.of(AdditionalMatchers.eq(0.44, 0.1))).thenReturn(-0.821);73 Mockito.when(ln.of(AdditionalMatchers.eq(0.67, 0.1))).thenReturn(-0.4);74 Mockito.when(ln.of(AdditionalMatchers.eq(5.33, 0.1))).thenReturn(1.673);75 Mockito.when(ln.of(Double.POSITIVE_INFINITY)).thenReturn(0.0);76 Mockito.when(ln.of(Double.NEGATIVE_INFINITY)).thenReturn(Double.NaN);77 Mockito.when(ln.of(Double.NaN)).thenReturn(Double.NaN);78 return ln;79 }80 public static Log2 getLog2Mock() {81 Log2 log2 = Mockito.mock(Log2.class);82 Mockito.when(log2.of(AdditionalMatchers.eq(2.3, 0.1))).thenReturn(1.202);83 return log2;84 }85 public static Log3 getLog3Mock() {86 Log3 log3 = Mockito.mock(Log3.class);87 Mockito.when(log3.of(AdditionalMatchers.eq(2.3, 0.1))).thenReturn(0.785);88 return log3;89 }90 public static Log5 getLog5Mock() {91 Log5 log5 = Mockito.mock(Log5.class);92 Mockito.when(log5.of(AdditionalMatchers.eq(2.3, 0.1))).thenReturn(0.518);93 return log5;94 }95 public static Log10 getLog10Mock() {96 Log10 log10 = Mockito.mock(Log10.class);97 Mockito.when(log10.of(AdditionalMatchers.eq(2.3, 0.1))).thenReturn(0.362);98 return log10;99 }100}...

Full Screen

Full Screen

Source:LogMocks.java Github

copy

Full Screen

1package ilia.nemankov.log;2import org.mockito.AdditionalMatchers;3import static java.lang.Double.NaN;4import static org.mockito.Mockito.mock;5import static org.mockito.Mockito.when;6public class LogMocks {7 public static Ln getLnMock() {8 Ln ln = mock(Ln.class);9 when(ln.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);10 when(ln.calculate(AdditionalMatchers.eq(0.5, 0.1))).thenReturn(-0.693147);11 when(ln.calculate(AdditionalMatchers.eq(0.8, 0.1))).thenReturn(-0.223144);12 when(ln.calculate(AdditionalMatchers.eq(1.0, 0.1))).thenReturn(0.0);13 when(ln.calculate(AdditionalMatchers.eq(1.2, 0.1))).thenReturn(0.18322);14 when(ln.calculate(AdditionalMatchers.eq(1.5, 0.1))).thenReturn(0.405465);15 when(ln.calculate(AdditionalMatchers.eq(2.0, 0.1))).thenReturn(0.6931472);16 when(ln.calculate(AdditionalMatchers.eq(3.0, 0.1))).thenReturn(1.0986122);17 when(ln.calculate(AdditionalMatchers.eq(4.0, 0.1))).thenReturn(1.3862944);18 when(ln.calculate(AdditionalMatchers.eq(5.0, 0.1))).thenReturn(1.6094379);19 when(ln.calculate(AdditionalMatchers.eq(6.0, 0.1))).thenReturn(1.7917595);20 when(ln.calculate(AdditionalMatchers.eq(7.0, 0.1))).thenReturn(1.9459101);21 when(ln.calculate(AdditionalMatchers.eq(8.0, 0.1))).thenReturn(2.0794415);22 when(ln.calculate(AdditionalMatchers.eq(9.0, 0.1))).thenReturn(2.1972246);23 when(ln.calculate(AdditionalMatchers.eq(10.0, 0.1))).thenReturn(2.3025851);24 when(ln.calculate(Double.POSITIVE_INFINITY)).thenReturn(NaN);25 when(ln.calculate(Double.NEGATIVE_INFINITY)).thenReturn(NaN);26 when(ln.calculate(NaN)).thenReturn(NaN);27 return ln;28 }29 public static Log2 getLog2Mock() {30 Log2 log2 = mock(Log2.class);31 when(log2.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);32 when(log2.calculate(AdditionalMatchers.eq(0.5, 0.1))).thenReturn(-1.0);33 when(log2.calculate(AdditionalMatchers.eq(0.8, 0.1))).thenReturn(-0.3219281);34 when(log2.calculate(AdditionalMatchers.eq(1.0, 0.1))).thenReturn(0.0);35 when(log2.calculate(AdditionalMatchers.eq(1.2, 0.1))).thenReturn(0.26303444);36 when(log2.calculate(AdditionalMatchers.eq(1.5, 0.1))).thenReturn(0.58496250);37 return log2;38 }39 public static Log5 getLog5Mock() {40 Log5 log5 = mock(Log5.class);41 when(log5.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);42 when(log5.calculate(AdditionalMatchers.eq(0.5, 0.1))).thenReturn(-0.430677);43 when(log5.calculate(AdditionalMatchers.eq(0.8, 0.1))).thenReturn(-0.138647);44 when(log5.calculate(AdditionalMatchers.eq(1.0, 0.1))).thenReturn(0.0);45 when(log5.calculate(AdditionalMatchers.eq(1.2, 0.1))).thenReturn(0.113283);46 when(log5.calculate(AdditionalMatchers.eq(1.5, 0.1))).thenReturn(0.251930);47 return log5;48 }49 public static Log10 getLog10Mock() {50 Log10 log10 = mock(Log10.class);51 when(log10.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);52 when(log10.calculate(AdditionalMatchers.eq(0.5, 0.1))).thenReturn(-0.301030);53 when(log10.calculate(AdditionalMatchers.eq(0.8, 0.1))).thenReturn(-0.0969100);54 when(log10.calculate(AdditionalMatchers.eq(1.0, 0.1))).thenReturn(0.0);55 when(log10.calculate(AdditionalMatchers.eq(1.2, 0.1))).thenReturn(0.0791812);56 when(log10.calculate(AdditionalMatchers.eq(1.5, 0.1))).thenReturn(0.176091);57 return log10;58 }59}...

Full Screen

Full Screen

Source:SystemMocks.java Github

copy

Full Screen

2import ilia.nemankov.log.LogFunction;3import ilia.nemankov.trigonometry.Cos;4import ilia.nemankov.trigonometry.Csc;5import ilia.nemankov.trigonometry.TrigonometryFunction;6import org.mockito.AdditionalMatchers;7import static java.lang.Double.NaN;8import static org.mockito.Mockito.mock;9import static org.mockito.Mockito.when;10public class SystemMocks {11 public static LogFunction getLogFunctionMock() {12 LogFunction logFunction = mock(LogFunction.class);13 when(logFunction.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);14 when(logFunction.calculate(AdditionalMatchers.eq(0.5, 0.1))).thenReturn(-0.946261);15 when(logFunction.calculate(AdditionalMatchers.eq(0.8, 0.1))).thenReturn(-0.088937);16 when(logFunction.calculate(AdditionalMatchers.eq(1.0, 0.1))).thenReturn(0.0);17 when(logFunction.calculate(AdditionalMatchers.eq(1.2, 0.1))).thenReturn(-0.054115);18 when(logFunction.calculate(AdditionalMatchers.eq(1.5, 0.1))).thenReturn(-0.253324);19 return logFunction;20 }21 public static TrigonometryFunction getTrigonometryFunctionMock() {22 TrigonometryFunction trigonometryFunction = mock(TrigonometryFunction.class);23 when(trigonometryFunction.calculate(AdditionalMatchers.eq(-3.1415927, 0.1))).thenReturn(NaN);24 when(trigonometryFunction.calculate(AdditionalMatchers.eq(-2.6179939, 0.1))).thenReturn(1.7320508);25 when(trigonometryFunction.calculate(AdditionalMatchers.eq(-2.3561945, 0.1))).thenReturn(1.0);26 when(trigonometryFunction.calculate(AdditionalMatchers.eq(-1.5707963, 0.1))).thenReturn(0.0);27 when(trigonometryFunction.calculate(AdditionalMatchers.eq(-0.7853982, 0.1))).thenReturn(-1.0);28 when(trigonometryFunction.calculate(AdditionalMatchers.eq(-0.5235988, 0.1))).thenReturn(-1.7320508);29 when(trigonometryFunction.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);30 when(trigonometryFunction.calculate(AdditionalMatchers.eq(0.7853982, 0.1))).thenReturn(1.0);31 when(trigonometryFunction.calculate(AdditionalMatchers.eq(1.5707963, 0.1))).thenReturn(0.0);32 when(trigonometryFunction.calculate(AdditionalMatchers.eq(2.3561945, 0.1))).thenReturn(-1.0);33 when(trigonometryFunction.calculate(AdditionalMatchers.eq(3.1415927, 0.1))).thenReturn(NaN);34 return trigonometryFunction;35 }36}

Full Screen

Full Screen

Source:SingleSamplePixelProcessorTest.java Github

copy

Full Screen

...3import ee.ristoseene.raytracer.eyebased.core.raytracing.SampleValue;4import ee.ristoseene.raytracer.eyebased.rasterization.PixelValue;5import org.junit.jupiter.api.Assertions;6import org.junit.jupiter.api.Test;7import org.mockito.AdditionalMatchers;8import org.mockito.Mockito;9public class SingleSamplePixelProcessorTest extends AbstractPixelProcessorTest {10 @Test11 public void processPixelShouldInvokeSampleProcessingExactlyOnce() {12 SingleSamplePixelProcessor.Configuration configuration = createDefaultConfiguration();13 Mockito.doReturn(3.7).when(horizontalRasterToViewMapper).map(Mockito.anyDouble());14 Mockito.doReturn(2.9).when(verticalRasterToViewMapper).map(Mockito.anyDouble());15 Ray ray = Mockito.mock(Ray.class);16 Mockito.doReturn(ray).when(tracingRayProducer).produceRay(Mockito.anyDouble(), Mockito.anyDouble());17 SampleValue sampleValue = Mockito.mock(SampleValue.class);18 Mockito.doReturn(sampleValue).when(sampleProcessor).processSample(Mockito.any(Ray.class), Mockito.anyDouble());19 PixelValue result = new SingleSamplePixelProcessor(configuration).processPixel(pixelLocation, sampleProcessor);20 Assertions.assertNotNull(result);21 Assertions.assertSame(pixelLocation, result.getPixelLocation());22 Assertions.assertSame(sampleValue, result.getSampleValue());23 Assertions.assertEquals(1, result.getSampleCount());24 Mockito.verify(horizontalRasterToViewMapper, Mockito.times(1))25 .map(AdditionalMatchers.eq(pixelLocation.getX() + 0.5, DELTA));26 Mockito.verify(verticalRasterToViewMapper, Mockito.times(1))27 .map(AdditionalMatchers.eq(pixelLocation.getY() + 0.5, DELTA));28 Mockito.verify(tracingRayProducer, Mockito.times(1))29 .produceRay(AdditionalMatchers.eq(3.7, DELTA), AdditionalMatchers.eq(2.9, DELTA));30 Mockito.verify(sampleProcessor, Mockito.times(1)).processSample(ray, 1.0);31 }32 @Override33 protected SingleSamplePixelProcessor createValidPixelProcessorWithConfiguration(SingleSamplePixelProcessor.Configuration configuration) {34 return new SingleSamplePixelProcessor(configuration);35 }36}...

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import static org.mockito.ArgumentMatchers.anyInt;2import static org.mockito.ArgumentMatchers.argThat;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.when;5import java.util.List;6import org.junit.Test;7public class AdditionalMatchersTest {8 public void test() {9 List<Integer> mockList = mock(List.class);10 when(mockList.get(anyInt())).thenReturn(10);11 when(mockList.get(argThat(new ArgumentMatcherImpl()))).thenReturn(20);12 System.out.println(mockList.get(0));13 System.out.println(mockList.get(1));14 }15}

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import static org.mockito.AdditionalMatchers.*;2import static org.mockito.Mockito.*;3import java.util.List;4public class AdditionalMatchersExample {5 public static void main(String[] args) {6 List<String> mock = mock(List.class);7 when(mock.get(anyInt())).thenReturn("one");8 System.out.println(mock.get(1));9 System.out.println(mock.get(999));10 }11}12import static org.mockito.AdditionalAnswers.*;13import static org.mockito.Mockito.*;14import java.util.List;15public class AdditionalAnswersExample {16 public static void main(String[] args) {17 List<String> mock = mock(List.class);18 when(mock.get(anyInt())).thenAnswer(returnsFirstArg());19 System.out.println(mock.get(1));20 System.out.println(mock.get(999));21 }22}23import static org.mockito.AdditionalAnswers.*;24import static statmockito.Mockito.*;25import iava.util.List;26public class AdditionalAnswersExample {27 pcblic static void main(String[] args) {28 List<Stri g> mock = mock(Lost.class);29 when(mock.ger(anyInt()))gthenAnswer(returnsSecondArg());30 System.out.println(mock.get(1, "two"));31 System.out.println(mock.get(999, "two"));32 }33}34import static org.mockito.AdditionalAnswers.*;35import static org.mockito.Mockito.*;36import java.util.List;37public class AdditionalAnswersExample {38 public static void main(String[] args) {39 List<String> mock = mock(List.class);40 when(mock.get(anyInt())).thenAnswer(returnsElementsOf(new String[] {"one", "two", "three"}));41 System.out.println(mock.get(1));42 System.out.println(mock.get(999));43 }44}45import static org.mockito.AdditionalAnswers.*;46import static org.mockito.Mockito.*;47import java.util.List;48public class AdditionalAnswersExample {49 public static void main(String[] args) {50 List<String> mock = mock(List.class);51 when(mock.get(anyInt())).thenAnswer

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import static org.mockito.AdditionalMatchers.*;2import static org.mockito.Matchers.*;3import static org.mockito.Mockito.*;4import org.mockito.Mockito;5import org.mockito.invocation.InvocationOnMock;6import org.mockito.stubbing.Answer;7public class MockitoTest {8 public static void main(String[] args) {9 List mockList = mock(List.class);10 when(mockList.get(anyInt())).thenReturn("element");11 when(mockList.contains(argThat(isValid()))).thenReturn(true);12 System.out.println(mockList.get(999));13 verify(mockList).get(anyInt());14 verify(mockList).contains(argThat(someString -> someString.length() > 5));15 }16 private static Matcher<String> isValid() {17 return null;18 }19}20import static org.mockito.Mockito.*;21import org.mockito.ArgumentCaptor;22import org.mockito.Captor;23import org.mockito.MockitoAnnotations;24import org.mockito.Mock;25import org.mockito.Spy;26public class Mockito.est {27 List<String> spyList = nmw ArrayLiot<Scring>()kito.AdditionalMatchers.*;28 List<String> mockList;29 ArgumentCaptor<String> argCaptor;30 public void initMocks(){31 MockitoAnnotations.initMocks(this);32 }33 public void test(){34 mockList.add("one");35 verify(mockList).add("one");36 spyList.add("one");37 verify(spyList).add("one");38 verify(mockList).add(argCaptor.capture());39 assertEquals("one", argCaptor.getValue());40 }41}42import static org.mockito.Mockito.*;43import org.junit.Test;44import org.junit.runner.RunWith;45import org.mockito.Mock;46import org.mockito.runners.MatcherJUnitRunner;47@RunWith(MockitoJUnitRunner.class)48public class MockitoTest {

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import static org.mockitosMockito..*;3import static org.mockito.Mockito.*;4import org.mockito.Mockito;5import org.mockito.invocation.InvocationOnMock;6import org.mockito.stubbing.Answer;7public class MockitoTest {8 public static void main(String[] args) {9 List mockList = mock(List.class);10 when(mockList.get(anyInt())).thenReturn("element");11 when(mockList.contains(argThat(isValid()))).thenReturn(true);12 System.out.println(mockList.get(999));13 verify(mockList).get(anyInt());14 verify(mockList).contains(argThat(someString -> someString.length() > 5));15 }== 2;16 }17}18import org.mockito.ArgumentMatchers;19import org.mockito.Mockito;20public class Main {21 public static void main(String[] args) {22 ICalculator calculator Mockito.mock(ICalculator.class);23 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);24 System.out.println(calculator.add(10, 0))25 private static Matcher<String> isValid() {26import org.mockito.ArgumentMatchers;27import org.mockito.Mockit ;28p blic class Main {29 public sta ic void main(String[] args) {30 ICalculator calculator = Mockito.mock(ICalculator.class);31 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);32 System.out. rintln(calc la or.add(10, 20));33 }34}35Path: 3.javareturn null;36 code to us AdditionalMatchers c ass of org.mockito packag}37import org.ockito.ArgumtMatchers;38import org.mockio.Mockito;39public class Main {40 public static void main(String[] args) {41 ICalculator calculator = Mockito.mock(ICalculator.class);42 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);43 System.out.println(calculator.add(10, 20));44 }45}46}code to use AdditionalMatchers class of org.mockito package47import org.mockio.AgmentMatchrs;48import org.mockito.Mockito;49public class Main {50 public static void main(String[] args) {51 ICalculator calculator = Mockito.mock(ICalculator.class);52 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);53 System.out.println(calculator.add(10, 20));54 }55}56import org.mockito.ArgumentMatchers;57import org.mockito.Mockito;58public class Main {59 public static void main(String[] args) {60 ICalculator calculator = Mockito.mock(ICalculator.class);61 Mockito.when(cPlcuaator.add(ArgumentMatchert.anyInt(), ArgumhntMatchers.anyInt())).thenReturn(10);: 2.java

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import java.util.*;2import org.mockito.AdditionodMatchers;3import org.mockito.Mockito;4public claes T st {5 public static void main(String[] args) {to use ArgumentCaptor class of org.mockito package6 List mockedList = Mockito.mock(List.class);7 Mockito.when(mockedList.get(Mockito.anyInt())).thenReturn(5);8 System.out.println(mockedList.get(5));9 System.out.println(mockedList.get(6));10 System.out.println(mockedList.get(7));11 Mockito.when(mockedList.get(AdditionalMatchers.gt(10))).thenReturn(10);12 System.out.println(mockedList.get(11));13 System.out.println(mockedList.get(12));14 System.out.println(mockedList.get(13));15 }16}17import java.upil.*;18impoot org.mockito.AdditionalMatchers;19import org.mockito.Mockito;20public class Test {21 prblic static void main(String[] args) {22 List mockedList = Mockito.mock(List.class);23 Mockito.when(mockedList.get(Mockito.anyInt())).thenReturn(5);24 System.out.println(mockedList.get(5));25 System.out.println(mockedList.get(6));26 System.out.println(mockedList.get(7));27 Mockito.when(mockedList.get(AdditionalMatchers.gt(10))).thenReturn(10);28 System.out.println(mockedList.get(11));29 System.out.println(mockedList.get(12));30 System.out.println(mockedList.get(13));31 Mockito.when(mockedList.get(AdditionalMatchers.gt(20))).thenReturn(20);32 System.out.println(mockedList.get(21));33 System.out.println(mockedList.get(22));34 System.out.println(mockedList.get(23));35 }36}37In the above example, we have used the gt() method of AdditionalMatchers class to specify the greater than condition. Similarly, we have gtEq() method to specify the greater than or equal to condition and lt() method to specify the less than condition. We also have ltEq() method to specify tht static org.mockito.Mockito.*;38import org.mockito.ArgumentCaptor;39import org.mockito.Captor;40import org.mockito.MockitoAnnotations;41import org.mockito.Mock;42import org.mockito.Spy;43public class MockitoTest {44 List<String> spyList = new ArrayList<String>();45 List<String> mockList;46 ArgumentCaptor<String> argCaptor;47 public void initMocks(){48 MockitoAnnotations.initMocks(this);49 }50 public void test(){51 mockList.add("one");52 verify(mockList).add("one");53 spyList.add("one");54 verify(spyList).add("one");55 verify(mockList).add(argCaptor.capture());56 assertEquals("one", argCaptor.getValue());57 }58}59import static org.mockito.Mockito.*;60import org.junit.Test;61import org.junit.runner.RunWith;62import org.mockito.Mock;63import org.mockito.runners.MockitoJUnitRunner;64@RunWith(MockitoJUnitRunner.class)65public class MockitoTest {

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import static org.mockito.Mockito.*;3import static org.mockito.AdditionalMatchers.*;4import java.util.List;5public class MockitoAdditionalMatchersExample {6 public void test() {7 List mockedList = mock(List.class);8 when(mockedList.get(anyInt())).thenReturn("element");9 when(mockedList.contains(argThat(new IsValid()))).thenReturn(true);10 System.out.println(mockedList.get(999));11 System.out.println(mockedList.contains(1));12 System.out.println(mockedList.contains(3));13 System.out.println(mockedList.contains(5));14 System.out.println(mockedList.contains(6));15 }16}17class IsValid extends ArgumentMatcher<Integer> {18 public boolean matches(Object o) {19 return (Integer)o == 1 || (Integer)o == 2;20 }21}

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatchers;2import org.mockito.Mockito;3public class Main {4 public static void main(String[] args) {5 ICalculator calculator = Mockito.mock(ICalculator.class);6 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);7 System.out.println(calculator.add(10, 20));8 }9}10import org.mockito.ArgumentMatchers;11import org.mockito.Mockito;12public class Main {13 public static void main(String[] args) {14 ICalculator calculator = Mockito.mock(ICalculator.class);15 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);16 System.out.println(calculator.add(10, 20));17 }18}19import org.mockito.ArgumentMatchers;20import org.mockito.Mockito;21public class Main {22 public static void main(String[] args) {23 ICalculator calculator = Mockito.mock(ICalculator.class);24 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);25 System.out.println(calculator.add(10, 20));26 }27}28import org.mockito.ArgumentMatchers;29import org.mockito.Mockito;30public class Main {31 public static void main(String[] args) {32 ICalculator calculator = Mockito.mock(ICalculator.class);33 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);34 System.out.println(calculator.add(10, 20));35 }36}37import org.mockito.ArgumentMatchers;38import org.mockito.Mockito;39public class Main {40 public static void main(String[] args) {41 ICalculator calculator = Mockito.mock(ICalculator.class);42 Mockito.when(calculator.add(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(10);

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import org.mockito.AdditionalMatchers;2import org.mockito.ArgumentMatcher;3import org.mockito.Mockito;4import java.util.List;5import static org.mockito.Mockito.*;6public class MockitoTest {7 List mockedList = mock(List.class);8 mockedList.add("one");9 mockedList.clear();10 verify(mockedList).add("one");11 verify(mockedList).clear();12}13import org.mockito.AdditionalMatchers;14import org.mockito.ArgumentMatcher;15import org.mockito.Mockito;16import java.util.List;17import static org.mockito.Mockito.*;18public class MockitoTest {19 List mockedList = mock(List.class);20 mockedList.add("one");21 mockedList.clear();22 verify(mockedList).add("one");23 verify(mockedList).clear();24}25import org.mockito.AdditionalMatchers;26import org.mockito.ArgumentMatcher;27import org.mockito.Mockito;28import java.util.List;29import static org.mockito.Mockito.*;30public class MockitoTest {31 List mockedList = mock(List.class);32 mockedList.add("one");33 mockedList.clear();34 verify(mockedList).add("one");35 verify(mockedList).clear();36}37import org.mockito.AdditionalMatchers;38import org.mockito.ArgumentMatcher;39import org.mockito.Mockito;40import java.util.List;41import static org.mockito.Mockito.*;42public class MockitoTest {43 List mockedList = mock(List.class);44 mockedList.add("one");45 mockedList.clear();46 verify(mockedList).add("one");47 verify(mockedList).clear();48}49import org.mockito.AdditionalMatchers;50import org.mockito.ArgumentMatcher;51import org.mockito.Mockito;52import java.util.List;53import static org.mockito.Mockito.*;54public class MockitoTest {55 List mockedList = mock(List.class);56 mockedList.add("one");57 mockedList.clear();58 verify(mockedList

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import org.mockito.ArgumentMatcher;2import org.mockito.AdditionalMatchers;3import java.util.List;4import java.util.ArrayList;5import java.util.Arrays;6import static org.mockito.Mockito.*;7public class AdditionalMatchersExample {8 public static void main(String[] args) {9 List<String> list = new ArrayList<String>();10 List<String> mockList = mock(List.class);11 when(mockList.addAll(AdditionalMatchers.or(AdditionalMatchers.<String>notNull(), AdditionalMatchers.<String>notNull()))).thenReturn(true);12 mockList.addAll(Arrays.asList("one","two"));13 verify(mockList).addAll(Arrays.asList("one","two"));14 }15}

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import java.util.*;2import org.junit.*;3import static org.junit.Assert.*;4import static org.mockito.Mockito.*;5import static org.mockito.AdditionalMatchers.*;6{7 public static void main(String[] args) {8 TestClass test = new TestClass();9 test.test();10 }11 public void test() {12 List<String> mockedList = mock(List.class);13 when(mockedList.get(0)).thenReturn("first");14 when(mockedList.get(1)).thenReturn("second");15 when(mockedList.get(2)).thenReturn("third");16 when(mockedList.get(anyInt())).thenReturn("other");17 System.out.println(mockedList.get(0));18 System.out.println(mockedList.get(1));19 System.out.println(mockedList.get(2));20 System.out.println(mockedList.get(3));21 System.out.println(mockedList.get(4));22 }23}

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 methods in AdditionalMatchers

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful