This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch WW-5233-tiles in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/WW-5233-tiles by this push: new e8e514eee WW-5233 Copies Tiles Autotag related tests e8e514eee is described below commit e8e514eee667266d49475b1930024b9e38d5c7e0 Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Sun Oct 2 14:53:17 2022 +0200 WW-5233 Copies Tiles Autotag related tests --- .../core/internal/AnnotatedExampleModel.java | 40 ++++++ .../autotag/core/internal/ExampleExcluded.java | 39 ++++++ .../core/internal/ExampleExecutableModel.java | 36 +++++ .../tiles/autotag/core/internal/ExampleModel.java | 39 ++++++ .../autotag/core/internal/ExampleRequest.java | 23 ++++ .../core/internal/NotFeasibleExampleModel.java | 34 +++++ .../tiles/autotag/model/TemplateClassTest.java | 153 +++++++++++++++++++++ .../tiles/autotag/model/TemplateMethodTest.java | 132 ++++++++++++++++++ .../tiles/autotag/model/TemplateParameterTest.java | 88 ++++++++++++ .../tiles/autotag/model/TemplateSuiteTest.java | 112 +++++++++++++++ 10 files changed, 696 insertions(+) diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/AnnotatedExampleModel.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/AnnotatedExampleModel.java new file mode 100644 index 000000000..99291461b --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/AnnotatedExampleModel.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.core.internal; + +import org.apache.tiles.autotag.core.runtime.ModelBody; +import org.apache.tiles.autotag.core.runtime.annotation.Parameter; + +/** + * Example start/stop template. + */ +public class AnnotatedExampleModel { + + /** + * It starts. + * + * @param one Parameter one. + * @param two Parameter two. + * @param request The request. + * @param modelBody The model body. + */ + public void execute(@Parameter(defaultValue = "hello", name = "alternateOne", required = true) String one, int two, ExampleRequest request, ModelBody modelBody) { + // Does nothing. + } +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleExcluded.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleExcluded.java new file mode 100644 index 000000000..2d310f705 --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleExcluded.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.core.internal; + +import org.apache.tiles.autotag.core.runtime.ModelBody; + +/** + * Example start/stop template. + */ +public class ExampleExcluded { + + /** + * It starts. + * + * @param one Parameter one. + * @param two Parameter two. + * @param request The request. + * @param modelBody The model body. + */ + public void execute(String one, int two, ExampleRequest request, ModelBody modelBody) { + // Does nothing. + } +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleExecutableModel.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleExecutableModel.java new file mode 100644 index 000000000..ec0af768f --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleExecutableModel.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.core.internal; + +/** + * Example executable template. + */ +public class ExampleExecutableModel { + + /** + * It executes. + * + * @param one Parameter one. + * @param two Parameter two. + * @param request The request. + */ + public void execute(String one, int two, ExampleRequest request) { + // Does nothing. + } +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleModel.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleModel.java new file mode 100644 index 000000000..8e3014381 --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleModel.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.core.internal; + +import org.apache.tiles.autotag.core.runtime.ModelBody; + +/** + * Example start/stop template. + */ +public class ExampleModel { + + /** + * It starts. + * + * @param one Parameter one. + * @param two Parameter two. + * @param request The request. + * @param modelBody The model body. + */ + public void execute(String one, int two, ExampleRequest request, ModelBody modelBody) { + // Does nothing. + } +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleRequest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleRequest.java new file mode 100644 index 000000000..af94a383c --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/ExampleRequest.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.core.internal; + +public class ExampleRequest { + +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/NotFeasibleExampleModel.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/NotFeasibleExampleModel.java new file mode 100644 index 000000000..637b54281 --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/core/internal/NotFeasibleExampleModel.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.core.internal; + +/** + * This won't be registered. + */ +public class NotFeasibleExampleModel { + + /** + * It starts. + * + * @param whatever Doesn't matter. + */ + public void start(String whatever) { + // Does nothing. + } +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateClassTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateClassTest.java new file mode 100644 index 000000000..1b875c37d --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateClassTest.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.model; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +public class TemplateClassTest { + + /** + * Test method for {@link TemplateClass#TemplateClass(String)}. + */ + @Test + public void testTemplateConstructor1() { + TemplateClass templateClass = new TemplateClass("name"); + assertEquals("name", templateClass.getName()); + assertNull(templateClass.getTagName()); + assertNull(templateClass.getTagClassPrefix()); + assertNull(templateClass.getExecuteMethod()); + Collection<TemplateParameter> params = templateClass.getParameters(); + assertTrue(params.isEmpty()); + } + + /** + * Test method for {@link TemplateClass#TemplateClass(String, String, String, TemplateMethod)}. + */ + @Test + public void testTemplateConstructor2() { + TemplateMethod method = createMock(TemplateMethod.class); + + replay(method); + TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); + assertEquals("name", templateClass.getName()); + assertEquals("tagName", templateClass.getTagName()); + assertEquals("tagClassPrefix", templateClass.getTagClassPrefix()); + assertEquals(method, templateClass.getExecuteMethod()); + verify(method); + } + + /** + * Test method for {@link TemplateClass#getSimpleName()}. + */ + @Test + public void testGetSimpleName() { + TemplateClass templateClass = new TemplateClass("name"); + assertEquals("name", templateClass.getSimpleName()); + templateClass = new TemplateClass("org.whatever.Hello"); + assertEquals("Hello", templateClass.getSimpleName()); + } + + /** + * Test method for {@link TemplateClass#setDocumentation(String)}. + */ + @Test + public void testSetDocumentation() { + TemplateClass templateClass = new TemplateClass("name"); + templateClass.setDocumentation("docs"); + assertEquals("docs", templateClass.getDocumentation()); + } + + /** + * Test method for {@link TemplateClass#getParameters()}. + */ + @Test + public void testGetParameters() { + TemplateParameter param1 = createMock(TemplateParameter.class); + TemplateParameter param2 = createMock(TemplateParameter.class); + TemplateParameter param3 = createMock(TemplateParameter.class); + TemplateParameter param4 = createMock(TemplateParameter.class); + TemplateMethod method = createMock(TemplateMethod.class); + List<TemplateParameter> params = new ArrayList<>(); + + expect(method.getParameters()).andReturn(params); + expect(param1.isRequest()).andReturn(true); + expect(param2.isRequest()).andReturn(false); + expect(param2.isBody()).andReturn(true); + expect(param3.isRequest()).andReturn(false); + expect(param3.isBody()).andReturn(false); + expect(param4.isRequest()).andReturn(false); + expect(param4.isBody()).andReturn(false); + expect(param3.getName()).andReturn("param1"); + expect(param4.getName()).andReturn("param2"); + + replay(param1, param2, param3, param4, method); + params.add(param1); + params.add(param2); + params.add(param3); + params.add(param4); + + TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); + Collection<TemplateParameter> returnedParams = templateClass.getParameters(); + Iterator<TemplateParameter> paramIt = returnedParams.iterator(); + assertSame(param3, paramIt.next()); + assertSame(param4, paramIt.next()); + assertFalse(paramIt.hasNext()); + verify(param1, param2, param3, param4, method); + } + + /** + * Test method for {@link TemplateClass#hasBody()}. + */ + @Test + public void testHasBody() { + TemplateMethod method = createMock(TemplateMethod.class); + expect(method.hasBody()).andReturn(true); + + replay(method); + TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); + assertTrue(templateClass.hasBody()); + verify(method); + } + + /** + * Test method for {@link TemplateClass#toString()}. + */ + @Test + public void testToString() { + TemplateMethod method = new TemplateMethod("method", new ArrayList<>()); + TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); + assertEquals("TemplateClass [name=name, tagName=tagName, tagClassPrefix=tagClassPrefix, " + "documentation=null, executeMethod=TemplateMethod " + "[name=method, documentation=null, parameters={}]]", templateClass.toString()); + } + +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateMethodTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateMethodTest.java new file mode 100644 index 000000000..e6ad8b181 --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateMethodTest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.model; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +/** + * Tests {@link TemplateMethod}. + */ +public class TemplateMethodTest { + + /** + * Tests {@link TemplateMethod#TemplateMethod(String, Iterable)}. + */ + @Test + public void testTemplateMethod() { + TemplateParameter param1 = createMock(TemplateParameter.class); + TemplateParameter param2 = createMock(TemplateParameter.class); + + expect(param1.getName()).andReturn("param1"); + expect(param2.getName()).andReturn("param2"); + + replay(param1, param2); + List<TemplateParameter> parameters = new ArrayList<>(); + parameters.add(param1); + parameters.add(param2); + + TemplateMethod method = new TemplateMethod("method", parameters); + assertEquals("method", method.getName()); + Iterator<TemplateParameter> params = method.getParameters().iterator(); + assertSame(param1, params.next()); + assertSame(param2, params.next()); + assertFalse(params.hasNext()); + assertSame(param1, method.getParameterByName("param1")); + assertSame(param2, method.getParameterByName("param2")); + verify(param1, param2); + } + + /** + * Tests {@link TemplateMethod#setDocumentation(String)}. + */ + @Test + public void testSetDocumentation() { + TemplateMethod method = new TemplateMethod("method", new ArrayList<>()); + method.setDocumentation("docs"); + assertEquals("docs", method.getDocumentation()); + } + + /** + * Tests {@link TemplateMethod#hasBody()}. + */ + @Test + public void testHasBody() { + TemplateParameter param1 = createMock(TemplateParameter.class); + TemplateParameter param2 = createMock(TemplateParameter.class); + + expect(param1.getName()).andReturn("param1"); + expect(param2.getName()).andReturn("param2"); + expect(param1.isBody()).andReturn(true); + + replay(param1, param2); + List<TemplateParameter> parameters = new ArrayList<>(); + parameters.add(param1); + parameters.add(param2); + + TemplateMethod method = new TemplateMethod("method", parameters); + assertTrue(method.hasBody()); + verify(param1, param2); + } + + /** + * Tests {@link TemplateMethod#hasBody()}. + */ + @Test + public void testHasBody2() { + TemplateParameter param1 = createMock(TemplateParameter.class); + TemplateParameter param2 = createMock(TemplateParameter.class); + + expect(param1.getName()).andReturn("param1"); + expect(param2.getName()).andReturn("param2"); + expect(param1.isBody()).andReturn(false); + expect(param2.isBody()).andReturn(false); + + replay(param1, param2); + List<TemplateParameter> parameters = new ArrayList<>(); + parameters.add(param1); + parameters.add(param2); + + TemplateMethod method = new TemplateMethod("method", parameters); + assertFalse(method.hasBody()); + verify(param1, param2); + } + + /** + * Tests {@link TemplateMethod#toString()}. + */ + @Test + public void testToString() { + TemplateMethod method = new TemplateMethod("method", new ArrayList<>()); + assertEquals("TemplateMethod [name=method, documentation=null, parameters={}]", method.toString()); + } + +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateParameterTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateParameterTest.java new file mode 100644 index 000000000..efa486950 --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateParameterTest.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.model; + +import org.apache.tiles.autotag.core.runtime.ModelBody; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Tests {@link TemplateParameter}. + */ +public class TemplateParameterTest { + + @Test + public void testTemplateParameter() { + TemplateParameter parameter = new TemplateParameter("name", "exportedName", "type", "defaultValue", true, false); + assertEquals("name", parameter.getName()); + assertEquals("exportedName", parameter.getExportedName()); + assertEquals("type", parameter.getType()); + assertEquals("defaultValue", parameter.getDefaultValue()); + assertTrue(parameter.isRequired()); + assertEquals("ExportedName", parameter.getGetterSetterSuffix()); + assertFalse(parameter.isBody()); + assertFalse(parameter.isRequest()); + + parameter = new TemplateParameter("name", "exportedName", "my.Request", "defaultValue", false, true); + assertEquals("name", parameter.getName()); + assertEquals("exportedName", parameter.getExportedName()); + assertEquals("my.Request", parameter.getType()); + assertEquals("defaultValue", parameter.getDefaultValue()); + assertFalse(parameter.isRequired()); + assertEquals("ExportedName", parameter.getGetterSetterSuffix()); + assertFalse(parameter.isBody()); + assertTrue(parameter.isRequest()); + + parameter = new TemplateParameter("name", "exportedName", ModelBody.class.getName(), "defaultValue", false, false); + assertEquals("name", parameter.getName()); + assertEquals("exportedName", parameter.getExportedName()); + assertEquals(ModelBody.class.getName(), parameter.getType()); + assertEquals("defaultValue", parameter.getDefaultValue()); + assertFalse(parameter.isRequired()); + assertEquals("ExportedName", parameter.getGetterSetterSuffix()); + assertTrue(parameter.isBody()); + assertFalse(parameter.isRequest()); + } + + /** + * Tests {@link TemplateParameter#setDocumentation(String)}. + */ + @Test + public void testSetDocumentation() { + TemplateParameter parameter = new TemplateParameter("name", "exportedName", "type", "defaultValue", true, false); + parameter.setDocumentation("docs"); + assertEquals("docs", parameter.getDocumentation()); + } + + /** + * Tests {@link TemplateParameter#toString()}. + */ + @Test + public void testToString() { + TemplateParameter parameter = new TemplateParameter("name", "exportedName", "type", "defaultValue", true, false); + assertEquals( + "TemplateParameter [name=name, exportedName=exportedName, " + + "documentation=null, type=type, defaultValue=defaultValue, required=true, request=false]", + parameter.toString()); + } + +} diff --git a/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateSuiteTest.java b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateSuiteTest.java new file mode 100644 index 000000000..cdb5c5216 --- /dev/null +++ b/plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateSuiteTest.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tiles.autotag.model; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +/** + * Tests {@link TemplateSuite}. + */ +public class TemplateSuiteTest { + + /** + * Test method for {@link TemplateSuite#TemplateSuite(String, String)}. + */ + @Test + public void testTemplateSuiteConstructor1() { + TemplateSuite suite = new TemplateSuite("name", "docs"); + assertEquals("name", suite.getName()); + assertEquals("docs", suite.getDocumentation()); + assertTrue(suite.getTemplateClasses().isEmpty()); + } + + /** + * Test method for {@link TemplateSuite#TemplateSuite(String, String, Iterable)}. + */ + @Test + public void testTemplateSuiteConstructor2() { + TemplateClass class1 = createMock(TemplateClass.class); + TemplateClass class2 = createMock(TemplateClass.class); + expect(class1.getName()).andReturn("class1"); + expect(class2.getName()).andReturn("class2"); + + replay(class1, class2); + List<TemplateClass> classes = new ArrayList<>(); + classes.add(class1); + classes.add(class2); + TemplateSuite suite = new TemplateSuite("name", "docs", classes); + assertEquals("name", suite.getName()); + assertEquals("docs", suite.getDocumentation()); + Iterator<TemplateClass> clazzes = suite.getTemplateClasses().iterator(); + assertSame(class1, clazzes.next()); + assertSame(class2, clazzes.next()); + assertFalse(clazzes.hasNext()); + assertSame(class1, suite.getTemplateClassByName("class1")); + assertSame(class2, suite.getTemplateClassByName("class2")); + verify(class1, class2); + } + + /** + * Test method for {@link TemplateSuite#addTemplateClass(TemplateClass)}. + */ + @Test + public void testAddTemplateClass() { + TemplateClass class1 = createMock(TemplateClass.class); + TemplateClass class2 = createMock(TemplateClass.class); + expect(class1.getName()).andReturn("class1"); + expect(class2.getName()).andReturn("class2"); + + replay(class1, class2); + TemplateSuite suite = new TemplateSuite("name", "docs"); + assertEquals("name", suite.getName()); + assertEquals("docs", suite.getDocumentation()); + assertTrue(suite.getTemplateClasses().isEmpty()); + suite.addTemplateClass(class1); + suite.addTemplateClass(class2); + Iterator<TemplateClass> clazzes = suite.getTemplateClasses().iterator(); + assertSame(class1, clazzes.next()); + assertSame(class2, clazzes.next()); + assertFalse(clazzes.hasNext()); + assertSame(class1, suite.getTemplateClassByName("class1")); + assertSame(class2, suite.getTemplateClassByName("class2")); + verify(class1, class2); + } + + /** + * Test method for {@link TemplateSuite#toString()}. + */ + @Test + public void testToString() { + TemplateSuite suite = new TemplateSuite("name", "docs"); + assertEquals("TemplateSuite [name=name, documentation=docs, templateClasses={}]", suite.toString()); + } +}