1   package net.sf.fleet.test;
2   
3   import net.sf.fleet.Context;
4   
5   import org.easymock.EasyMock;
6   import org.testng.annotations.Test;
7   import static org.testng.Assert.*;
8   import static net.sf.fleet.Fleet.*;
9   import static org.easymock.EasyMock.*;
10  
11  public class FleetTest {
12  	@Test
13  	public void testCurrentContext() {
14  		assertNull(getCurrentContext(), "Fleet current context should be null when one has not been set.");
15  		final Context lContext = createMock(Context.class);
16  		replay(lContext);
17  		runWithContext(lContext, new Runnable() {
18  			public void run() {
19  				assertSame(getCurrentContext(), lContext, "Current context should have been set.");
20  				final Context lSubContext = EasyMock.createMock(Context.class);
21  				replay(lSubContext);
22  				try {
23  					runWithContext(lSubContext, new Runnable() {
24  						public void run() {
25  							assertSame(getCurrentContext(),lSubContext,"Sub context was not set.");
26  							throw new RuntimeException();
27  						}
28  					});
29  				} catch (RuntimeException e) {
30  					// expected.
31  				}
32  				assertSame(getCurrentContext(), lContext, "Context was not restored after an exception being thrown.");
33  			}
34  		});
35  		assertNull(getCurrentContext(),"Root context was not restored.");
36  	}
37  	
38  	@Test
39  	public void testGetModule() {
40  		final Context lContext = createMock(Context.class);
41  		expect(lContext.getModule(Object.class)).andReturn(new Object());
42  		replay(lContext);
43  		runWithContext(lContext, new Runnable() {
44  			public void run() {
45  				assertNotNull(getModule(Object.class),"getModule should not return null.");
46  			}
47  		});
48  		
49  		verify(lContext);
50  	}
51  }