List of usage examples for java.util Collections emptyEnumeration
@SuppressWarnings("unchecked") public static <T> Enumeration<T> emptyEnumeration()
From source file:org.openqa.grid.internal.listener.CommandListenerTest.java
@Test public void canModifyResponseWithListener() throws IOException { Registry registry = Registry.newInstance(); registry.add(new MyRemoteProxy(req, registry)); RequestHandler req = GridHelper.createNewSessionHandler(registry, app1); req.process();/*from w ww. j av a 2 s. c o m*/ TestSession session = req.getSession(); // Mock the request so it seems like a new session SeleniumBasedRequest request = mock(SeleniumBasedRequest.class); when(request.getRequestURI()).thenReturn("session"); when(request.getServletPath()).thenReturn("session"); when(request.getContextPath()).thenReturn(""); when(request.getMethod()).thenReturn("GET"); Enumeration<String> strings = Collections.emptyEnumeration(); when(request.getHeaderNames()).thenReturn(strings); HttpServletResponse response = mock(HttpServletResponse.class); ServletOutputStream stream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(stream); session.forward(request, response, true); // When the output stream is being written back to the remote, it should // only contain the bits we modified in // MyRemoteProxy's afterCommand method verify(stream).write(responseBytes); }
From source file:io.nebo.container.NettyEmbeddedContext.java
@Override public Enumeration<String> getAttributeNames() { return Collections.emptyEnumeration(); }
From source file:com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.java
@Override public Enumeration<String> getHeaderNames() { if (request.getHeaders() == null) { return Collections.emptyEnumeration(); }/* ww w . j av a2 s .c o m*/ return Collections.enumeration(request.getHeaders().keySet()); }
From source file:javarestart.WebClassLoader.java
/** * Returns none or zero resources: it just wraps findResource now. * TODO: extend client-server protocol to support fetching multiple resources by the given name. */// w w w . jav a2s. c o m @Override public Enumeration<URL> findResources(String name) throws IOException { URL url = findResource(name); if (url == null) return Collections.emptyEnumeration(); return new Enumeration<URL>() { private boolean hasMore = true; @Override public boolean hasMoreElements() { return hasMore; } @Override public URL nextElement() { hasMore = false; return url; } }; }
From source file:com.astamuse.asta4d.web.test.dispatch.RequestDispatcherTest.java
@Test(dataProvider = "data") public void execute(String method, String url, int status, ContentProvider contentProvider) throws Exception { WebApplicationContext context = (WebApplicationContext) Context.getCurrentThreadContext(); HttpServletRequest request = context.getRequest(); HttpServletResponse response = context.getResponse(); HttpSession session = mock(HttpSession.class); when(request.getParameterNames()).thenReturn(Collections.emptyEnumeration()); when(request.getCookies()).thenReturn(new Cookie[0]); when(request.getHeaderNames()).thenReturn(Collections.emptyEnumeration()); when(request.getSession(true)).thenReturn(session); when(request.getRequestURI()).thenReturn(url); when(request.getContextPath()).thenReturn(""); when(request.getMethod()).thenReturn(method); final ByteArrayOutputStream responseBos = new ByteArrayOutputStream(); when(response.getOutputStream()).thenReturn(new ServletOutputStream() { @Override/*from w w w.j a v a2 s . c om*/ public void write(int b) throws IOException { responseBos.write(b); } }); HandyRuleSet ruleSet = new HandyRuleSet(); initTestRules(ruleSet); if (url.equals("/index-rewrite")) { context.setAccessURI("/index"); } dispatcher.dispatchAndProcess(ruleSet.getArrangedRuleList()); // verify status at first then when contentProvider is null, we do not // need to do more verification if (status != 0) { verify(response).setStatus(status); } if (contentProvider == null) { return; } // prepare expected results HttpServletResponse expectedResponse = mock(HttpServletResponse.class); final ByteArrayOutputStream expectedBos = new ByteArrayOutputStream(); when(expectedResponse.getOutputStream()).thenReturn(new ServletOutputStream() { @Override public void write(int b) throws IOException { expectedBos.write(b); } }); final List<Pair<String, String>> expectedHeaderList = new LinkedList<>(); doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); expectedHeaderList.add(Pair.of((String) args[0], (String) args[1])); return null; } }).when(expectedResponse).addHeader(anyString(), anyString()); UrlMappingRule currentRule = context.getCurrentRule(); contentProvider.produce(currentRule, expectedResponse); // verify extra contents like headers and output stream for (Pair<String, String> pair : expectedHeaderList) { verify(response).addHeader(pair.getKey(), pair.getValue()); } Assert.assertEquals(new String(responseBos.toByteArray()), new String(expectedBos.toByteArray())); }
From source file:com.feilong.core.bean.ConvertUtilTest.java
/** * Test to enumeration. */ @Test public void testToEnumeration() { assertEquals(Collections.emptyEnumeration(), ConvertUtil.toEnumeration(null)); }