<commit_before>/*
 * Copyright 2015-2016 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.nebula.lint.rule.dependency

import com.netflix.nebula.lint.rule.test.AbstractRuleSpec

class UnusedDependencyExcludeRuleSpec extends AbstractRuleSpec {
    def rule

    def setup() {
        rule = new UnusedDependencyExcludeRule(project: project)
    }

    def 'unused exclude violates'() {
        when:
        // trivial case: no dependencies
        project.buildFile << """
            apply plugin: 'java'
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'com.google.guava', module: 'guava'
                }
            }
        """

        project.with {
            apply plugin: 'java'
            repositories {
                mavenCentral()
            }
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'com.google.guava', module: 'guava'
                }
            }
        }

        def results = runRulesAgainst(rule)

        then:
        results.violates()
    }

    def 'exclude matching a transitive dependency does not violate'() {
        when:
        // trivial case: no dependencies
        project.buildFile << """
            apply plugin: 'java'
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'commons-lang', module: 'commons-lang'
                }
            }
        """

        project.with {
            apply plugin: 'java'
            repositories {
                mavenCentral()
            }
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'commons-lang', module: 'commons-lang'
                }
            }
        }

        def results = runRulesAgainst(rule)

        then:
        results.doesNotViolate()
    }
}<commit_msg>Add test for reported issue related to unused-dependency-exclude on an unresolvable dependency (closes #57)<commit_after>/*
 * Copyright 2015-2016 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.nebula.lint.rule.dependency

import com.netflix.nebula.lint.rule.test.AbstractRuleSpec
import spock.lang.Issue

class UnusedDependencyExcludeRuleSpec extends AbstractRuleSpec {
    def rule

    def setup() {
        rule = new UnusedDependencyExcludeRule(project: project)
    }

    def 'unused exclude violates'() {
        when:
        // trivial case: no dependencies
        project.buildFile << """
            apply plugin: 'java'
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'com.google.guava', module: 'guava'
                }
            }
        """

        project.with {
            apply plugin: 'java'
            repositories {
                mavenCentral()
            }
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'com.google.guava', module: 'guava'
                }
            }
        }

        def results = runRulesAgainst(rule)

        then:
        results.violates()
    }

    def 'exclude matching a transitive dependency does not violate'() {
        when:
        // trivial case: no dependencies
        project.buildFile << """
            apply plugin: 'java'
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'commons-lang', module: 'commons-lang'
                }
            }
        """

        project.with {
            apply plugin: 'java'
            repositories {
                mavenCentral()
            }
            dependencies {
                compile('commons-configuration:commons-configuration:1.10') {
                    exclude group: 'commons-lang', module: 'commons-lang'
                }
            }
        }

        def results = runRulesAgainst(rule)

        then:
        results.doesNotViolate()
    }

    @Issue('#57')
    def 'exclude on a dependency that is unresolvable is considered unapplicable'() {
        when:
        // trivial case: no dependencies
        project.buildFile << """
            apply plugin: 'java'
            dependencies {
                compile('dne:dne:1.0') {
                    exclude group: 'com.google.guava', module: 'guava'
                }
            }
        """

        project.with {
            apply plugin: 'java'
            repositories {
                mavenCentral()
            }
            dependencies {
                compile('dne:dne:1.0') {
                    exclude group: 'com.google.guava', module: 'guava'
                }
            }
        }

        def results = runRulesAgainst(rule)

        then:
        results.violates()
    }
}
{'fraction_non_alphanumeric': 0.09153318077803203, 'fraction_numerical': 0.009153318077803204, 'mean_word_length': 1.6932218309859155, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6992473', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1469, 'n_words': 421}