Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-2438

Missing @MockStaticEntityMethods annotation in test mock

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 1.1.3.RELEASE
    • Fix Version/s: 1.1.4.RELEASE
    • Component/s: TESTING
    • Labels:
      None

      Description

      The generated mock test requires mocking of static entity methods, and as such won't run as is. Current code is missing a class-level annotation, @MockStaticEntityMethods, which will make the code function properly.

      Incorrect version:

      package org.rooina.coursemanager.model;
      
      import org.junit.Test;
      
      public class StudentTest {
      
          @Test
          public void testMethod() {
              int expectedCount = 13;
              Student.countStudents();
              org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.expectReturn(expectedCount);
              org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.playback();
              org.junit.Assert.assertEquals(expectedCount, Student.countStudents());
          }
      }
      

      Correct version:

      package org.rooina.coursemanager.model;
      
      import org.junit.Test;
      import org.springframework.mock.staticmock.MockStaticEntityMethods;
      
      @MockStaticEntityMethods
      public class StudentTest {
      
          @Test
          public void testMethod() {
              int expectedCount = 13;
              Student.countStudents();
              org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.expectReturn(expectedCount);
              org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.playback();
              org.junit.Assert.assertEquals(expectedCount, Student.countStudents());
          }
      }
      

        Attachments

          Activity

            People

            Assignee:
            stewarta Alan Stewart
            Reporter:
            krimple Ken Rimple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified