001    // SECTION-START[License Header]
002    // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003    /*
004     *   Java Object Management and Configuration
005     *   Copyright (C) Christian Schulte, 2005-206
006     *   All rights reserved.
007     *
008     *   Redistribution and use in source and binary forms, with or without
009     *   modification, are permitted provided that the following conditions
010     *   are met:
011     *
012     *     o Redistributions of source code must retain the above copyright
013     *       notice, this list of conditions and the following disclaimer.
014     *
015     *     o Redistributions in binary form must reproduce the above copyright
016     *       notice, this list of conditions and the following disclaimer in
017     *       the documentation and/or other materials provided with the
018     *       distribution.
019     *
020     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     *
031     *   $JOMC: ObjectManagerFactoryTest.java 4268 2012-02-16 23:14:52Z schulte2005 $
032     *
033     */
034    // </editor-fold>
035    // SECTION-END
036    package org.jomc.test;
037    
038    import org.jomc.ObjectManagerFactory;
039    import org.jomc.test.support.UnsupportedOperationExceptionObjectManager;
040    import org.junit.Test;
041    import static org.junit.Assert.assertFalse;
042    import static org.junit.Assert.assertNotNull;
043    import static org.junit.Assert.assertTrue;
044    
045    // SECTION-START[Documentation]
046    // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
047    /**
048     * Test cases for class {@code org.jomc.ObjectManagerFactory}.
049     *
050     * <dl>
051     *   <dt><b>Identifier:</b></dt><dd>org.jomc.test.ObjectManagerFactoryTest</dd>
052     *   <dt><b>Name:</b></dt><dd>JOMC API</dd>
053     *   <dt><b>Abstract:</b></dt><dd>No</dd>
054     *   <dt><b>Final:</b></dt><dd>Yes</dd>
055     *   <dt><b>Stateless:</b></dt><dd>No</dd>
056     * </dl>
057     *
058     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
059     * @version 1.2
060     */
061    // </editor-fold>
062    // SECTION-END
063    // SECTION-START[Annotations]
064    // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
065    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2" )
066    // </editor-fold>
067    // SECTION-END
068    public class ObjectManagerFactoryTest
069    {
070        // SECTION-START[ObjectManagerFactoryTest]
071    
072        private static final String SYS_FACTORY_CLASSNAME = "org.jomc.ObjectManagerFactory";
073    
074        private static final String SYS_IMPLEMENTATION_CLASSNAME = "org.jomc.ObjectManager";
075    
076        @Test
077        public final void testObjectManagerFactory() throws Exception
078        {
079            final String objectManagerFactory = System.getProperty( SYS_FACTORY_CLASSNAME );
080            final String objectManager = System.getProperty( SYS_IMPLEMENTATION_CLASSNAME );
081            try
082            {
083                System.setProperty( SYS_FACTORY_CLASSNAME, UnsupportedOperationExceptionObjectManager.class.getName() );
084                System.setProperty( SYS_IMPLEMENTATION_CLASSNAME, UnsupportedOperationExceptionObjectManager.class.getName() );
085                assertNotNull( ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ) );
086                assertTrue( ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() )
087                            == ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ) );
088    
089                assertNotNull( ObjectManagerFactory.newObjectManager( this.getClass().getClassLoader() ) );
090                assertFalse( ObjectManagerFactory.newObjectManager( this.getClass().getClassLoader() )
091                             == ObjectManagerFactory.newObjectManager( this.getClass().getClassLoader() ) );
092    
093            }
094            finally
095            {
096                if ( objectManagerFactory != null )
097                {
098                    System.setProperty( SYS_FACTORY_CLASSNAME, objectManagerFactory );
099                }
100                else
101                {
102                    System.clearProperty( SYS_FACTORY_CLASSNAME );
103                }
104                if ( objectManager != null )
105                {
106                    System.setProperty( SYS_IMPLEMENTATION_CLASSNAME, objectManager );
107                }
108                else
109                {
110                    System.clearProperty( SYS_IMPLEMENTATION_CLASSNAME );
111                }
112            }
113        }
114        // SECTION-END
115        // SECTION-START[Constructors]
116        // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
117        /** Creates a new {@code ObjectManagerFactoryTest} instance. */
118        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2" )
119        public ObjectManagerFactoryTest()
120        {
121            // SECTION-START[Default Constructor]
122            super();
123            // SECTION-END
124        }
125        // </editor-fold>
126        // SECTION-END
127        // SECTION-START[Dependencies]
128        // SECTION-END
129        // SECTION-START[Properties]
130        // SECTION-END
131        // SECTION-START[Messages]
132        // SECTION-END
133    }