How to use AdditionalMatchers method of org.mockito.AdditionalMatchers class

Best Mockito code snippet using org.mockito.AdditionalMatchers.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:ConversionTests.java Github

copy

Full Screen

...19import com.physphil.android.unitconverterultimate.presenters.ConversionView;20import com.physphil.android.unitconverterultimate.util.Conversions;21import org.junit.Before;22import org.junit.Test;23import org.mockito.AdditionalMatchers;24import org.mockito.Mock;25import org.mockito.MockitoAnnotations;26import static com.physphil.android.unitconverterultimate.models.Unit.*;27import static org.mockito.Matchers.eq;28import static org.mockito.Mockito.atLeastOnce;29import static org.mockito.Mockito.verify;30/**31 * JUnit tests for unit conversions32 * Created by pshadlyn on 8/10/2015.33 */34public class ConversionTests35{36 @Mock37 ConversionView view;38 private final double DELTA_4 = 0.0001;39 private final double DELTA_6 = 0.000001;40 private final double DELTA_7 = 0.0000001;41 private final double DELTA_9 = 0.000000001;42 private final double DELTA_10 = 0.0000000001;43 private Conversions mConversions;44 private ConversionPresenter mPresenter;45 @Before46 public void setup()47 {48 MockitoAnnotations.initMocks(this);49 mConversions = Conversions.getInstance();50 mPresenter = new ConversionPresenter(view);51 }52 @Test53 public void testArea()54 {55 Conversion area = mConversions.getById(Conversion.AREA);56 // Test each fromBase and toBase value57 mPresenter.convert(5.5, area.getUnitById(SQ_KILOMETRES), area.getUnitById(SQ_METRES));58 verify(view, atLeastOnce()).showResult(eq(5500000.0));59 mPresenter.convert(5.5, area.getUnitById(SQ_METRES), area.getUnitById(SQ_CENTIMETRES));60 verify(view, atLeastOnce()).showResult(eq(55000.0));61 mPresenter.convert(5.5, area.getUnitById(SQ_CENTIMETRES), area.getUnitById(HECTARE));62 verify(view, atLeastOnce()).showResult(eq(0.000000055));63 mPresenter.convert(5.5, area.getUnitById(HECTARE), area.getUnitById(SQ_MILE));64 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(0.0212, DELTA_4));65 mPresenter.convert(5.5, area.getUnitById(SQ_MILE), area.getUnitById(SQ_YARD));66 verify(view, atLeastOnce()).showResult(eq(17036800.0));67 mPresenter.convert(5.5, area.getUnitById(SQ_YARD), area.getUnitById(SQ_FOOT));68 verify(view, atLeastOnce()).showResult(eq(49.5));69 mPresenter.convert(5.5, area.getUnitById(SQ_FOOT), area.getUnitById(SQ_INCH));70 verify(view, atLeastOnce()).showResult(eq(792.0));71 mPresenter.convert(5.5, area.getUnitById(SQ_INCH), area.getUnitById(ACRE));72 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(0.0000008768, DELTA_10));73 mPresenter.convert(5.5, area.getUnitById(ACRE), area.getUnitById(SQ_KILOMETRES));74 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(0.0223, DELTA_4));75 }76 @Test77 public void testStorage()78 {79 Conversion storage = mConversions.getById(Conversion.STORAGE);80 mPresenter.convert(4.0, storage.getUnitById(BYTE), storage.getUnitById(BIT));81 verify(view, atLeastOnce()).showResult(eq(32.0));82 mPresenter.convert(4.0, storage.getUnitById(KILOBIT), storage.getUnitById(BYTE));83 verify(view, atLeastOnce()).showResult(eq(512.0));84 mPresenter.convert(4.0, storage.getUnitById(KILOBYTE), storage.getUnitById(KILOBIT));85 verify(view, atLeastOnce()).showResult(eq(32.0));86 mPresenter.convert(4.0, storage.getUnitById(MEGABIT), storage.getUnitById(KILOBYTE));87 verify(view, atLeastOnce()).showResult(eq(512.0));88 mPresenter.convert(4.0, storage.getUnitById(MEGABYTE), storage.getUnitById(MEGABIT));89 verify(view, atLeastOnce()).showResult(eq(32.0));90 mPresenter.convert(4.0, storage.getUnitById(GIGABIT), storage.getUnitById(MEGABYTE));91 verify(view, atLeastOnce()).showResult(eq(512.0));92 mPresenter.convert(4.0, storage.getUnitById(GIGABYTE), storage.getUnitById(GIGABIT));93 verify(view, atLeastOnce()).showResult(eq(32.0));94 mPresenter.convert(4.0, storage.getUnitById(TERABIT), storage.getUnitById(GIGABYTE));95 verify(view, atLeastOnce()).showResult(eq(512.0));96 mPresenter.convert(4.0, storage.getUnitById(TERABIT), storage.getUnitById(TERABYTE));97 verify(view, atLeastOnce()).showResult(eq(0.5));98 mPresenter.convert(4.0, storage.getUnitById(BIT), storage.getUnitById(BYTE));99 verify(view, atLeastOnce()).showResult(eq(0.5));100 mPresenter.convert(1.0, storage.getUnitById(GIGABYTE), storage.getUnitById(MEGABYTE));101 verify(view, atLeastOnce()).showResult(eq(1024.0));102 }103 104 @Test105 public void testEnergy()106 {107 Conversion energy = mConversions.getById(Conversion.ENERGY);108 109 mPresenter.convert(5.5, energy.getUnitById(JOULE), energy.getUnitById(KILOJOULE));110 verify(view).showResult(eq(0.0055));111 mPresenter.convert(5.5, energy.getUnitById(KILOJOULE), energy.getUnitById(CALORIE));112 verify(view).showResult(AdditionalMatchers.eq(1314.5315, DELTA_4));113 mPresenter.convert(5.5, energy.getUnitById(CALORIE), energy.getUnitById(KILOCALORIE));114 verify(view, atLeastOnce()).showResult(eq(0.0055));115 mPresenter.convert(5.5, energy.getUnitById(KILOCALORIE), energy.getUnitById(BTU));116 verify(view).showResult(AdditionalMatchers.eq(21.8112, DELTA_4));117 mPresenter.convert(5.5, energy.getUnitById(BTU), energy.getUnitById(FT_LBF));118 verify(view).showResult(AdditionalMatchers.eq(4279.9309, DELTA_4));119 mPresenter.convert(5.5, energy.getUnitById(FT_LBF), energy.getUnitById(IN_LBF));120 verify(view).showResult(AdditionalMatchers.eq(66.0000000161, DELTA_10));121 mPresenter.convert(5555555.0, energy.getUnitById(IN_LBF), energy.getUnitById(KILOWATT_HOUR));122 verify(view).showResult(AdditionalMatchers.eq(0.1744, DELTA_4));123 mPresenter.convert(5.5, energy.getUnitById(KILOWATT_HOUR), energy.getUnitById(JOULE));124 verify(view).showResult(eq(19800000.0));125 }126 @Test127 public void testFuelConsumption()128 {129 Conversion fuel = mConversions.getById(Conversion.FUEL);130 mPresenter.convertFuelValue(5.5, fuel.getUnitById(MPG_US), fuel.getUnitById(MPG_UK));131 verify(view).showResult(AdditionalMatchers.eq(6.6052245905, DELTA_10));132 mPresenter.convertFuelValue(5.5, fuel.getUnitById(MPG_UK), fuel.getUnitById(L_100K));133 verify(view).showResult(AdditionalMatchers.eq(51.3601699525, DELTA_10));134 mPresenter.convertFuelValue(5.5, fuel.getUnitById(L_100K), fuel.getUnitById(KM_L));135 verify(view).showResult(AdditionalMatchers.eq(18.1818180813, DELTA_10));136 mPresenter.convertFuelValue(5.5, fuel.getUnitById(KM_L), fuel.getUnitById(MILES_L));137 verify(view).showResult(AdditionalMatchers.eq(3.4175415522, DELTA_10));138 mPresenter.convertFuelValue(5.5, fuel.getUnitById(MILES_L), fuel.getUnitById(MPG_US));139 verify(view).showResult(AdditionalMatchers.eq(20.8197649, DELTA_10));140 mPresenter.convertFuelValue(0, fuel.getUnitById(L_100K), fuel.getUnitById(MPG_UK));141 verify(view, atLeastOnce()).showResult(0.0);142 mPresenter.convertFuelValue(0, fuel.getUnitById(MPG_UK), fuel.getUnitById(L_100K));143 verify(view, atLeastOnce()).showResult(0.0);144 }145 @Test146 public void testLength()147 {148 Conversion length = mConversions.getById(Conversion.LENGTH);149 mPresenter.convert(5.5, length.getUnitById(KILOMETRE), length.getUnitById(MILE));150 verify(view).showResult(AdditionalMatchers.eq(3.4175415573, DELTA_10));151 mPresenter.convert(5.5, length.getUnitById(MILE), length.getUnitById(METRE));152 verify(view).showResult(eq(8851.392));153 mPresenter.convert(5.5, length.getUnitById(METRE), length.getUnitById(CENTIMETRE));154 verify(view).showResult(eq(550.0));155 mPresenter.convert(5.5, length.getUnitById(CENTIMETRE), length.getUnitById(MILLIMETRE));156 verify(view).showResult(eq(55.0));157 mPresenter.convert(5.5, length.getUnitById(MILLIMETRE), length.getUnitById(MICROMETRE));158 verify(view).showResult(eq(5500.0));159 mPresenter.convert(5.5, length.getUnitById(MICROMETRE), length.getUnitById(NANOMETRE));160 verify(view, atLeastOnce()).showResult(eq(5500.0));161 mPresenter.convert(5558, length.getUnitById(NANOMETRE), length.getUnitById(YARD));162 verify(view).showResult(AdditionalMatchers.eq(0.0000060783, DELTA_10));163 mPresenter.convert(5.5, length.getUnitById(YARD), length.getUnitById(FEET));164 verify(view).showResult(eq(16.5));165 mPresenter.convert(5.5, length.getUnitById(FEET), length.getUnitById(INCH));166 verify(view).showResult(AdditionalMatchers.eq(66.0, DELTA_10));167 mPresenter.convert(5.5, length.getUnitById(MILLIMETRE), length.getUnitById(MICROMETRE));168 verify(view, atLeastOnce()).showResult(eq(5500.0));169 mPresenter.convert(5.5, length.getUnitById(INCH), length.getUnitById(NAUTICAL_MILE));170 verify(view).showResult(AdditionalMatchers.eq(0.000075432, DELTA_10));171 mPresenter.convert(5.5, length.getUnitById(NAUTICAL_MILE), length.getUnitById(FURLONG));172 verify(view).showResult(AdditionalMatchers.eq(50.634295713, DELTA_10));173 mPresenter.convert(123456789.0, length.getUnitById(FURLONG), length.getUnitById(LIGHT_YEAR));174 verify(view).showResult(AdditionalMatchers.eq(0.0000026251, DELTA_10));175 mPresenter.convert(5.5, length.getUnitById(LIGHT_YEAR), length.getUnitById(KILOMETRE));176 verify(view).showResult(eq(52034017599194.4));177 }178 @Test179 public void testMass()180 {181 Conversion mass = mConversions.getById(Conversion.MASS);182 mPresenter.convert(5.5, mass.getUnitById(KILOGRAM), mass.getUnitById(POUND));183 verify(view).showResult(AdditionalMatchers.eq(12.1254244202, DELTA_10));184 mPresenter.convert(5.5, mass.getUnitById(POUND), mass.getUnitById(GRAM));185 verify(view).showResult(AdditionalMatchers.eq(2494.758035, DELTA_6));186 mPresenter.convert(5.5, mass.getUnitById(GRAM), mass.getUnitById(MILLIGRAM));187 verify(view).showResult(eq(5500.0));188 mPresenter.convert(5.5, mass.getUnitById(MILLIGRAM), mass.getUnitById(OUNCE));189 verify(view).showResult(AdditionalMatchers.eq(0.0001940068, DELTA_10));190 mPresenter.convert(5.5, mass.getUnitById(OUNCE), mass.getUnitById(GRAIN));191 verify(view).showResult(eq(2406.25));192 mPresenter.convert(5.5, mass.getUnitById(GRAIN), mass.getUnitById(STONE));193 verify(view).showResult(AdditionalMatchers.eq(0.0000561224, DELTA_10));194 mPresenter.convert(5.5, mass.getUnitById(STONE), mass.getUnitById(METRIC_TON));195 verify(view).showResult(AdditionalMatchers.eq(0.0349266125, DELTA_10));196 mPresenter.convert(5.5, mass.getUnitById(METRIC_TON), mass.getUnitById(SHORT_TON));197 verify(view).showResult(AdditionalMatchers.eq(6.0627122101, DELTA_10));198 mPresenter.convert(5.5, mass.getUnitById(SHORT_TON), mass.getUnitById(LONG_TON));199 verify(view).showResult(AdditionalMatchers.eq(4.9107142857, DELTA_10));200 mPresenter.convert(5.5, mass.getUnitById(LONG_TON), mass.getUnitById(KILOGRAM));201 verify(view).showResult(AdditionalMatchers.eq(5588.2579984, DELTA_7));202 }203 @Test204 public void testPower()205 {206 Conversion power = mConversions.getById(Conversion.POWER);207 mPresenter.convert(5.5, power.getUnitById(WATT), power.getUnitById(KILOWATT));208 verify(view).showResult(eq(0.0055));209 mPresenter.convert(5.5, power.getUnitById(KILOWATT), power.getUnitById(MEGAWATT));210 verify(view, atLeastOnce()).showResult(eq(0.0055));211 mPresenter.convert(5.5, power.getUnitById(MEGAWATT), power.getUnitById(HP));212 verify(view).showResult(AdditionalMatchers.eq(7477.9188951715, DELTA_10));213 mPresenter.convert(5.5, power.getUnitById(HP), power.getUnitById(HP_UK));214 verify(view).showResult(AdditionalMatchers.eq(5.4247603884, DELTA_10));215 mPresenter.convert(5.5, power.getUnitById(HP_UK), power.getUnitById(FT_LBF_S));216 verify(view).showResult(eq(3025.0));217 mPresenter.convert(5.5, power.getUnitById(FT_LBF_S), power.getUnitById(CALORIE_S));218 verify(view).showResult(AdditionalMatchers.eq(1.7810735444, DELTA_10));219 mPresenter.convert(5.5, power.getUnitById(CALORIE_S), power.getUnitById(BTU_S));220 verify(view).showResult(AdditionalMatchers.eq(0.021825764, DELTA_9));221 mPresenter.convert(5.5, power.getUnitById(BTU_S), power.getUnitById(KVA));222 verify(view).showResult(AdditionalMatchers.eq(5.8028071894, DELTA_10));223 mPresenter.convert(5.5, power.getUnitById(KVA), power.getUnitById(WATT));224 verify(view).showResult(eq(5500.0));225 }226 @Test227 public void testPressure()228 {229 Conversion pressure = mConversions.getById(Conversion.PRESSURE);230 mPresenter.convert(5.5, pressure.getUnitById(MEGAPASCAL), pressure.getUnitById(KILOPASCAL));231 verify(view).showResult(eq(5500.0));232 mPresenter.convert(5.5, pressure.getUnitById(KILOPASCAL), pressure.getUnitById(PASCAL));233 verify(view, atLeastOnce()).showResult(eq(5500.0));234 mPresenter.convert(5.5, pressure.getUnitById(PASCAL), pressure.getUnitById(BAR));235 verify(view).showResult(eq(0.000055));236 mPresenter.convert(5.5, pressure.getUnitById(BAR), pressure.getUnitById(PSI));237 verify(view).showResult(AdditionalMatchers.eq(79.7707557516, DELTA_10));238 mPresenter.convert(5.5, pressure.getUnitById(PSI), pressure.getUnitById(PSF));239 verify(view).showResult(eq(792.0));240 mPresenter.convert(5.5, pressure.getUnitById(PSF), pressure.getUnitById(ATMOSPHERE));241 verify(view).showResult(AdditionalMatchers.eq(0.0025989778, DELTA_10));242 mPresenter.convert(5.5, pressure.getUnitById(ATMOSPHERE), pressure.getUnitById(MMHG));243 verify(view).showResult(AdditionalMatchers.eq(4179.9994044909, DELTA_10));244 mPresenter.convert(5.5, pressure.getUnitById(MMHG), pressure.getUnitById(TORR));245 verify(view).showResult(AdditionalMatchers.eq(5.5000007836, DELTA_10));246 mPresenter.convert(5.5, pressure.getUnitById(TORR), pressure.getUnitById(TECHNICAL_ATMOSPHERE));247 verify(view).showResult(AdditionalMatchers.eq(0.007477303934736015598438, DELTA_10));248 mPresenter.convert(5.5, pressure.getUnitById(TECHNICAL_ATMOSPHERE), pressure.getUnitById(MEGAPASCAL));249 verify(view).showResult((0.53936575));250 }251 @Test252 public void testSpeed()253 {254 Conversion speed = mConversions.getById(Conversion.SPEED);255 mPresenter.convert(5.5, speed.getUnitById(KM_HR), speed.getUnitById(MPH));256 verify(view).showResult(AdditionalMatchers.eq(3.4175415573, DELTA_10));257 mPresenter.convert(5.5, speed.getUnitById(MPH), speed.getUnitById(M_S));258 verify(view).showResult(eq(2.45872));259 mPresenter.convert(5.5, speed.getUnitById(M_S), speed.getUnitById(FPS));260 verify(view).showResult(AdditionalMatchers.eq(18.0446194226, DELTA_10));261 mPresenter.convert(5.5, speed.getUnitById(FPS), speed.getUnitById(KNOT));262 verify(view).showResult(AdditionalMatchers.eq(3.2586609071, DELTA_10));263 mPresenter.convert(5.5, speed.getUnitById(KNOT), speed.getUnitById(KM_HR));264 verify(view).showResult(AdditionalMatchers.eq(10.1860, DELTA_4));265 }266 @Test267 public void testTemperature()268 {269 Conversion temp = mConversions.getById(Conversion.TEMPERATURE);270 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(CELSIUS), temp.getUnitById(FAHRENHEIT));271 verify(view).showResult(eq(41.9));272 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(FAHRENHEIT), temp.getUnitById(KELVIN));273 verify(view).showResult(AdditionalMatchers.eq(258.4277777778, DELTA_10));274 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(KELVIN), temp.getUnitById(RANKINE));275 verify(view).showResult(eq(9.9));276 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(RANKINE), temp.getUnitById(DELISLE));277 verify(view).showResult(AdditionalMatchers.eq(555.1416666667, DELTA_10));278 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(DELISLE), temp.getUnitById(NEWTON));279 verify(view).showResult(eq(31.79));280 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(NEWTON), temp.getUnitById(REAUMUR));281 verify(view).showResult(AdditionalMatchers.eq(13.3333333333, DELTA_10));282 mPresenter.convertTemperatureValue(5.5, temp.getUnitById(REAUMUR), temp.getUnitById(ROMER));283 verify(view).showResult(eq(11.109375));284 mPresenter.convertTemperatureValue(10.0, temp.getUnitById(GAS_MARK), temp.getUnitById(CELSIUS));285 verify(view).showResult(eq(260.0));286 }287 @Test288 public void testTime()289 {290 Conversion time = mConversions.getById(Conversion.TIME);291 mPresenter.convert(5.0, time.getUnitById(YEAR), time.getUnitById(MONTH));292 verify(view).showResult(AdditionalMatchers.eq(59.9999994, DELTA_7));293 mPresenter.convert(5.0, time.getUnitById(MONTH), time.getUnitById(WEEK));294 verify(view).showResult(AdditionalMatchers.eq(21.7261904762, DELTA_10));295 mPresenter.convert(5.0, time.getUnitById(WEEK), time.getUnitById(DAY));296 verify(view).showResult(eq(35.0));297 mPresenter.convert(5.0, time.getUnitById(DAY), time.getUnitById(HOUR));298 verify(view).showResult(eq(120.0));299 mPresenter.convert(5.0, time.getUnitById(HOUR), time.getUnitById(MINUTE));300 verify(view).showResult(eq(300.0));301 mPresenter.convert(5.0, time.getUnitById(MINUTE), time.getUnitById(SECOND));302 verify(view, atLeastOnce()).showResult(eq(300.0));303 mPresenter.convert(5.0, time.getUnitById(SECOND), time.getUnitById(MILLISECOND));304 verify(view).showResult(eq(5000.0));305 mPresenter.convert(5.0, time.getUnitById(MILLISECOND), time.getUnitById(NANOSECOND));306 verify(view).showResult(eq(5000000.0));307 mPresenter.convert(5.0, time.getUnitById(NANOSECOND), time.getUnitById(MILLISECOND));308 verify(view).showResult(AdditionalMatchers.eq(0.000005, DELTA_7));309 mPresenter.convert(5.0, time.getUnitById(MONTH), time.getUnitById(YEAR));310 verify(view).showResult(AdditionalMatchers.eq(0.4166666667, DELTA_10));311 }312 @Test313 public void testTorque()314 {315 Conversion torque = mConversions.getById(Conversion.TORQUE);316 mPresenter.convert(5.5, torque.getUnitById(N_M), torque.getUnitById(FT_LBF));317 verify(view).showResult(AdditionalMatchers.eq(4.056591822, DELTA_10));318 mPresenter.convert(5.5, torque.getUnitById(FT_LBF), torque.getUnitById(IN_LBF));319 verify(view).showResult(AdditionalMatchers.eq(66.0000000161, DELTA_10));320 mPresenter.convert(5.5, torque.getUnitById(IN_LBF), torque.getUnitById(N_M));321 verify(view).showResult(AdditionalMatchers.eq(0.6214165597, DELTA_10));322 }323 @Test324 public void testVolume()325 {326 Conversion volume = mConversions.getById(Conversion.VOLUME);327 mPresenter.convert(5.5, volume.getUnitById(TEASPOON), volume.getUnitById(TABLESPOON));328 verify(view).showResult(AdditionalMatchers.eq(1.8333333334, DELTA_10));329 mPresenter.convert(5.5, volume.getUnitById(TABLESPOON), volume.getUnitById(CUP));330 verify(view).showResult(AdditionalMatchers.eq(0.34375, DELTA_6));331 mPresenter.convert(5.5, volume.getUnitById(CUP), volume.getUnitById(FLUID_OUNCE));332 verify(view).showResult(eq(44.0));333 mPresenter.convert(5.5, volume.getUnitById(FLUID_OUNCE), volume.getUnitById(FLUID_OUNCE_UK));334 verify(view).showResult(AdditionalMatchers.eq(5.7246350193, DELTA_10));335 mPresenter.convert(5.5, volume.getUnitById(FLUID_OUNCE_UK), volume.getUnitById(PINT));336 verify(view).showResult(AdditionalMatchers.eq(0.3302612295, DELTA_10));337 mPresenter.convert(5.5, volume.getUnitById(PINT), volume.getUnitById(PINT_UK));338 verify(view).showResult(AdditionalMatchers.eq(4.5797080155, DELTA_10));339 mPresenter.convert(5.5, volume.getUnitById(PINT_UK), volume.getUnitById(QUART));340 verify(view).showResult(AdditionalMatchers.eq(3.3026122951, DELTA_10));341 mPresenter.convert(5.5, volume.getUnitById(QUART), volume.getUnitById(QUART_UK));342 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(4.5797080155, DELTA_10));343 mPresenter.convert(5.5, volume.getUnitById(QUART_UK), volume.getUnitById(GALLON));344 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(1.6513061476, DELTA_10));345 mPresenter.convert(5.5, volume.getUnitById(GALLON), volume.getUnitById(GALLON_UK));346 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(4.5797080155, DELTA_10));347 mPresenter.convert(5.5, volume.getUnitById(GALLON_UK), volume.getUnitById(BARREL));348 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(0.2096896695, DELTA_10));349 mPresenter.convert(5.5, volume.getUnitById(BARREL), volume.getUnitById(BARREL_UK));350 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(4.0072445135, DELTA_10));351 mPresenter.convert(5.5, volume.getUnitById(BARREL_UK), volume.getUnitById(MILLILITRE));352 verify(view).showResult(AdditionalMatchers.eq(900125.82, DELTA_6));353 mPresenter.convert(5.5, volume.getUnitById(MILLILITRE), volume.getUnitById(LITRE));354 verify(view).showResult(eq(0.0055));355 mPresenter.convert(5.5, volume.getUnitById(LITRE), volume.getUnitById(CUBIC_CM));356 verify(view).showResult(eq(5500.0));357 mPresenter.convert(5.5, volume.getUnitById(CUBIC_CM), volume.getUnitById(CUBIC_M));358 verify(view).showResult(eq(0.0000055));359 mPresenter.convert(5.5, volume.getUnitById(CUBIC_M), volume.getUnitById(CUBIC_INCH));360 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(335630.592521028, DELTA_9));361 mPresenter.convert(5.5, volume.getUnitById(CUBIC_INCH), volume.getUnitById(CUBIC_FOOT));362 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(0.0031828704, DELTA_9));363 mPresenter.convert(5.5, volume.getUnitById(CUBIC_FOOT), volume.getUnitById(CUBIC_YARD));364 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(0.2037037007, DELTA_10));365 mPresenter.convert(5.5, volume.getUnitById(CUBIC_YARD), volume.getUnitById(TEASPOON));366 verify(view, atLeastOnce()).showResult(AdditionalMatchers.eq(853138.298312504, DELTA_9));367 }368}...

Full Screen

Full Screen

Source:DriveSubsystemTest.java Github

copy

Full Screen

...14import org.junit.jupiter.api.MethodOrderer;15import org.junit.jupiter.api.Order;16import org.junit.jupiter.api.Test;17import org.junit.jupiter.api.TestMethodOrder;18import org.mockito.AdditionalMatchers;19import org.mockito.ArgumentCaptor;20import org.mockito.ArgumentMatchers;21import edu.wpi.first.wpilibj.Counter;22import frc.robot.Constants;23@TestMethodOrder(MethodOrderer.OrderAnnotation.class)24public class DriveSubsystemTest {25 private final double DELTA = 2e-3;26 private final double ALT_DELTA = 3e-2;27 private DriveSubsystem m_driveSubsystem;28 private DriveSubsystem.Hardware m_drivetrainHardware;29 private WPI_TalonFX m_lMasterMotor;30 private WPI_TalonFX m_rMasterMotor;31 private WPI_TalonFX m_leftSlaveMotor;32 private WPI_TalonFX m_rightSlaveMotor;33 private Counter m_lidar;34 private AHRS m_navx;35 @BeforeEach36 public void setup() {37 // Create mock hardware devices38 m_lMasterMotor = mock(WPI_TalonFX.class);39 m_rMasterMotor = mock(WPI_TalonFX.class);40 m_leftSlaveMotor = mock(WPI_TalonFX.class);41 m_rightSlaveMotor = mock(WPI_TalonFX.class);42 m_lidar = mock(Counter.class);43 m_navx = mock(AHRS.class);44 // Create Hardware object using mock objects45 m_drivetrainHardware = new DriveSubsystem.Hardware(m_lMasterMotor, m_rMasterMotor, m_leftSlaveMotor, m_rightSlaveMotor, m_lidar, m_navx);46 // Create DriveSubsystem object47 m_driveSubsystem = new DriveSubsystem(m_drivetrainHardware, 48 Constants.DRIVE_kP,49 Constants.DRIVE_kD, 50 Constants.DRIVE_TURN_SCALAR,51 Constants.CONTROLLER_DEADBAND,52 Constants.DRIVE_ACCELERATION_LIMIT,53 Constants.DRIVE_TRACTION_CONTROL_CURVE,54 Constants.DRIVE_THROTTLE_INPUT_CURVE);55 }56 @AfterEach57 public void close() {58 m_driveSubsystem.close();59 m_driveSubsystem = null;60 }61 @Test62 @Order(1)63 @DisplayName("Test if robot can move forward using PID drive")64 public void forward() {65 // Hardcode NAVX sensor return values for angle, and velocityY66 when(m_navx.getAngle()).thenReturn(0.0);67 when(m_navx.getVelocityY()).thenReturn((float)4.106);68 // Fill up velocity moving average buffer by calling periodic69 for (int i = 0; i < 6; i++) { m_driveSubsystem.periodic(); }70 // Try to drive forward71 m_driveSubsystem.teleopPID(1.0, 0.0);72 // Verify that left and right motors are being driven with expected values73 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(1.0, DELTA), 74 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));75 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(1.0, DELTA), 76 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));77 }78 @Test79 @Order(2)80 @DisplayName("Test if robot can move in reverse using PID drive")81 public void reverse() {82 // Hardcode NAVX sensor return values for angle, and velocityY83 when(m_navx.getAngle()).thenReturn(0.0);84 when(m_navx.getVelocityY()).thenReturn((float)-4.106);85 // Fill up velocity moving average buffer by calling periodic86 for (int i = 0; i < 6; i++) { m_driveSubsystem.periodic(); }87 // Try to drive in reverse88 m_driveSubsystem.teleopPID(-1.0, 0.0);89 // Verify that left and right motors are being driven with expected values90 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(-1.0, DELTA), 91 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));92 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(-1.0, DELTA), 93 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));94 }95 @Test96 @Order(3)97 @DisplayName("Test if robot can reverse direction using PID drive")98 public void reverseDirection() {99 // Initial velocity100 double velocity = 2.053;101 when(m_navx.getVelocityY()).thenReturn((float)velocity);102 // Argument capture objects103 ArgumentCaptor<Double> lMotorOutputs = ArgumentCaptor.forClass(Double.class);104 ArgumentCaptor<Double> rMotorOutputs = ArgumentCaptor.forClass(Double.class);105 // Hardcode NAVX sensor value for angle106 when(m_navx.getAngle()).thenReturn(0.0);107 // Fill up velocity moving average buffer by calling periodic108 for (int i = 0; i < 6; i++) { m_driveSubsystem.periodic(); }109 // Simulate NAVX sensor deceleration110 for (int i = 0; i < 75; i++) {111 velocity = (velocity <= -2.053) ?112 -2.053 :113 velocity - 0.05;114 when(m_navx.getVelocityY()).thenReturn((float)velocity);115 // Try to reverse direction116 m_driveSubsystem.teleopPID(-0.5, 0.0);117 m_driveSubsystem.periodic();118 }119 // Verify that left and right motors are being driven and capture output120 verify(m_lMasterMotor, times(75)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), lMotorOutputs.capture(), 121 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));122 verify(m_rMasterMotor, times(75)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), rMotorOutputs.capture(), 123 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));124 // Check that last motor output value was as expected125 double lMotorOutput = lMotorOutputs.getAllValues().get(lMotorOutputs.getAllValues().size() - 1);126 double rMotorOutput = rMotorOutputs.getAllValues().get(rMotorOutputs.getAllValues().size() - 1);127 assertTrue(Math.abs(-0.5 - lMotorOutput) <= ALT_DELTA);128 assertTrue(Math.abs(-0.5 - rMotorOutput) <= ALT_DELTA);129 }130 @Test131 @Order(4)132 @DisplayName("Test if robot can stop using PID drive")133 public void stop() {134 // Hardcode NAVX sensor return value for angle135 when(m_navx.getAngle()).thenReturn(0.0);136 // Try to stop137 m_driveSubsystem.teleopPID(0.0, 0.0);138 // Verify that left and right motors are being driven with expected values139 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 140 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));141 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 142 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));143 }144 @Test145 @Order(5)146 @DisplayName("Test if robot ignores small turn input values under threshold")147 public void ignoreSmallTurnInput() {148 // Hardcode NAVX sensor return values for angle, velocityY149 when(m_navx.getAngle()).thenReturn(0.0);150 when(m_navx.getVelocityY()).thenReturn((float)4.106);151 // Fill up velocity moving average buffer by calling periodic152 for (int i = 0; i < 6; i++) { m_driveSubsystem.periodic(); }153 // Try to drive with small turn value154 m_driveSubsystem.teleopPID(1.0, 0.001);155 // Verify that left and right motors are being driven with expected values156 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(1.0, DELTA), 157 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));158 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(1.0, DELTA), 159 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));160 }161 @Test162 @Order(6)163 @DisplayName("Test if robot can turn left using PID drive")164 public void turningLeft() {165 // Hardcode NAVX sensor return value for angle166 when(m_navx.getAngle()).thenReturn(0.0);167 // Try to turn left168 m_driveSubsystem.teleopPID(0.0, -1.0);169 // Verify that left and right motors are being driven with expected values170 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 171 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.gt(0.0));172 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 173 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.lt(0.0));174 }175 @Test176 @Order(7)177 @DisplayName("Test if robot can turn right using PID drive")178 public void turningRight() {179 // Hardcode NAVX sensor return value for angle180 when(m_navx.getAngle()).thenReturn(0.0);181 // Try to turn right182 m_driveSubsystem.teleopPID(0.0, 1.0);183 // Verify that left and right motors are being driven with expected values184 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 185 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.lt(0.0));186 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(0.0, DELTA), 187 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.gt(0.0));188 }189 @Test190 @Order(8)191 @DisplayName("Test if robot will limit wheel slip")192 public void tractionControl() {193 // Hardcode NAVX sensor values for angle, and velocityY194 when(m_navx.getAngle()).thenReturn(0.0);195 when(m_navx.getVelocityY()).thenReturn((float)0.0);196 // Fill up velocity moving average buffer by calling periodic197 for (int i = 0; i < 6; i++) { m_driveSubsystem.periodic(); }198 // Enable traction control199 m_driveSubsystem.enableTractionControl();200 201 // Try to move forward202 m_driveSubsystem.teleopPID(1.0, 0.0);203 // Verify that left and right motors are being driven with expected values204 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.and(AdditionalMatchers.lt(0.13), AdditionalMatchers.gt(0.0)), 205 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));206 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.and(AdditionalMatchers.lt(0.13), AdditionalMatchers.gt(0.0)), 207 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));208 }209 @Test210 @Order(9)211 @DisplayName("Test if robot can toggle traction control")212 public void toggleTractionControl() {213 // Hardcode NAVX sensor values for angle, and velocityY214 when(m_navx.getAngle()).thenReturn(0.0);215 when(m_navx.getVelocityY()).thenReturn((float)0.0);216 // Fill up velocity moving average buffer by calling periodic217 for (int i = 0; i < 6; i++) { m_driveSubsystem.periodic(); }218 // Enable traction control219 m_driveSubsystem.enableTractionControl();220 // Toggle off traction control221 m_driveSubsystem.toggleTractionControl();222 // Try to drive forward223 m_driveSubsystem.teleopPID(1.0, 0.0);224 // Verify that left and right motors are being driven with expected values225 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(1.0, DELTA), 226 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));227 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.eq(1.0, DELTA), 228 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));229 // Toggle on traction control230 m_driveSubsystem.toggleTractionControl();231 // Try to drive forward232 m_driveSubsystem.teleopPID(1.0, 0.0);233 // Verify that left and right motors are being driven with expected values234 verify(m_lMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.and(AdditionalMatchers.lt(0.13), AdditionalMatchers.gt(0.0)), 235 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));236 verify(m_rMasterMotor, times(1)).set(ArgumentMatchers.eq(ControlMode.PercentOutput), AdditionalMatchers.and(AdditionalMatchers.lt(0.13), AdditionalMatchers.gt(0.0)), 237 ArgumentMatchers.eq(DemandType.ArbitraryFeedForward), AdditionalMatchers.eq(0.0, DELTA));238 }239}...

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:TrigonometryMocks.java Github

copy

Full Screen

1package ilia.nemankov.trigonometry;2import org.mockito.AdditionalMatchers;3import static java.lang.Double.NaN;4import static org.mockito.Mockito.mock;5import static org.mockito.Mockito.when;6public class TrigonometryMocks {7 public static Cos getCosMock() {8 Cos cos = mock(Cos.class);9 when(cos.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(1.0);10 when(cos.calculate(AdditionalMatchers.eq(0.5235988, 0.1))).thenReturn(0.8660254);11 when(cos.calculate(AdditionalMatchers.eq(0.7853982, 0.1))).thenReturn(0.7071068);12 when(cos.calculate(AdditionalMatchers.eq(1.0471976, 0.1))).thenReturn(0.5);13 when(cos.calculate(AdditionalMatchers.eq(1.5707963, 0.1))).thenReturn(0.0);14 when(cos.calculate(AdditionalMatchers.eq(2.0943951, 0.1))).thenReturn(-0.5);15 when(cos.calculate(AdditionalMatchers.eq(2.3561945, 0.1))).thenReturn(-0.7071068);16 when(cos.calculate(AdditionalMatchers.eq(2.6179939, 0.1))).thenReturn(-0.8660254);17 when(cos.calculate(AdditionalMatchers.eq(3.1415927, 0.1))).thenReturn(-1.0);18 when(cos.calculate(AdditionalMatchers.eq(3.6651914, 0.1))).thenReturn(0.8660254);19 when(cos.calculate(AdditionalMatchers.eq(3.9269908, 0.1))).thenReturn(0.7071068);20 when(cos.calculate(AdditionalMatchers.eq(4.1887902, 0.1))).thenReturn(0.5);21 when(cos.calculate(AdditionalMatchers.eq(4.7123890, 0.1))).thenReturn(0.0);22 when(cos.calculate(AdditionalMatchers.eq(5.2359878, 0.1))).thenReturn(0.5);23 when(cos.calculate(AdditionalMatchers.eq(5.4977871, 0.1))).thenReturn(0.7071068);24 when(cos.calculate(AdditionalMatchers.eq(5.7595865, 0.1))).thenReturn(0.8660254);25 when(cos.calculate(AdditionalMatchers.eq(6.2831853, 0.1))).thenReturn(1.0);26 when(cos.calculate(AdditionalMatchers.eq(-0.5235988, 0.1))).thenReturn(0.8660254);27 when(cos.calculate(AdditionalMatchers.eq(-0.7853982, 0.1))).thenReturn(0.7071068);28 when(cos.calculate(AdditionalMatchers.eq(-1.0471976, 0.1))).thenReturn(0.5);29 when(cos.calculate(AdditionalMatchers.eq(-1.5707963, 0.1))).thenReturn(0.0);30 when(cos.calculate(AdditionalMatchers.eq(-2.0943951, 0.1))).thenReturn(-0.5);31 when(cos.calculate(AdditionalMatchers.eq(-2.3561945, 0.1))).thenReturn(-0.7071068);32 when(cos.calculate(AdditionalMatchers.eq(-2.6179939, 0.1))).thenReturn(-0.8660254);33 when(cos.calculate(AdditionalMatchers.eq(-3.1415927, 0.1))).thenReturn(-1.0);34 when(cos.calculate(AdditionalMatchers.eq(-3.6651914, 0.1))).thenReturn(0.8660254);35 when(cos.calculate(AdditionalMatchers.eq(-3.9269908, 0.1))).thenReturn(0.7071068);36 when(cos.calculate(AdditionalMatchers.eq(-4.1887902, 0.1))).thenReturn(0.5);37 when(cos.calculate(AdditionalMatchers.eq(-4.7123890, 0.1))).thenReturn(0.0);38 when(cos.calculate(AdditionalMatchers.eq(-5.2359878, 0.1))).thenReturn(0.5);39 when(cos.calculate(AdditionalMatchers.eq(-5.4977871, 0.1))).thenReturn(0.7071068);40 when(cos.calculate(AdditionalMatchers.eq(-5.7595865, 0.1))).thenReturn(0.8660254);41 when(cos.calculate(AdditionalMatchers.eq(-6.2831853, 0.1))).thenReturn(1.0);42 when(cos.calculate(Double.POSITIVE_INFINITY)).thenReturn(NaN);43 when(cos.calculate(Double.NEGATIVE_INFINITY)).thenReturn(NaN);44 when(cos.calculate(NaN)).thenReturn(NaN);45 return cos;46 }47 public static Csc getCscMock() {48 Csc csc = mock(Csc.class);49 when(csc.calculate(AdditionalMatchers.eq(0.0, 0.1))).thenReturn(NaN);50 when(csc.calculate(AdditionalMatchers.eq(0.5235988, 0.1))).thenReturn(2.0);51 when(csc.calculate(AdditionalMatchers.eq(0.7853982, 0.1))).thenReturn(1.4142136);52 when(csc.calculate(AdditionalMatchers.eq(1.0471976, 0.1))).thenReturn(1.1547005);53 when(csc.calculate(AdditionalMatchers.eq(1.5707963, 0.1))).thenReturn(1.0);54 when(csc.calculate(AdditionalMatchers.eq(2.0943951, 0.1))).thenReturn(1.1547005);55 when(csc.calculate(AdditionalMatchers.eq(2.3561945, 0.1))).thenReturn(1.4142136);56 when(csc.calculate(AdditionalMatchers.eq(2.6179939, 0.1))).thenReturn(2.0);57 when(csc.calculate(AdditionalMatchers.eq(3.1415927, 0.1))).thenReturn(NaN);58 when(csc.calculate(AdditionalMatchers.eq(3.6651914, 0.1))).thenReturn(-2.0);59 when(csc.calculate(AdditionalMatchers.eq(3.9269908, 0.1))).thenReturn(-1.4142136);60 when(csc.calculate(AdditionalMatchers.eq(4.1887902, 0.1))).thenReturn(-1.1547005);61 when(csc.calculate(AdditionalMatchers.eq(4.7123890, 0.1))).thenReturn(-1.0);62 when(csc.calculate(AdditionalMatchers.eq(5.2359878, 0.1))).thenReturn(-1.1547005);63 when(csc.calculate(AdditionalMatchers.eq(5.4977871, 0.1))).thenReturn(-1.4142136);64 when(csc.calculate(AdditionalMatchers.eq(5.7595865, 0.1))).thenReturn(-2.0);65 when(csc.calculate(AdditionalMatchers.eq(6.2831853, 0.1))).thenReturn(NaN);66 when(csc.calculate(AdditionalMatchers.eq(-0.5235988, 0.1))).thenReturn(-2.0);67 when(csc.calculate(AdditionalMatchers.eq(-0.7853982, 0.1))).thenReturn(-1.4142136);68 when(csc.calculate(AdditionalMatchers.eq(-1.0471976, 0.1))).thenReturn(-1.1547005);69 when(csc.calculate(AdditionalMatchers.eq(-1.5707963, 0.1))).thenReturn(-1.0);70 when(csc.calculate(AdditionalMatchers.eq(-2.0943951, 0.1))).thenReturn(-1.1547005);71 when(csc.calculate(AdditionalMatchers.eq(-2.3561945, 0.1))).thenReturn(-1.4142136);72 when(csc.calculate(AdditionalMatchers.eq(-2.6179939, 0.1))).thenReturn(-2.0);73 when(csc.calculate(AdditionalMatchers.eq(-3.1415927, 0.1))).thenReturn(NaN);74 when(csc.calculate(AdditionalMatchers.eq(-3.6651914, 0.1))).thenReturn(2.0);75 when(csc.calculate(AdditionalMatchers.eq(-3.9269908, 0.1))).thenReturn(1.4142136);76 when(csc.calculate(AdditionalMatchers.eq(-4.1887902, 0.1))).thenReturn(1.1547005);77 when(csc.calculate(AdditionalMatchers.eq(-4.7123890, 0.1))).thenReturn(1.0);78 when(csc.calculate(AdditionalMatchers.eq(-5.2359878, 0.1))).thenReturn(1.1547005);79 when(csc.calculate(AdditionalMatchers.eq(-5.4977871, 0.1))).thenReturn(1.4142136);80 when(csc.calculate(AdditionalMatchers.eq(-5.7595865, 0.1))).thenReturn(2.0);81 when(csc.calculate(AdditionalMatchers.eq(-6.2831853, 0.1))).thenReturn(NaN);82 return csc;83 }84}

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

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import org.mockito.AdditionalMatchers;2import org.mockito.ArgumentMatcher;3import org.mockito.Mockito;4import org.mockito.invocation.InvocationOnMock;5import org.mockito.stubbing.Answer;6import org.mockito.stubbing.OngoingStubbing;7import org.mockito.verification.VerificationMode;8import org.mockito.verification.VerificationWithTimeout;

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1public class MockitoTest {2 private List<String> list;3 public void setUp() {4 MockitoAnnotations.initMocks(this);5 }6 public void test() {7 Mockito.when(list.get(Mockito.anyInt())).thenReturn("first", "second");8 Mockito.when(list.contains(Mockito.anyString())).thenReturn(true);9 Mockito.when(list.contains(AdditionalMatchers.not(Mockito.contains("not contained")))).thenReturn(true);10 System.out.println(list.get(1));11 System.out.println(list.get(2));12 System.out.println(list.contains("some string"));13 System.out.println(list.contains("not contained"));14 }15}16public class MockitoTest {17 private List<String> list;18 public void setUp() {19 MockitoAnnotations.initMocks(this);20 }21 public void test() {22 Mockito.when(list.get(Mockito.anyInt())).thenReturn("first", "second");23 Mockito.when(list.contains(Mockito.anyString())).thenReturn(true);24 Mockito.when(list.contains(AdditionalMatchers.not(Mockito.contains("not contained")))).thenReturn(true);25 System.out.println(list.get(1));26 System.out.println(list.get(2));27 System.out.println(list.contains("some string"));28 System.out.println(list.contains("not contained"));29 }30}31public class MockitoTest {32 private List<String> list;33 public void setUp() {34 MockitoAnnotations.initMocks(this);35 }36 public void test() {37 Mockito.when(list.get(Mockito.anyInt())).thenReturn("first", "second");38 Mockito.when(list.contains(Mockito.anyString())).thenReturn(true);39 Mockito.when(list.contains(AdditionalMatchers.not(Mockito.contains("not contained")))).thenReturn(true);40 System.out.println(list.get(1));41 System.out.println(list.get(2));42 System.out.println(list.contains("some string"));43 System.out.println(list.contains("not contained"));44 }45}

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.mockito;2import static org.mockito.Matchers.anyString;3import static org.mockito.Matchers.argThat;4import static org.mockito.Mockito.mock;5import static org.mockito.Mockito.when;6import java.util.List;7import org.junit.Test;8public class MockitoAdditionalMatchersTest {9 public void testMockitoAdditionalMatchers() {10 List mockedList = mock(List.class);11 when(mockedList.get(argThat(AdditionalMatchers.contains("1")))).thenReturn("one");12 System.out.println(mockedList.get(1));13 }14}15package com.automationrhapsody.mockito;16import org.hamcrest.Description;17import org.hamcrest.Matcher;18import org.hamcrest.TypeSafeMatcher;19public class AdditionalMatchers {20 public static Matcher<Integer> contains(final String str) {21 return new TypeSafeMatcher<Integer>() {22 public boolean matchesSafely(Integer item) {23 return item.toString().contains(str);24 }25 public void describeTo(Description description) {26 description.appendText("contains string " + str);27 }28 };29 }30}

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1package com.ack.test;2import org.junit.Test;3import org.junit.runner.RunWith;4import org.mockito.AdditionalMatchers;5import org.mockito.Mock;6import org.mockito.runners.MockitoJUnitRunner;7import java.util.List;8import static org.mockito.Mockito.verify;9@RunWith(MockitoJUnitRunner.class)10public class MockitoAdditionalMatchersTest {11 private List mockedList;12 public void testMockitoAdditionalMatchers() {13 mockedList.add(1);14 mockedList.clear();15 verify(mockedList).add(AdditionalMatchers.gt(0));16 verify(mockedList).clear();17 }18}19package com.ack.test;20import org.junit.Test;21import org.junit.runner.RunWith;22import org.mockito.AdditionalMatchers;23import org.mockito.Mock;24import org.mockito.runners.MockitoJUnitRunner;25import java.util.List;26import static org.mockito.Mockito.verify;27@RunWith(MockitoJUnitRunner.class)28public class MockitoAdditionalMatchersTest {29 private List mockedList;30 public void testMockitoAdditionalMatchers() {31 mockedList.add(1);32 mockedList.clear();33 verify(mockedList).add(AdditionalMatchers.gt(0));34 verify(mockedList).clear();35 }36}37package com.ack.test;38import org.junit.Test;39import org.junit.runner.RunWith;40import org.mockito.AdditionalMatchers;41import org.mockito.Mock;42import org.mockito.runners.MockitoJUnitRunner;43import java.util.List;44import static org.mockito.Mockito.verify;45@RunWith(MockitoJUnitRunner.class)46public class MockitoAdditionalMatchersTest {47 private List mockedList;48 public void testMockitoAdditionalMatchers() {49 mockedList.add(1);50 mockedList.clear();51 verify(mockedList).add(AdditionalMatchers.gt(0));52 verify(mockedList).clear();53 }54}55package com.ack.test;56import org.junit.Test;57import org.junit.runner.RunWith;58import org.mockito.Additional

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import static org.mockito.Matchers.anyInt;2import static org.mockito.Matchers.anyString;3import static org.mockito.Mockito.mock;4import static org.mockito.Mockito.when;5import java.util.List;6import org.junit.Test;7public class MockitoAnyArgumentsTest {8 public void test() {9 List mockedList = mock(List.class);10 when(mockedList.get(anyInt())).thenReturn("element");11 when(mockedList.contains(anyString())).thenReturn(true);12 System.out.println(mockedList.get(999));13 verify(mockedList).get(anyInt());14 verify(mockedList).contains(argThat(s -> s.length() > 5));15 }16}17Related posts: Mockito – verify() method example Mockito – any() method example Mockito – anyString() method example Mockito – anyInt() method example Mockito – anyBoolean() method example Mockito – anyList() method example Mockito – anySet() method example Mockito – anyMap() method example Mockito – anyCollection() method example Mockito – anyObject() method example Mo

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1public class Test1 {2 public void test1() {3 List<String> mockedList = mock(List.class);4 when(mockedList.get(AdditionalMatchers.or(eq(0), eq(1)))).thenReturn("first", "second");5 assertEquals("first", mockedList.get(0));6 assertEquals("second", mockedList.get(1));7 assertEquals(null, mockedList.get(2));8 }9}10public class Test2 {11 public void test2() {12 List<String> mockedList = mock(List.class);13 when(mockedList.get(AdditionalMatchers.or(eq(0), eq(1)))).thenReturn("first", "second");14 assertEquals("first", mockedList.get(0));15 assertEquals("second", mockedList.get(1));16 assertEquals(null, mockedList.get(2));17 }18}19public class Test3 {20 public void test3() {21 List<String> mockedList = mock(List.class);22 when(mockedList.get(AdditionalMatchers.or(eq(0), eq(1)))).thenReturn("first", "second");23 assertEquals("first", mockedList.get(0));24 assertEquals("second", mockedList.get(1));25 assertEquals(null, mockedList.get(2));26 }27}28public class Test4 {29 public void test4() {30 List<String> mockedList = mock(List.class);31 when(mockedList.get(AdditionalMatchers.or(eq(0), eq(1)))).thenReturn("first", "second");32 assertEquals("first", mockedList.get(0));33 assertEquals("second", mockedList.get(1));34 assertEquals(null, mockedList.get(2));35 }36}

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import static org.mockito.Mockito.*;2import static org.mockito.AdditionalMatchers.*;3import static org.mockito.Matchers.*;4import org.mockito.*;5import org.mockito.stubbing.*;6import org.mockito.invocation.*;7import org.mockito.verification.*;8import org.mockito.exceptions.*;9import org.mockito.matchers.*;10import org.mockito.internal.*;11import org.mockito.internal.matchers.*;12import org.mockito.internal.verification.*;13import org.mockito.internal.invocation.*;14import org.mockito.internal.progress.*;15import org.mockito.internal.stubbing.*;16import org.mockito.internal.creation.*;17import org.mockito.internal.util.*;18import org.mockito.internal.configuration.*;19import org.mockito.internal.debugging.*;20import org.mockito.internal.exceptions.*;21import org.mockito.internal.listeners.*;22import org.mockito.internal.stubbing.defaultanswers.*;23import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;24import org.mockito.internal.stubbing.defaultanswers.ReturnsMocks;25import org.mockito.internal.stubbing.defaultanswers.ReturnsMoreEmptyValues;26import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls;27import org.mockito.internal.stubbing.defaultanswers.ReturnsSubclasses;28import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;29import org.mockito.internal.stubbing.defaultanswers.Returns;30import org.mockito.internal.stubbing.defaultanswers.ReturnsNull;31import org.mockito.internal.stubbing.defaultanswers.ReturnsArgAt;32import org.mockito.internal.stubbing.defaultanswers.ReturnsDefaultValues;33import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues;34import org.mockito.internal.stubbing.defaultanswers.ReturnsMocks;35import org.mockito.internal.stubbing.defaultanswers.ReturnsMoreEmptyValues;36import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls;37import org.mockito.internal.stubbing.defaultanswers.ReturnsSubclasses;38import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;39import org.mockito.internal.stubbing.defaultanswers.Returns;40import org.mockito.internal.stubbing.defaultanswers.ReturnsNull;41import org.mockito.internal.stubbing.defaultanswers.ReturnsArgAt;42import org.mockito.internal.stubbing.defaultanswers.ReturnsDefaultValues;43import org.mockito.internal.stubbing.answers.*;44import org.mockito.internal.stubbing.answers.DoesNothing;45import org.mockito.internal.stubbing.answers.Returns;46import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;47import org.mockito.internal.stubbing.answers.ReturnsEmptyValues;48import org.mockito.internal.stubbing.answers.ReturnsMocks;49import org.mockito.internal.stubbing.answers.Returns

Full Screen

Full Screen

AdditionalMatchers

Using AI Code Generation

copy

Full Screen

1import static org.mockito.AdditionalMatchers.gt;2import static org.mockito.Mockito.mock;3import static org.mockito.Mockito.verify;4public class GreaterThan {5 public static void main(String[] args) {6 List mockedList = mock(List.class);7 mockedList.add(1);8 verify(mockedList).add(gt(5));9 }10}11org.mockito.exceptions.verification.ArgumentsAreDifferent: Argument(s) are different! Wanted:12list.add(13);14-> at org.mockito.AdditionalMatchersTest.shouldVerifyUsingGreaterThan(AdditionalMatchersTest.java:64)15list.add(16);17-> at org.mockito.AdditionalMatchersTest.shouldVerifyUsingGreaterThan(AdditionalMatchersTest.java:64)18org.mockito.exceptions.verification.ArgumentsAreDifferent: Argument(s) are different! Wanted:19list.add(20);21-> at org.mockito.AdditionalMatchersTest.shouldVerifyUsingGreaterThan(AdditionalMatchersTest.java:64)22list.add(23);24-> at org.mockito.AdditionalMatchersTest.shouldVerifyUsingGreaterThan(AdditionalMatchersTest.java:64)

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 AdditionalMatchers

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful