/**
 * Copyright 2007-2015, Kaazing Corporation. All rights reserved.
 *
 * 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.kaazing.nuklei;

import static org.junit.Assert.assertSame;

import java.io.IOException;

import javax.annotation.Resource;

import org.junit.Test;

public final class NukleusFactoryTest
{

    @Test
    public void shouldLoadAndInject() throws IOException
    {
        NukleusFactory factory = NukleusFactory.instantiate();
        TestNukleus nukleus = (TestNukleus) factory.create("test", new Configuration());
        assertSame(factory, nukleus.factory());
    }

    public static final class TestNukleusFactory implements NukleusFactorySpi
    {
        private NukleusFactory factory;

        @Resource
        public void setFacktory(NukleusFactory factory)
        {
            this.factory = factory;
        }

        @Override
        public String name()
        {
            return "test";
        }

        @Override
        public Nukleus create(Configuration options)
        {
            return new TestNukleus(factory);
        }

    }

    static final class TestNukleus implements Nukleus
    {
        private final NukleusFactory factory;

        TestNukleus(NukleusFactory factory)
        {
            this.factory = factory;
        }

        NukleusFactory factory()
        {
            return factory;
        }

        @Override
        public int process()
        {
            // no-op
            return 0;
        }

        @Override
        public void close() throws Exception
        {
            // no-op
        }

    }
}

@@ -650,16 +650,64 @@
 uklei;%0A%0A
+import static org.hamcrest.Matchers.instanceOf;%0A
 import s
@@ -735,20 +735,20 @@
 t.assert
-Same
+That
 ;%0A%0Aimpor
@@ -775,43 +775,8 @@
 n;%0A%0A
-import javax.annotation.Resource;%0A%0A
 impo
@@ -879,14 +879,14 @@
 dAnd
-Inject
+Create
 () t
@@ -976,28 +976,24 @@
 ();%0A        
-Test
 Nukleus nukl
@@ -1001,22 +1001,8 @@
 us =
- (TestNukleus)
  fac
@@ -1061,38 +1061,50 @@
 sert
-Same(factory, nukleus.factory(
+That(nukleus, instanceOf(TestNukleus.class
 ));%0A
@@ -1198,180 +1198,8 @@
   %7B%0A
-        private NukleusFactory factory;%0A%0A        @Resource%0A        public void setFacktory(NukleusFactory factory)%0A        %7B%0A            this.factory = factory;%0A        %7D%0A%0A
     
@@ -1405,23 +1405,16 @@
 Nukleus(
-factory
 );%0A     
@@ -1414,25 +1414,24 @@
 ;%0A        %7D%0A
-%0A
     %7D%0A%0A    s
@@ -1489,238 +1489,8 @@
   %7B%0A
-        private final NukleusFactory factory;%0A%0A        TestNukleus(NukleusFactory factory)%0A        %7B%0A            this.factory = factory;%0A        %7D%0A%0A        NukleusFactory factory()%0A        %7B%0A            return factory;%0A        %7D%0A%0A
     
@@ -1696,21 +1696,20 @@
 p%0A        %7D%0A
-%0A
     %7D%0A%7D%0A

Update unit test to no longer verify factory injection into nukleus