<commit_before>package grails.test.mixin

import org.junit.Test
import spock.lang.Specification
import org.apache.commons.logging.Log

class TestForSpec extends Specification{

    void "Test that imports aren't needed for junit"() {
        when:
            def test = junit4Test

        then:
            test != null
            test.getClass().getDeclaredMethod("testIndex", null).getAnnotation(Test.class) != null
            test.retrieveLog() instanceof Log
    }

    void "Test junit 3 test doesn't get annotation"() {
        when:
            def test = junit3Test

        then:
            test != null
            test.getClass().getDeclaredMethod("testIndex", null).getAnnotation(Test.class) == null
            test.retrieveLog() instanceof Log
    }

    void "Test spock test doesn't get annotation"() {
        when:
            def test = spockTest

        then:
            test != null
            test.getClass().getDeclaredMethod("Test index", null).getAnnotation(Test.class) == null
            test.retrieveLog() instanceof Log
    }
    
    void "Test that TestFor doesn't apply if the test is not JUnit 4, Junit 4 or Spock"() {
        when:
            def test = invalidTest

        then:
            test != null
            test.getClass().getDeclaredMethod("testBlah", null).getAnnotation(Test.class) == null
        
        when:
            test.retrieveLog() instanceof Log
        
        then:
            thrown MissingPropertyException
        
    }

    def getInvalidTest() {
        final gcl = new GroovyClassLoader()
        gcl.parseClass('''
class SimpleController {
    def index = {
        render "Hello"
    }<commit_msg>fix failing test<commit_after>package grails.test.mixin

import org.junit.Test
import spock.lang.Specification
import org.apache.commons.logging.Log

class TestForSpec extends Specification{

    void "Test that imports aren't needed for junit"() {
        when:
            def test = junit4Test

        then:
            test != null
            test.getClass().getDeclaredMethod("testIndex", null).getAnnotation(Test.class) != null
            test.retrieveLog() instanceof Log
    }

    void "Test junit 3 test doesn't get annotation"() {
        when:
            def test = junit3Test

        then:
            test != null
            test.getClass().getDeclaredMethod("testIndex", null).getAnnotation(Test.class) == null
            test.retrieveLog() instanceof Log
    }

    void "Test spock test doesn't get annotation"() {
        when:
            def test = spockTest

        then:
            test != null
            test.retrieveLog() instanceof Log
    }
    
    void "Test that TestFor doesn't apply if the test is not JUnit 4, Junit 4 or Spock"() {
        when:
            def test = invalidTest

        then:
            test != null
            test.getClass().getDeclaredMethod("testBlah", null).getAnnotation(Test.class) == null
        
        when:
            test.retrieveLog() instanceof Log
        
        then:
            thrown MissingPropertyException
        
    }

    def getInvalidTest() {
        final gcl = new GroovyClassLoader()
        gcl.parseClass('''
class SimpleController {
    def index = {
        render "Hello"
    }
{'fraction_non_alphanumeric': 0.08979466748391052, 'fraction_numerical': 0.0030646644192460926, 'mean_word_length': 1.8987566607460036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5046053', 'n_tokens_mistral': 894, 'n_tokens_neox': 863, 'n_words': 242}