1 17 package org.apache.servicemix.jbi.installation; 18 19 import org.easymock.ArgumentsMatcher; 20 import org.easymock.MockControl; 21 import org.easymock.internal.Range; 22 23 import java.lang.reflect.InvocationHandler ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Proxy ; 27 28 import junit.framework.AssertionFailedError; 29 30 public class ExtMockControl implements InvocationHandler { 31 32 private MockControl control; 33 private Class clazz; 34 private AssertionFailedError error; 35 private Object mock; 36 37 public ExtMockControl(MockControl control, Class clazz) { 38 this.control = control; 39 this.clazz = clazz; 40 } 41 42 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 43 try { 44 return method.invoke(control.getMock(), args); 45 } catch (InvocationTargetException e) { 46 if (e.getCause() instanceof AssertionFailedError && error == null) { 47 error = (AssertionFailedError) e.getCause(); 48 } 49 throw e; 50 } 51 } 52 53 public static ExtMockControl createControl(Class clazz) { 54 MockControl mock = MockControl.createControl(clazz); 55 return new ExtMockControl(mock, clazz); 56 } 57 58 61 public void expectAndDefaultReturn(boolean arg0, boolean arg1) { 62 control.expectAndDefaultReturn(arg0, arg1); 63 } 64 65 68 public void expectAndDefaultReturn(double arg0, double arg1) { 69 control.expectAndDefaultReturn(arg0, arg1); 70 } 71 72 75 public void expectAndDefaultReturn(float arg0, float arg1) { 76 control.expectAndDefaultReturn(arg0, arg1); 77 } 78 79 82 public void expectAndDefaultReturn(long arg0, long arg1) { 83 control.expectAndDefaultReturn(arg0, arg1); 84 } 85 86 89 public void expectAndDefaultReturn(Object arg0, Object arg1) { 90 control.expectAndDefaultReturn(arg0, arg1); 91 } 92 93 96 public void expectAndDefaultThrow(boolean arg0, Throwable arg1) { 97 control.expectAndDefaultThrow(arg0, arg1); 98 } 99 100 103 public void expectAndDefaultThrow(double arg0, Throwable arg1) { 104 control.expectAndDefaultThrow(arg0, arg1); 105 } 106 107 110 public void expectAndDefaultThrow(float arg0, Throwable arg1) { 111 control.expectAndDefaultThrow(arg0, arg1); 112 } 113 114 117 public void expectAndDefaultThrow(long arg0, Throwable arg1) { 118 control.expectAndDefaultThrow(arg0, arg1); 119 } 120 121 124 public void expectAndDefaultThrow(Object arg0, Throwable arg1) { 125 control.expectAndDefaultThrow(arg0, arg1); 126 } 127 128 131 public void expectAndReturn(boolean arg0, boolean arg1, int arg2, int arg3) { 132 control.expectAndReturn(arg0, arg1, arg2, arg3); 133 } 134 135 138 public void expectAndReturn(boolean arg0, boolean arg1, int arg2) { 139 control.expectAndReturn(arg0, arg1, arg2); 140 } 141 142 145 public void expectAndReturn(boolean arg0, boolean arg1, Range arg2) { 146 control.expectAndReturn(arg0, arg1, arg2); 147 } 148 149 152 public void expectAndReturn(boolean arg0, boolean arg1) { 153 control.expectAndReturn(arg0, arg1); 154 } 155 156 159 public void expectAndReturn(double arg0, double arg1, int arg2, int arg3) { 160 control.expectAndReturn(arg0, arg1, arg2, arg3); 161 } 162 163 166 public void expectAndReturn(double arg0, double arg1, int arg2) { 167 control.expectAndReturn(arg0, arg1, arg2); 168 } 169 170 173 public void expectAndReturn(double arg0, double arg1, Range arg2) { 174 control.expectAndReturn(arg0, arg1, arg2); 175 } 176 177 180 public void expectAndReturn(double arg0, double arg1) { 181 control.expectAndReturn(arg0, arg1); 182 } 183 184 187 public void expectAndReturn(float arg0, float arg1, int arg2, int arg3) { 188 control.expectAndReturn(arg0, arg1, arg2, arg3); 189 } 190 191 194 public void expectAndReturn(float arg0, float arg1, int arg2) { 195 control.expectAndReturn(arg0, arg1, arg2); 196 } 197 198 201 public void expectAndReturn(float arg0, float arg1, Range arg2) { 202 control.expectAndReturn(arg0, arg1, arg2); 203 } 204 205 208 public void expectAndReturn(float arg0, float arg1) { 209 control.expectAndReturn(arg0, arg1); 210 } 211 212 215 public void expectAndReturn(long arg0, long arg1, int arg2, int arg3) { 216 control.expectAndReturn(arg0, arg1, arg2, arg3); 217 } 218 219 222 public void expectAndReturn(long arg0, long arg1, int arg2) { 223 control.expectAndReturn(arg0, arg1, arg2); 224 } 225 226 229 public void expectAndReturn(long arg0, long arg1, Range arg2) { 230 control.expectAndReturn(arg0, arg1, arg2); 231 } 232 233 236 public void expectAndReturn(long arg0, long arg1) { 237 control.expectAndReturn(arg0, arg1); 238 } 239 240 243 public void expectAndReturn(Object arg0, Object arg1, int arg2, int arg3) { 244 control.expectAndReturn(arg0, arg1, arg2, arg3); 245 } 246 247 250 public void expectAndReturn(Object arg0, Object arg1, int arg2) { 251 control.expectAndReturn(arg0, arg1, arg2); 252 } 253 254 257 public void expectAndReturn(Object arg0, Object arg1, Range arg2) { 258 control.expectAndReturn(arg0, arg1, arg2); 259 } 260 261 264 public void expectAndReturn(Object arg0, Object arg1) { 265 control.expectAndReturn(arg0, arg1); 266 } 267 268 271 public void expectAndThrow(boolean arg0, Throwable arg1, int arg2, int arg3) { 272 control.expectAndThrow(arg0, arg1, arg2, arg3); 273 } 274 275 278 public void expectAndThrow(boolean arg0, Throwable arg1, int arg2) { 279 control.expectAndThrow(arg0, arg1, arg2); 280 } 281 282 285 public void expectAndThrow(boolean arg0, Throwable arg1, Range arg2) { 286 control.expectAndThrow(arg0, arg1, arg2); 287 } 288 289 292 public void expectAndThrow(boolean arg0, Throwable arg1) { 293 control.expectAndThrow(arg0, arg1); 294 } 295 296 299 public void expectAndThrow(double arg0, Throwable arg1, int arg2, int arg3) { 300 control.expectAndThrow(arg0, arg1, arg2, arg3); 301 } 302 303 306 public void expectAndThrow(double arg0, Throwable arg1, int arg2) { 307 control.expectAndThrow(arg0, arg1, arg2); 308 } 309 310 313 public void expectAndThrow(double arg0, Throwable arg1, Range arg2) { 314 control.expectAndThrow(arg0, arg1, arg2); 315 } 316 317 320 public void expectAndThrow(double arg0, Throwable arg1) { 321 control.expectAndThrow(arg0, arg1); 322 } 323 324 327 public void expectAndThrow(float arg0, Throwable arg1, int arg2, int arg3) { 328 control.expectAndThrow(arg0, arg1, arg2, arg3); 329 } 330 331 334 public void expectAndThrow(float arg0, Throwable arg1, int arg2) { 335 control.expectAndThrow(arg0, arg1, arg2); 336 } 337 338 341 public void expectAndThrow(float arg0, Throwable arg1, Range arg2) { 342 control.expectAndThrow(arg0, arg1, arg2); 343 } 344 345 348 public void expectAndThrow(float arg0, Throwable arg1) { 349 control.expectAndThrow(arg0, arg1); 350 } 351 352 355 public void expectAndThrow(long arg0, Throwable arg1, int arg2, int arg3) { 356 control.expectAndThrow(arg0, arg1, arg2, arg3); 357 } 358 359 362 public void expectAndThrow(long arg0, Throwable arg1, int arg2) { 363 control.expectAndThrow(arg0, arg1, arg2); 364 } 365 366 369 public void expectAndThrow(long arg0, Throwable arg1, Range arg2) { 370 control.expectAndThrow(arg0, arg1, arg2); 371 } 372 373 376 public void expectAndThrow(long arg0, Throwable arg1) { 377 control.expectAndThrow(arg0, arg1); 378 } 379 380 383 public void expectAndThrow(Object arg0, Throwable arg1, int arg2, int arg3) { 384 control.expectAndThrow(arg0, arg1, arg2, arg3); 385 } 386 387 390 public void expectAndThrow(Object arg0, Throwable arg1, int arg2) { 391 control.expectAndThrow(arg0, arg1, arg2); 392 } 393 394 397 public void expectAndThrow(Object arg0, Throwable arg1, Range arg2) { 398 control.expectAndThrow(arg0, arg1, arg2); 399 } 400 401 404 public void expectAndThrow(Object arg0, Throwable arg1) { 405 control.expectAndThrow(arg0, arg1); 406 } 407 408 411 public Object getMock() { 412 if (mock == null) { 413 mock = Proxy.newProxyInstance(clazz.getClassLoader(), new Class [] { clazz }, this); 414 } 415 return mock; 416 } 417 418 421 public void replay() { 422 control.replay(); 423 } 424 425 428 public void reset() { 429 control.reset(); 430 } 431 432 435 public void setDefaultMatcher(ArgumentsMatcher arg0) { 436 control.setDefaultMatcher(arg0); 437 } 438 439 442 public void setDefaultReturnValue(boolean arg0) { 443 control.setDefaultReturnValue(arg0); 444 } 445 446 449 public void setDefaultReturnValue(double arg0) { 450 control.setDefaultReturnValue(arg0); 451 } 452 453 456 public void setDefaultReturnValue(float arg0) { 457 control.setDefaultReturnValue(arg0); 458 } 459 460 463 public void setDefaultReturnValue(long arg0) { 464 control.setDefaultReturnValue(arg0); 465 } 466 467 470 public void setDefaultReturnValue(Object arg0) { 471 control.setDefaultReturnValue(arg0); 472 } 473 474 477 public void setDefaultThrowable(Throwable arg0) { 478 control.setDefaultThrowable(arg0); 479 } 480 481 484 public void setDefaultVoidCallable() { 485 control.setDefaultVoidCallable(); 486 } 487 488 491 public void setMatcher(ArgumentsMatcher arg0) { 492 control.setMatcher(arg0); 493 } 494 495 498 public void setReturnValue(boolean arg0, int arg1, int arg2) { 499 control.setReturnValue(arg0, arg1, arg2); 500 } 501 502 505 public void setReturnValue(boolean arg0, int arg1) { 506 control.setReturnValue(arg0, arg1); 507 } 508 509 512 public void setReturnValue(boolean arg0, Range arg1) { 513 control.setReturnValue(arg0, arg1); 514 } 515 516 519 public void setReturnValue(boolean arg0) { 520 control.setReturnValue(arg0); 521 } 522 523 526 public void setReturnValue(double arg0, int arg1, int arg2) { 527 control.setReturnValue(arg0, arg1, arg2); 528 } 529 530 533 public void setReturnValue(double arg0, int arg1) { 534 control.setReturnValue(arg0, arg1); 535 } 536 537 540 public void setReturnValue(double arg0, Range arg1) { 541 control.setReturnValue(arg0, arg1); 542 } 543 544 547 public void setReturnValue(double arg0) { 548 control.setReturnValue(arg0); 549 } 550 551 554 public void setReturnValue(float arg0, int arg1, int arg2) { 555 control.setReturnValue(arg0, arg1, arg2); 556 } 557 558 561 public void setReturnValue(float arg0, int arg1) { 562 control.setReturnValue(arg0, arg1); 563 } 564 565 568 public void setReturnValue(float arg0, Range arg1) { 569 control.setReturnValue(arg0, arg1); 570 } 571 572 575 public void setReturnValue(float arg0) { 576 control.setReturnValue(arg0); 577 } 578 579 582 public void setReturnValue(long arg0, int arg1, int arg2) { 583 control.setReturnValue(arg0, arg1, arg2); 584 } 585 586 589 public void setReturnValue(long arg0, int arg1) { 590 control.setReturnValue(arg0, arg1); 591 } 592 593 596 public void setReturnValue(long arg0, Range arg1) { 597 control.setReturnValue(arg0, arg1); 598 } 599 600 603 public void setReturnValue(long arg0) { 604 control.setReturnValue(arg0); 605 } 606 607 610 public void setReturnValue(Object arg0, int arg1, int arg2) { 611 control.setReturnValue(arg0, arg1, arg2); 612 } 613 614 617 public void setReturnValue(Object arg0, int arg1) { 618 control.setReturnValue(arg0, arg1); 619 } 620 621 624 public void setReturnValue(Object arg0, Range arg1) { 625 control.setReturnValue(arg0, arg1); 626 } 627 628 631 public void setReturnValue(Object arg0) { 632 control.setReturnValue(arg0); 633 } 634 635 638 public void setThrowable(Throwable arg0, int arg1, int arg2) { 639 control.setThrowable(arg0, arg1, arg2); 640 } 641 642 645 public void setThrowable(Throwable arg0, int arg1) { 646 control.setThrowable(arg0, arg1); 647 } 648 649 652 public void setThrowable(Throwable arg0, Range arg1) { 653 control.setThrowable(arg0, arg1); 654 } 655 656 659 public void setThrowable(Throwable arg0) { 660 control.setThrowable(arg0); 661 } 662 663 666 public void setVoidCallable() { 667 control.setVoidCallable(); 668 } 669 670 673 public void setVoidCallable(int arg0, int arg1) { 674 control.setVoidCallable(arg0, arg1); 675 } 676 677 680 public void setVoidCallable(int arg0) { 681 control.setVoidCallable(arg0); 682 } 683 684 687 public void setVoidCallable(Range arg0) { 688 control.setVoidCallable(arg0); 689 } 690 691 694 public void verify() { 695 if (error != null) { 696 throw error; 697 } 698 control.verify(); 699 } 700 701 } 702 | Popular Tags |