-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shashi Bhushan
committed
Aug 23, 2016
1 parent
4b910c0
commit 46e22c6
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...test/slice-core-test/src/test/groovy/com/cognifide/slice/api/tag/SliceTagUtilsTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*- | ||
* #%L | ||
* Slice - Core Tests | ||
* %% | ||
* Copyright (C) 2012 Cognifide Limited | ||
* %% | ||
* Licensed 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. | ||
* #L% | ||
*/ | ||
|
||
package com.cognifide.slice.api.tag | ||
|
||
import com.cognifide.slice.test.setup.BaseSetup | ||
import org.apache.sling.api.scripting.SlingBindings | ||
import org.apache.sling.api.scripting.SlingScriptHelper | ||
import org.apache.sling.commons.classloader.DynamicClassLoaderManager | ||
import org.junit.Assert | ||
|
||
import javax.servlet.ServletRequest | ||
import javax.servlet.jsp.PageContext | ||
import java.lang.reflect.Method | ||
|
||
/** | ||
* @author Shashi Bhushan | ||
* Date: 23.08.16 | ||
*/ | ||
class SliceTagUtilsTest extends BaseSetup { | ||
|
||
def "Get Class object, given the String type"() { | ||
given: | ||
final PageContext pageContext = Mock(PageContext){ | ||
getRequest()>> Mock(ServletRequest){ | ||
getAttribute(_ as String) >> Mock(SlingBindings) { | ||
getSling() >> Mock(SlingScriptHelper) { | ||
getService(_ as Class) >> Mock(DynamicClassLoaderManager) { | ||
getDynamicClassLoader() >> Mock(ClassLoader) { | ||
loadClass(_ as String) >> SliceTagUtils.class | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
when: | ||
Class aClass = SliceTagUtils.getClassFromType(pageContext, "com.cognifide.slice.api.tag.SliceTagUtils"); | ||
|
||
then: "aClass object should not be null and should be equal to expected Class" | ||
Assert.assertNotNull(aClass) | ||
Assert.assertEquals(SliceTagUtils.class, aClass); | ||
} | ||
} |