<commit_before>package org.osiam.resources.scim

import org.codehaus.groovy.classgen.Verifier.DefaultArgsAction;
import org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys;

import spock.lang.Specification


class ExtensionTest extends Specification {

    static def FIELD = 'foo'
    static def VALUE = 'bar'
    
    static def FIELD_INJECTED = 'injected'
    static def VALUE_INJECTED = 'iwasinjected'

    def 'Query for existing field returns value'(){
        given:
            def extension = new Extension([(FIELD):VALUE])
        expect:
            extension.getField(FIELD) == VALUE
    }

    def 'Query for non-existing field raises NoSuchElementException'(){
        given:
            def extension = new Extension()
        when:
            extension.getField(FIELD)
        then:
            thrown(NoSuchElementException)

    }

    def 'Query for Null raises IllegalArgumentException'(){
        given:
            def extension = new Extension()
        when:
            extension.getField(null)
        then:
            thrown(IllegalArgumentException)

    }

    def 'Query for an empty field name raises IllegalArgumentException'(){
        given:
            def extension = new Extension()
        when:
            extension.getField('')
        then:
            thrown(IllegalArgumentException)
    }

    def 'Setting a field to null raises IllegalArgumentException'(){
        given:
            def extension = new Extension()
        when:
            extension.setField(null, VALUE)
        then:
            thrown(IllegalArgumentException)
    }
    
    def 'Adding a field raises exception' () {
        given:
            def extension = new Extension([(FIELD):VALUE, (VALUE):FIELD])
        when:
            extension.setField(FIELD_INJECTED, VALUE_INJECTED)
        then:
            thrown(IllegalArgumentException)
    }

    def 'getAllFields returns a map of all the fields'(){
        given:
            def extension = new Extension([(FIELD):VALUE, (VALUE):FIELD])
        when:
            def result = extension.allFields
        then:
            result.size() == 2
            result[FIELD] == VALUE
            result[VALUE] == FIELD
    }

    def 'getAllFields returns a immutable map'(){
        given:
            def extension = new Extension([(FIELD):VALUE])
            def result = extension.getAllFields()
        when:
            result[FIELD] = FIELD
        then:
            thrown(UnsupportedOperationException)
    }
    
    def 'the constructor creates a copy of its parameter' () {
        given:
            def map = [(FIELD):VALUE, (VALUE):FIELD]
            def extension = new Extension(map)
        when:
            map[FIELD_INJECTED] = VALUE_INJECTED
            
        then:
            !extension.fields.containsKey(FIELD_INJECTED)
    }
}
<commit_msg>[cleanup] cleaning up tests #OSNG-191<commit_after>package org.osiam.resources.scim

import org.codehaus.groovy.classgen.Verifier.DefaultArgsAction;
import org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys;

import spock.lang.Specification
import spock.lang.Unroll;


class ExtensionTest extends Specification {

    static def FIELD = 'foo'
    static def VALUE = 'bar'
    
    static def FIELD_INJECTED = 'injected'
    static def VALUE_INJECTED = 'iwasinjected'

    def 'Query for existing field returns value'(){
        given:
            def extension = new Extension([(FIELD):VALUE])
        expect:
            extension.getField(FIELD) == VALUE
    }

    def 'Query for non-existing field raises NoSuchElementException'(){
        given:
            def extension = new Extension()
        when:
            extension.getField(FIELD)
        then:
            thrown(NoSuchElementException)

    }

    def 'Query for Null raises IllegalArgumentException'(){
        given:
            def extension = new Extension()
        when:
            extension.getField(null)
        then:
            thrown(IllegalArgumentException)

    }

    def 'Query for an empty field name raises IllegalArgumentException'(){
        given:
            def extension = new Extension()
        when:
            extension.getField('')
        then:
            thrown(IllegalArgumentException)
    }
    
    @Unroll
    def 'Setting a field with a #testCase name raises exception'(){
        given:
            def extension = new Extension()
        when:
            extension.setField(fieldName, VALUE)
        then:
            thrown(expectedException)
            
        where:
            testCase  | fieldName      | expectedException
            'null'    | null           | IllegalArgumentException
            'invalid' | FIELD_INJECTED | IllegalArgumentException
    }

    def 'getAllFields returns a map of all the fields'(){
        given:
            def extension = new Extension([(FIELD):VALUE, (VALUE):FIELD])
        when:
            def result = extension.allFields
        then:
            result.size() == 2
            result[FIELD] == VALUE
            result[VALUE] == FIELD
    }

    def 'getAllFields returns a immutable map'(){
        given:
            def extension = new Extension([(FIELD):VALUE])
            def result = extension.getAllFields()
        when:
            result[FIELD] = FIELD
        then:
            thrown(UnsupportedOperationException)
    }
    
    def 'the constructor creates a copy of its parameter' () {
        given:
            def map = [(FIELD):VALUE, (VALUE):FIELD]
            def extension = new Extension(map)
        when:
            map[FIELD_INJECTED] = VALUE_INJECTED
            
        then:
            !extension.fields.containsKey(FIELD_INJECTED)
    }
}

{'fraction_non_alphanumeric': 0.08498335377606449, 'fraction_numerical': 0.0008761170492377782, 'mean_word_length': 1.9544513457556936, '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': '5014115', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1464, 'n_words': 392}