ASF Bugzilla – Attachment 25691 Details for
Bug 49546
Add test cases for SetSupport
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Add test cases for determining result
taglibs-49546.patch (text/plain), 6.75 KB, created by
Jeremy Boynes
on 2010-07-03 11:54:54 UTC
(
hide
)
Description:
Add test cases for determining result
Filename:
MIME Type:
Creator:
Jeremy Boynes
Created:
2010-07-03 11:54:54 UTC
Size:
6.75 KB
patch
obsolete
>Index: src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java >=================================================================== >--- src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java (revision 960224) >+++ src/test/java/org/apache/taglibs/standard/tag/common/core/TestSetSupport.java (working copy) >@@ -16,6 +16,7 @@ > */ > package org.apache.taglibs.standard.tag.common.core; > >+import org.junit.Assert; > import org.junit.Before; > import org.junit.Test; > >@@ -24,6 +25,7 @@ > import javax.el.VariableMapper; > import javax.servlet.jsp.JspException; > import javax.servlet.jsp.PageContext; >+import javax.servlet.jsp.tagext.BodyContent; > > import static org.easymock.EasyMock.createMock; > import static org.easymock.EasyMock.expect; >@@ -31,6 +33,8 @@ > import static org.easymock.EasyMock.verify; > > public class TestSetSupport { >+ private static String VALUE = "Hello"; >+ private static final String VAR = "x"; > > private PageContext pageContext; > private ELContext elContext; >@@ -39,13 +43,15 @@ > > @Before > public void setup() { >- tag = new SetSupport(); > pageContext = createMock(PageContext.class); > elContext = createMock(ELContext.class); > vm = createMock(VariableMapper.class); > > expect(pageContext.getELContext()).andStubReturn(elContext); > expect(elContext.getVariableMapper()).andStubReturn(vm); >+ >+ tag = new SetSupport(); >+ tag.setPageContext(pageContext); > } > > /** >@@ -55,13 +61,12 @@ > */ > @Test > public void test49526WhenNotMapped() throws JspException { >- tag.setPageContext(pageContext); >- tag.setVar("x"); >- tag.value = "Hello"; >+ tag.setVar(VAR); >+ tag.value = VALUE; > > // verify mapper is checked but that no action is taken >- expect(vm.resolveVariable("x")).andReturn(null); >- pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE); >+ expect(vm.resolveVariable(VAR)).andReturn(null); >+ pageContext.setAttribute(VAR, VALUE, PageContext.PAGE_SCOPE); > replay(pageContext, elContext, vm); > tag.doEndTag(); > verify(pageContext, elContext, vm); >@@ -74,15 +79,14 @@ > */ > @Test > public void test49526WhenAlreadyMapped() throws JspException { >- tag.setPageContext(pageContext); >- tag.setVar("x"); >- tag.value = "Hello"; >+ tag.setVar(VAR); >+ tag.value = VALUE; > > // verify mapper is checked and the mapped variable removed > ValueExpression ve = createMock(ValueExpression.class); >- expect(vm.resolveVariable("x")).andReturn(ve); >- expect(vm.setVariable("x", null)).andReturn(ve); >- pageContext.setAttribute("x", "Hello", PageContext.PAGE_SCOPE); >+ expect(vm.resolveVariable(VAR)).andReturn(ve); >+ expect(vm.setVariable(VAR, null)).andReturn(ve); >+ pageContext.setAttribute(VAR, VALUE, PageContext.PAGE_SCOPE); > replay(pageContext, elContext, vm, ve); > tag.doEndTag(); > verify(pageContext, elContext, vm, ve); >@@ -95,15 +99,53 @@ > */ > @Test > public void test49526WhenNotUsingPageContext() throws JspException { >- tag.setPageContext(pageContext); >- tag.setVar("x"); >- tag.value = "Hello"; >+ tag.setVar(VAR); >+ tag.value = VALUE; > tag.setScope("request"); > > // verify mapper is not checked >- pageContext.setAttribute("x", "Hello", PageContext.REQUEST_SCOPE); >+ pageContext.setAttribute(VAR, VALUE, PageContext.REQUEST_SCOPE); > replay(pageContext, elContext, vm); > tag.doEndTag(); > verify(pageContext, elContext, vm); > } >+ >+ @Test >+ public void testResultFromValueAttribute() { >+ tag.valueSpecified = true; >+ tag.value = VALUE; >+ Assert.assertSame(VALUE, tag.getResult()); >+ } >+ >+ @Test >+ public void testResultFromNullValueAttribute() { >+ tag.valueSpecified = true; >+ tag.value = null; >+ Assert.assertNull(tag.getResult()); >+ } >+ >+ @Test >+ public void testResultFromBodyContent() { >+ tag.valueSpecified = false; >+ BodyContent bodyContent = createMock(BodyContent.class); >+ expect(bodyContent.getString()).andStubReturn(" Hello "); >+ replay(bodyContent); >+ tag.setBodyContent(bodyContent); >+ Assert.assertEquals(VALUE, tag.getResult()); >+ } >+ >+ @Test >+ public void testResultFromNullBodyContent() { >+ tag.valueSpecified = false; >+ tag.setBodyContent(null); >+ Assert.assertEquals("", tag.getResult()); >+ } >+ >+ @Test >+ public void testResultFromEmptyBodyContent() { >+ tag.valueSpecified = false; >+ BodyContent bodyContent = createMock(BodyContent.class); >+ expect(bodyContent.getString()).andStubReturn(null); >+ Assert.assertEquals("", tag.getResult()); >+ } > } >Index: src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java >=================================================================== >--- src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java (revision 960224) >+++ src/main/java/org/apache/taglibs/standard/tag/common/core/SetSupport.java (working copy) >@@ -91,23 +91,9 @@ > > public int doEndTag() throws JspException { > >- Object result; // what we'll store in scope:var >+ // what we'll store in scope:var >+ Object result = getResult(); > >- // determine the value by... >- if (value != null) { >- // ... reading our attribute >- result = value; >- } else if (valueSpecified) { >- // ... accepting an explicit null >- result = null; >- } else { >- // ... retrieving and trimming our body >- if (bodyContent == null || bodyContent.getString() == null) >- result = ""; >- else >- result = bodyContent.getString().trim(); >- } >- > // decide what to do with the result > if (var != null) { > >@@ -196,6 +182,27 @@ > return EVAL_PAGE; > } > >+ Object getResult() { >+ Object result; // what we'll store in scope:var >+ >+ // determine the value by... >+ if (value != null) { >+ // ... reading our attribute >+ result = value; >+ } else if (valueSpecified) { >+ // ... accepting an explicit null >+ result = null; >+ } else { >+ // ... retrieving and trimming our body >+ if (bodyContent == null || bodyContent.getString() == null) >+ result = ""; >+ else >+ result = bodyContent.getString().trim(); >+ } >+ >+ return result; >+ } >+ > /** > * Convert an object to an expected type according to the conversion > * rules of the Expression Language.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 49546
: 25691