All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.sisu.wire.ParametersTest Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (c) 2010, 2013 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Stuart McCulloch (Sonatype, Inc.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.sisu.wire;

import java.util.Arrays;
import java.util.Map;

import javax.inject.Inject;

import junit.framework.TestCase;

import org.eclipse.sisu.Parameters;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Provides;

public class ParametersTest
    extends TestCase
{
    @Inject
    @Parameters
    String[] arguments;

    @Inject
    @Parameters
    Map properties;

    public void testDefaultParameters()
    {
        Guice.createInjector( new WireModule( new AbstractModule()
        {
            @Override
            protected void configure()
            {
                bind( ParametersTest.class );
            }
        } ) ).injectMembers( this );

        assertTrue( properties.isEmpty() );
        assertEquals( 0, arguments.length );
    }

    @SuppressWarnings( { "unchecked", "rawtypes" } )
    public void testCustomParameters()
    {
        Guice.createInjector( new WireModule( new AbstractModule()
        {
            @Override
            protected void configure()
            {
                bind( ParametersTest.class );
            }

            @Provides
            @Parameters
            String[] arguments()
            {
                return new String[] { "Hello", "World" };
            }

            @Provides
            @Parameters
            Map properties()
            {
                return (Map) System.getProperties();
            }
        } ) ).injectMembers( this );

        assertEquals( System.getProperties(), properties );
        assertTrue( Arrays.equals( new String[] { "Hello", "World" }, arguments ) );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy