You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OperationsOnMethodsUpdateClassRedefinedCount.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.github.dcevm.test.methods;
  2. import com.github.dcevm.test.TestUtil;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
  6. import static org.junit.Assert.assertEquals;
  7. public class OperationsOnMethodsUpdateClassRedefinedCount {
  8. // Version 0
  9. public static class A {
  10. public int value(int newVersion) {
  11. return newVersion;
  12. }
  13. }
  14. // Version 1
  15. public static class A___1 {
  16. public int value(int newVersion) {
  17. int x = 1;
  18. try {
  19. x = 2;
  20. } catch (NumberFormatException e) {
  21. x = 3;
  22. } catch (Exception e) {
  23. x = 4;
  24. } finally {
  25. x = x * 2;
  26. }
  27. __toVersion__(newVersion);
  28. throw new IllegalArgumentException();
  29. }
  30. }
  31. // Version 2
  32. public static class A___2 {
  33. public int value2() {
  34. return 2;
  35. }
  36. public int value(int newVersion) {
  37. int x = 1;
  38. try {
  39. x = 2;
  40. } catch (NumberFormatException e) {
  41. x = 3;
  42. } catch (Exception e) {
  43. x = 4;
  44. } finally {
  45. x = x * 2;
  46. }
  47. __toVersion__(newVersion);
  48. throw new IllegalArgumentException();
  49. }
  50. public int value3() {
  51. return 3;
  52. }
  53. public int value4() {
  54. return 4;
  55. }
  56. public int value5() {
  57. return 5;
  58. }
  59. }
  60. @Before
  61. public void setUp() throws Exception {
  62. __toVersion__(0);
  63. }
  64. @Test
  65. public void changingMethodUpdatesClassRedefinedCount() {
  66. // setup
  67. __toVersion__(0);
  68. int prevVersion = TestUtil.getClassRedefinedCount(A.class);
  69. // examine
  70. __toVersion__(1);
  71. // verify
  72. assertEquals(prevVersion+1, TestUtil.getClassRedefinedCount(A.class));
  73. }
  74. @Test
  75. public void addingMethodUpdatesClassRedefinedCount() {
  76. // setup
  77. __toVersion__(0);
  78. int prevVersion = TestUtil.getClassRedefinedCount(A.class);
  79. // examine
  80. __toVersion__(2);
  81. // verify
  82. assertEquals(prevVersion+1, TestUtil.getClassRedefinedCount(A.class));
  83. }
  84. @Test
  85. public void deletingMethodUpdatesClassRedefinedCount() {
  86. // setup
  87. __toVersion__(2);
  88. int prevVersion = TestUtil.getClassRedefinedCount(A.class);
  89. // examine
  90. __toVersion__(0);
  91. // verify
  92. assertEquals(prevVersion+1, TestUtil.getClassRedefinedCount(A.class));
  93. }
  94. }