1 // SECTION-START[License Header] 2 // <editor-fold defaultstate="collapsed" desc=" Generated License "> 3 /* 4 * Java Object Management and Configuration 5 * Copyright (C) Christian Schulte, 2005-206 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * o Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * o Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * $JOMC: ObjectManagerFactoryTest.java 4588 2012-06-03 06:01:30Z schulte2005 $ 32 * 33 */ 34 // </editor-fold> 35 // SECTION-END 36 package org.jomc.test; 37 38 import org.jomc.ObjectManagerFactory; 39 import org.jomc.test.support.UnsupportedOperationExceptionObjectManager; 40 import org.junit.Test; 41 import static org.junit.Assert.assertFalse; 42 import static org.junit.Assert.assertNotNull; 43 import static org.junit.Assert.assertTrue; 44 45 // SECTION-START[Documentation] 46 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 47 /** 48 * Test cases for class {@code org.jomc.ObjectManagerFactory}. 49 * 50 * <dl> 51 * <dt><b>Identifier:</b></dt><dd>org.jomc.test.ObjectManagerFactoryTest</dd> 52 * <dt><b>Name:</b></dt><dd>JOMC API</dd> 53 * <dt><b>Abstract:</b></dt><dd>No</dd> 54 * <dt><b>Final:</b></dt><dd>Yes</dd> 55 * <dt><b>Stateless:</b></dt><dd>No</dd> 56 * </dl> 57 * 58 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 59 * @version 1.3 60 */ 61 // </editor-fold> 62 // SECTION-END 63 // SECTION-START[Annotations] 64 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 65 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 66 // </editor-fold> 67 // SECTION-END 68 public class ObjectManagerFactoryTest 69 { 70 // SECTION-START[ObjectManagerFactoryTest] 71 72 private static final String SYS_FACTORY_CLASSNAME = "org.jomc.ObjectManagerFactory"; 73 74 private static final String SYS_IMPLEMENTATION_CLASSNAME = "org.jomc.ObjectManager"; 75 76 @Test 77 public final void testObjectManagerFactory() throws Exception 78 { 79 final String objectManagerFactory = System.getProperty( SYS_FACTORY_CLASSNAME ); 80 final String objectManager = System.getProperty( SYS_IMPLEMENTATION_CLASSNAME ); 81 try 82 { 83 System.setProperty( SYS_FACTORY_CLASSNAME, UnsupportedOperationExceptionObjectManager.class.getName() ); 84 System.setProperty( SYS_IMPLEMENTATION_CLASSNAME, UnsupportedOperationExceptionObjectManager.class.getName() ); 85 assertNotNull( ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ) ); 86 assertTrue( ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ) 87 == ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ) ); 88 89 assertNotNull( ObjectManagerFactory.newObjectManager( this.getClass().getClassLoader() ) ); 90 assertFalse( ObjectManagerFactory.newObjectManager( this.getClass().getClassLoader() ) 91 == ObjectManagerFactory.newObjectManager( this.getClass().getClassLoader() ) ); 92 93 } 94 finally 95 { 96 if ( objectManagerFactory != null ) 97 { 98 System.setProperty( SYS_FACTORY_CLASSNAME, objectManagerFactory ); 99 } 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.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" ) 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 }