1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }