    1   /*
    2    * $Id: SyntaxErrorMessageTest.java,v 1.1 2005/07/01 03:01:19 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.messages;
    20
    21  import junit.framework.TestCase;
    22
    23  import org.codehaus.groovy.control.SourceUnit;
    24  import org.codehaus.groovy.syntax.SyntaxException;
    25
    26  public class SyntaxErrorMessageTest extends TestCase {
    27
    28      public void testSetsTheSourceLocatorOfItsSyntaxExceptionAsTheNameOfTheCorrespondingSourceUnitWhenInstantiated() {
    29          SyntaxException syntaxException = new SyntaxException(someString(), -1, -1);
    30          assertEquals("source locator", null, syntaxException.getSourceLocator());
    31
    32          String sourceUnitName = someString();
    33          SourceUnit sourceUnit = SourceUnit.create(sourceUnitName, someString());
    34
    35          new SyntaxErrorMessage(syntaxException, sourceUnit);
    36          assertEquals("source locator", sourceUnitName, syntaxException.getSourceLocator());
    37      }
    38
    39      private String someString() {
    40          return String.valueOf(Math.random() * System.currentTimeMillis());
    41      }
    42  }