1   package com.atlassian.maven.plugins.amps;
2   
3   import junit.framework.TestCase;
4   
5   import java.io.IOException;
6   import java.net.ServerSocket;
7   
8   /**
9    *
10   */
11  public class TestMavenGoals extends TestCase
12  {
13      public void testPickFreePort() throws IOException
14      {
15          MavenContext ctx = new MavenContext(null, null, null, null, null);
16          MavenGoals goals = new MavenGoals(ctx);
17          ServerSocket socket = null;
18          try
19          {
20              socket = new ServerSocket(16829);
21  
22              // Pick any
23              int port = goals.pickFreePort(0);
24              assertTrue(16829 != port);
25              assertTrue(port > 0);
26  
27              // Pick taken
28              port = goals.pickFreePort(16829);
29              assertTrue(16829 != port);
30              assertTrue(port > 0);
31  
32              // Pick free
33              assertEquals(16828, goals.pickFreePort(16828));
34          }
35          finally
36          {
37              socket.close();
38          }
39      }
40  }