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.

FieldOperationsUpdateClassRedefinedCount.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.github.dcevm.test.fields;
  2. import com.github.dcevm.HotSwapTool;
  3. import com.github.dcevm.test.TestUtil;
  4. import com.github.dcevm.test.category.Light;
  5. import org.junit.Before;
  6. import org.junit.Test;
  7. import org.junit.experimental.categories.Category;
  8. import static com.github.dcevm.test.util.HotSwapTestHelper.__toVersion__;
  9. import static org.junit.Assert.assertEquals;
  10. @Category(Light.class)
  11. public class FieldOperationsUpdateClassRedefinedCount {
  12. // Version 0
  13. public static class A {
  14. public int x;
  15. int getFieldInOldCode() {
  16. __toVersion__(1);
  17. // This field does no longer exist
  18. return x;
  19. }
  20. int getVer() {
  21. return 0;
  22. }
  23. }
  24. // Version 1
  25. public static class A___1 {
  26. public int x;
  27. public int y;
  28. int getVer() {
  29. return 1;
  30. }
  31. }
  32. public static class A___2 {
  33. int getVer() {
  34. return 2;
  35. }
  36. }
  37. @Before
  38. public void setUp() throws Exception {
  39. __toVersion__(0);
  40. }
  41. @Test
  42. public void addingFieldUpdatesClassRedifinedCount() throws NoSuchFieldException, IllegalAccessException {
  43. // setup
  44. A a = new A();
  45. __toVersion__(0);
  46. int prevVersion = TestUtil.getClassRedefinedCount(A.class);
  47. // examine
  48. __toVersion__(1);
  49. Object y = A.class.getDeclaredField("y").get(a);
  50. // verify
  51. assertEquals(0,y);
  52. assertEquals(1, a.getVer());
  53. assertEquals(prevVersion+1, TestUtil.getClassRedefinedCount(A.class));
  54. }
  55. @Test
  56. public void deletingFieldUpdatesClassRedifinedCount() {
  57. // setup
  58. A a= new A();
  59. __toVersion__(0);
  60. int prevVersion = TestUtil.getClassRedefinedCount(A.class);
  61. // examine
  62. __toVersion__(2);
  63. // verify
  64. assertEquals(2, a.getVer());
  65. assertEquals(prevVersion+1, TestUtil.getClassRedefinedCount(A.class));
  66. }
  67. }