001 /*****************************************************************************
002 * Copyright (C) PicoContainer Organization. All rights reserved. *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD *
005 * style license a copy of which has been included with this distribution in *
006 * the LICENSE.txt file. *
007 *****************************************************************************/
008 package org.picocontainer.lifecycle;
009
010 import static org.junit.Assert.assertTrue;
011
012 import org.junit.Test;
013 import org.junit.Before;
014 import org.junit.Assert;
015
016 /**
017 * @author Michael Rimov
018 */
019 public class DefaultLifecycleStateTestCase {
020
021 DefaultLifecycleState dls;
022
023 @Before
024 public void foo() {
025 dls = new DefaultLifecycleState();
026 }
027
028 @Test public void testNormalLifecycle() {
029 dls.starting();
030 dls.stopping();
031 dls.stopped();
032 dls.disposing();
033 dls.disposed();
034 }
035
036 @Test public void testReStartLifecycle() {
037 dls.starting();
038 dls.stopping();
039 dls.stopped();
040 dls.starting();
041 dls.stopping();
042 dls.stopped();
043 }
044
045 @Test public void testDisposalWithoutStarting() {
046 dls.disposing();
047 dls.disposed();
048 }
049
050 @Test public void testDisposalWithoutStop() {
051 dls.starting();
052 try {
053 dls.disposing();
054 Assert.fail("should have barfed");
055 } catch (IllegalStateException e) {
056 assertTrue(e.getMessage().endsWith("STARTED"));
057 //expected
058 }
059 }
060
061 @Test public void testStopWithoutStart() {
062 try {
063 dls.stopping();
064 Assert.fail("should have barfed");
065 } catch (IllegalStateException e) {
066 assertTrue(e.getMessage().endsWith("CONSTRUCTED"));
067 //expected
068 }
069 }
070
071 }