@Test public void shouldThreatViewURIAsAjax() { final HttpServletRequest request = mockery.mock(HttpServletRequest.class); mockery.checking( new Expectations() { { allowing(request).getRequestURI(); will(returnValue("somethig.ajax.logic")); } }); DefaultComponentInfoProvider info = new DefaultComponentInfoProvider(request); assertThat(info.isAjax(), is(equalTo(true))); mockery.assertIsSatisfied(); }
@Test public void shouldNormalURIAsNotAjax() { final HttpServletRequest request = mockery.mock(HttpServletRequest.class); mockery.checking( new Expectations() { { allowing(request).getRequestURI(); will(returnValue("somethig.non-ajax.logic")); allowing(request).getParameter("view"); will(returnValue("xml")); } }); DefaultComponentInfoProvider info = new DefaultComponentInfoProvider(request); assertThat(info.isAjax(), is(equalTo(false))); mockery.assertIsSatisfied(); }
@Test public void shouldThreatViewlessAsNonDisplayView() throws NoSuchMethodException { ResourceMethod method = mockery.methodFor(DefaultComponents.class, "nothing"); final HttpServletRequest request = mockery.mock(HttpServletRequest.class); mockery.checking( new Expectations() { { allowing(request).getRequestURI(); will(returnValue("somethig.whatever.logic")); allowing(request).getParameter("view"); will(returnValue(null)); } }); DefaultComponentInfoProvider info = new DefaultComponentInfoProvider(request); assertThat(info.shouldShowView(method), is(equalTo(false))); mockery.assertIsSatisfied(); }
@Test public void shouldThreatNormalMethod() throws NoSuchMethodException { final HttpServletRequest request = mockery.mock(HttpServletRequest.class); mockery.checking( new Expectations() { { allowing(request).getRequestURI(); will(returnValue("somethig.non-ajax.logic")); allowing(request).getParameter("view"); will(returnValue("xml")); } }); ResourceMethod method = mockery.methodFor(DefaultComponents.class, "showIt"); DefaultComponentInfoProvider info = new DefaultComponentInfoProvider(request); assertThat(info.shouldShowView(method), is(equalTo(true))); mockery.assertIsSatisfied(); }