1   /*
2    * $Id: CompilationUnitTest.java,v 1.1 2005/06/27 17:34:04 fraz Exp $
3    *
4    * Copyright (c) 2005 The Codehaus - http://groovy.codehaus.org
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
12   * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *
14   * See the License for the specific language governing permissions and limitations under the License.
15   *
16   */
17  
18  
19  package org.codehaus.groovy.control;
20  
21  import java.util.Iterator;
22  
23  import org.jmock.Mock;
24  import org.jmock.cglib.MockObjectTestCase;
25  
26  import groovy.lang.GroovyClassLoader;
27  
28  public class CompilationUnitTest extends MockObjectTestCase {
29  
30      public void testAppendsTheClasspathOfTheCompilerConfigurationToCurrentClassLoaderWhenInstantiated() {
31          CompilerConfiguration configuration = new CompilerConfiguration();
32          configuration.setClasspath(System.getProperty("java.class.path"));
33          new CompilationUnit(configuration, null, createGroovyClassLoaderWithExpectations(configuration));
34      }
35  
36      private GroovyClassLoader createGroovyClassLoaderWithExpectations(CompilerConfiguration configuration) {
37          Mock mockGroovyClassLoader = mock(GroovyClassLoader.class);
38          for (Iterator iterator = configuration.getClasspath().iterator(); iterator.hasNext();) {
39              mockGroovyClassLoader.expects(once()).method("addClasspath").with(eq(iterator.next()));
40          }
41          return (GroovyClassLoader) mockGroovyClassLoader.proxy();
42      }
43  }