/*
 * Copyright (c) 2008 Kasper Nielsen.
 *
 * 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 org.cakeframework.inject;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import cake.internal.inject.spi.InjectorBuilder;

/**
 *
 */
@Disabled
public class InjectorXTest extends AbstractInjectTest {

    @Test
    public void emptyBuilder() {
        i = new InjectorBuilder().build();
        assertThat(i).isNotNull();
        assertThat(injectorParent()).isNull();
        assertThat(i).isSameAs(i.injectMembers(i));
    }

    @Test
    public void addInstance() {
        InjectorBuilder b = new InjectorBuilder();
        ServiceConfiguration<Integer> c = b.bind(1);

        assertNotNull(c);
        assertNull(c.getKey());
        assertSame(c, c.as(Number.class));
        assertEquals(Key.of(Number.class), c.getKey());
        // I think you can call as again. I see no problem.
        // We just need to make sure the new is available.
        // Before we remove the old one.

    }

    @Nested
    public class BindService {

        /** Tests the description of services. We only test for one of */
        @Test
        public void serviceDescription() {
            InjectorBuilder b = new InjectorBuilder();
            ServiceConfiguration<?> c = b.bind(1).as(Integer.class);

            assertNull(c.getDescription());
            assertSame(c, c.setDescription("foo"));
            assertEquals("foo", c.getDescription());

            assertEquals("foo", b.build().withService(Integer.class).getDescription());

            // Cannot set description after the service has been initialized.
            assertThrows(IllegalStateException.class, () -> c.setDescription("qwerty"));
            assertEquals("foo", c.getDescription());
        }

    }
}
