2 * Copyright 2004-2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.codehaus
.groovy
.grails
.commons
;
18 import groovy
.lang
.GroovyClassLoader
;
19 import junit
.framework
.TestCase
;
24 * @author Steven Devijver
27 public class GrailsClassTests
extends TestCase
{
29 public GrailsClassTests() {
33 public GrailsClassTests(String arg0
) {
37 public void testAbstractGrailsClassNoPackage() throws Exception
{
38 GroovyClassLoader cl
= new GroovyClassLoader();
39 Class clazz
= cl
.parseClass("class TestService { }");
40 GrailsClass grailsClass
= new AbstractGrailsClass(clazz
, "Service") {};
41 assertEquals("TestService", clazz
.getName());
42 assertEquals("Test", grailsClass
.getName());
43 assertEquals("TestService", grailsClass
.getFullName());
44 assertNotNull(grailsClass
.newInstance());
47 public void testAbstractGrailsClassPackage() throws Exception
{
48 GroovyClassLoader cl
= new GroovyClassLoader();
49 Class clazz
= cl
.parseClass("package test.casey; class TestService { }");
50 GrailsClass grailsClass
= new AbstractGrailsClass(clazz
, "Service") {};
51 assertEquals("test.casey.TestService", clazz
.getName());
52 assertEquals("Test", grailsClass
.getName());
53 assertEquals("test.casey.TestService", grailsClass
.getFullName());
54 assertNotNull(grailsClass
.newInstance());
57 public void testGrailsClassNonPublicConstructor() throws Exception
{
58 GroovyClassLoader cl
= new GroovyClassLoader();
59 Class clazz
= cl
.parseClass("class ProtectedConstructor { protected ProtectedConstructor(){}}");
60 GrailsClass grailsClass
= new AbstractGrailsClass(clazz
, "ProtectedConstructor") {};
61 assertNotNull(grailsClass
.newInstance());