<commit_before>/*
 * Copyright 2015 <NAME>
 *
 * 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.shipdream.lib.poke;

import com.shipdream.lib.poke.exception.CircularDependenciesException;
import com.shipdream.lib.poke.exception.ProvideException;
import com.shipdream.lib.poke.exception.ProviderConflictException;
import com.shipdream.lib.poke.exception.ProviderMissingException;

import org.junit.Test;

public class TestDefaultGraphExceptions extends BaseTestCases {
    interface Pet{
    }

    static class Cat implements Pet {
    }

    static class Dog implements Pet {
    }

    @Test
    public void suppress_constructor_miss_coverage_of_pokerHelper() {
        new PokeHelper();
    }

    @Test(expected = ProviderConflictException.class)
    public void shouldDetectConflictingClassRegistry() throws ProviderConflictException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Cat.class);
        graph.register(Pet.class, Dog.class);
    }

    @Test(expected = ProviderConflictException.class)
    public void shouldDetectConflictingNameRegistry() throws ProviderConflictException, ClassNotFoundException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Cat.class.getName());
        graph.register(Pet.class, Dog.class.getName());
    }

    @SuppressWarnings("unchecked")
    @Test(expected = ProviderConflictException.class)
    public void shouldDetectConflictingProviderRegistry() throws ProviderConflictException, ProvideException, ClassNotFoundException {
        SimpleGraph graph = new SimpleGraph();
        Provider provider = new ProviderByClassType<>(Pet.class, Cat.class);
        Provider provider2 = new ProviderByClassName(Pet.class, Dog.class.getName());
        graph.register(provider);
        graph.register(provider2);
    }

    @Test(expected = ClassNotFoundException.class)
    public void shouldDetectBadClassException() throws ProviderConflictException, ClassNotFoundException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, "BadClass");
    }

    @Test
    public void shouldBeGoodInjection()
            throws ProviderConflictException, CircularDependenciesException, ProviderMissingException, ProvideException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Dog.class);

        class Family {
            @MyInject
            private Pet pet;
        }

        Family family = new Family();
        graph.inject(family, MyInject.class);
    }

    static class Rabbit implements Pet {
        String name;
        public Rabbit(String name) {
            this.name = name;
        }
    }

    @Test(expected = ProvideException.class)
    public void shouldDetectProvideExceptionWithClassDoesHaveDefaultConstructor()
            throws ProviderConflictException, CircularDependenciesException, ProviderMissingException, ProvideException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Rabbit.class);

        class Family {
            @MyInject
            private Pet pet;
        }

        Family family = new Family();
        graph.inject(family, MyInject.class);
    }

    static class Fish implements Pet {
        private Fish() {
        }
    }

    @Test(expected = ProvideException.class)
    public void shouldDetectProvideExceptionWithClassWithInaccessibleConstructor()
            throws ProviderConflictException, CircularDependenciesException, ProviderMissingException, ProvideException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Fish.class);

        class Family {
            @MyInject
            private Pet pet;
        }

        Family family = new Family();
        graph.inject(family, MyInject.class);
    }
}<commit_msg>Remove unit test not valid any more<commit_after>/*
 * Copyright 2015 <NAME>
 *
 * 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.shipdream.lib.poke;

import com.shipdream.lib.poke.exception.CircularDependenciesException;
import com.shipdream.lib.poke.exception.ProvideException;
import com.shipdream.lib.poke.exception.ProviderConflictException;
import com.shipdream.lib.poke.exception.ProviderMissingException;

import org.junit.Test;

public class TestDefaultGraphExceptions extends BaseTestCases {
    interface Pet{
    }

    static class Cat implements Pet {
    }

    static class Dog implements Pet {
    }

    @Test
    public void suppress_constructor_miss_coverage_of_pokerHelper() {
        new PokeHelper();
    }

    @Test(expected = ProviderConflictException.class)
    public void shouldDetectConflictingClassRegistry() throws ProviderConflictException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Cat.class);
        graph.register(Pet.class, Dog.class);
    }

    @Test(expected = ProviderConflictException.class)
    public void shouldDetectConflictingNameRegistry() throws ProviderConflictException, ClassNotFoundException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Cat.class.getName());
        graph.register(Pet.class, Dog.class.getName());
    }

    @SuppressWarnings("unchecked")
    @Test(expected = ProviderConflictException.class)
    public void shouldDetectConflictingProviderRegistry() throws ProviderConflictException, ProvideException, ClassNotFoundException {
        SimpleGraph graph = new SimpleGraph();
        Provider provider = new ProviderByClassType<>(Pet.class, Cat.class);
        Provider provider2 = new ProviderByClassName(Pet.class, Dog.class.getName());
        graph.register(provider);
        graph.register(provider2);
    }

    @Test(expected = ClassNotFoundException.class)
    public void shouldDetectBadClassException() throws ProviderConflictException, ClassNotFoundException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, "BadClass");
    }

    @Test
    public void shouldBeGoodInjection()
            throws ProviderConflictException, CircularDependenciesException, ProviderMissingException, ProvideException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Dog.class);

        class Family {
            @MyInject
            private Pet pet;
        }

        Family family = new Family();
        graph.inject(family, MyInject.class);
    }

    static class Rabbit implements Pet {
        String name;
        public Rabbit(String name) {
            this.name = name;
        }
    }

    @Test(expected = ProvideException.class)
    public void shouldDetectProvideExceptionWithClassDoesHaveDefaultConstructor()
            throws ProviderConflictException, CircularDependenciesException, ProviderMissingException, ProvideException {
        SimpleGraph graph = new SimpleGraph();
        graph.register(Pet.class, Rabbit.class);

        class Family {
            @MyInject
            private Pet pet;
        }

        Family family = new Family();
        graph.inject(family, MyInject.class);
    }

}
{'fraction_non_alphanumeric': 0.08021258188110246, 'fraction_numerical': 0.002471882338400692, 'mean_word_length': 3.236649214659686, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6747127', 'n_tokens_mistral': 2084, 'n_tokens_neox': 1968, 'n_words': 551}