Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3134

Cannot override private static method using EMC

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.5.6, 1.7.0
    • Fix Version/s: 3.x
    • Component/s: groovy-runtime
    • Labels:
      None
    • Environment:
      Windows XP, Eclipse Ganymede, Groovy Eclipse plugin using Groovy 1.5.6

      Description

      Here's an example of a simple test, in which the return type of a Private Static Method within a Class is needed to return a String different from what it would normally return:

      void testCheckSunrise(){
          WeatherMonitor.metaClass.static.findSunriseTime = {-> '5:57 AM'}
          WeatherMonitor testSubject = new WeatherMonitor()	
          assertEquals('5:57 AM', testSubject.sunrise)
      }
      

      And here is the Class itself:

      public class WeatherMonitor {
          def getSunrise(){
              findSunriseTime()
          }
      
          private static findSunriseTime(){
              '7:15 AM'
          }
      }
      

      The result of the test execution is always '7:15 AM' and so the test will always fail. This would be a great help in Unit Testing techniques, especially Test Driven Development in Groovy.

      It would be great to see Groovy have this capability.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              prometheusbound Michael Nyika
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: