    1   /*
    2    * $Id: CompilationUnitTest.java,v 1.2 2006/05/30 18:27:48 blackdrag 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          // disabled until checked with fraz
    34          //new CompilationUnit(configuration, null, createGroovyClassLoaderWithExpectations(configuration));
    35      }
    36
    37      private GroovyClassLoader createGroovyClassLoaderWithExpectations(CompilerConfiguration configuration) {
    38          Mock mockGroovyClassLoader = mock(GroovyClassLoader.class);
    39          for (Iterator iterator = configuration.getClasspath().iterator(); iterator.hasNext();) {
    40              mockGroovyClassLoader.expects(once()).method("addClasspath").with(eq(iterator.next()));
    41          }
    42          return (GroovyClassLoader) mockGroovyClassLoader.proxy();
    43      }
    44  }