Skip to content

Commit

Permalink
Minor changes in Spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashi Bhushan committed Aug 23, 2016
1 parent 46e22c6 commit 572e333
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public void doTag() throws JspException {
}

final PageContext pageContext = (PageContext) getJspContext();
final Class typeClass = SliceTagUtils.getClassFromType(pageContext, type);
final Object model = SliceTagUtils.getFromCurrentPath(pageContext, typeClass, appName);
final Class classObject = SliceTagUtils.getClassFromType(pageContext, type);
final Object model = SliceTagUtils.getFromCurrentPath(pageContext, classObject, appName);
pageContext.setAttribute(var, model, PageContext.PAGE_SCOPE);
} catch (ClassNotFoundException e) {
} catch (ClassNotFoundException cause) {
throw new JspTagException("Could not get class for " + type);
} finally {
clean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ import java.lang.reflect.Method
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
loadClass(_ as String) >> Class.forName(classList.className)
}
}
}
Expand All @@ -53,10 +54,18 @@ class SliceTagUtilsTest extends BaseSetup {
}

when:
Class aClass = SliceTagUtils.getClassFromType(pageContext, "com.cognifide.slice.api.tag.SliceTagUtils");
Class classObject = SliceTagUtils.getClassFromType(pageContext, classList.className);

then: "classObject should not be null and should be equal to expected Class"
Assert.assertNotNull(classObject)
Assert.assertEquals(classList.classObject, classObject);

then: "aClass object should not be null and should be equal to expected Class"
Assert.assertNotNull(aClass)
Assert.assertEquals(SliceTagUtils.class, aClass);
where:
classList << [
[
className : "com.cognifide.slice.api.tag.SliceTagUtils",
classObject : SliceTagUtils.class
]
]
}
}

0 comments on commit 572e333

Please sign in to comment.