1 /* Copyright 2004-2005 the original author or authors.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 package org
.codehaus
.groovy
.grails
.commons
;
17 import groovy
.lang
.GroovyClassLoader
;
18 import junit
.framework
.TestCase
;
24 public class CodecArtefactHandlerTests
extends TestCase
{
26 public void testIsCodecClass() throws Exception
29 ArtefactHandler handler
= new CodecArtefactHandler();
30 GroovyClassLoader gcl
= new GroovyClassLoader();
32 Class fullCodecClass
= gcl
.parseClass("class FullCodec {\n" +
33 "static def encode = { str -> }\n" +
34 "static def decode = { str -> }\n" +
36 assertTrue("class was an encoder/decoder", handler
.isArtefact( fullCodecClass
));
38 Class decodeOnlyCodecClass
= gcl
.parseClass("class DecodeOnlyCodec {\n" +
39 "static def decode = { str -> }\n" +
41 assertTrue("class was a decoder", handler
.isArtefact(decodeOnlyCodecClass
));
43 Class encodeOnlyCodecClass
= gcl
.parseClass("class EncodeOnlyCodec {\n" +
44 "static def encode = { str -> }\n" +
46 assertTrue("class was an encoder", handler
.isArtefact(encodeOnlyCodecClass
));
48 Class emptyCodecClass
= gcl
.parseClass("class EmptyCodec {\n" +
50 assertFalse("codec class had no encode or decode method", handler
.isArtefact(emptyCodecClass
));
52 Class nonCodecClass
= gcl
.parseClass("class SomeFoo {\n" +
53 "static def encode = { str -> }\n" +
55 assertFalse("class was not a codec", handler
.isArtefact(nonCodecClass
));