private <T> Enumeration<T> getEnumeration(int type) {
   if (count == 0) {
     return Collections.emptyEnumeration();
   } else {
     return new Enumerator<>(type, false);
   }
 }
  @Test
  @SuppressWarnings("unchecked")
  public void testWithOrdering() throws IOException {
    URL url1 = new URL("file://jar1.jar");
    URL sci1 = new URL("jar:file://jar1.jar!/" + CONFIG_FILE);
    URL url2 = new URL("file://dir/");
    URL sci2 = new URL("file://dir/" + CONFIG_FILE);
    loader =
        EasyMock.createMockBuilder(WebappServiceLoader.class)
            .addMockedMethod("parseConfigFile", LinkedHashSet.class, URL.class)
            .withConstructor(context)
            .createMock(control);
    List<String> jars = Arrays.asList("jar1.jar", "dir/");
    EasyMock.expect(servletContext.getAttribute(ServletContext.ORDERED_LIBS)).andReturn(jars);
    EasyMock.expect(servletContext.getResource("/WEB-INF/lib/jar1.jar")).andReturn(url1);
    loader.parseConfigFile(EasyMock.isA(LinkedHashSet.class), EasyMock.eq(sci1));
    EasyMock.expect(servletContext.getResource("/WEB-INF/lib/dir/")).andReturn(url2);
    loader.parseConfigFile(EasyMock.isA(LinkedHashSet.class), EasyMock.eq(sci2));
    EasyMock.expect(parent.getResources(CONFIG_FILE))
        .andReturn(Collections.<URL>emptyEnumeration());

    control.replay();
    Assert.assertTrue(loader.load(ServletContainerInitializer.class).isEmpty());
    control.verify();
  }
Esempio n. 3
0
  private InetAddress getWiFiIP() {
    Enumeration<NetworkInterface> interfaces;
    try {
      interfaces = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
      interfaces = Collections.emptyEnumeration();
    }

    while (interfaces.hasMoreElements()) {
      NetworkInterface inter = interfaces.nextElement();
      if (inter.getDisplayName().equals("wlan0")) {
        List<InetAddress> addresses = Collections.list(inter.getInetAddresses());
        for (InetAddress address : addresses) {
          if (!address.isLoopbackAddress()
              && InetAddressUtils.isIPv4Address(address.getHostAddress())) {
            return address;
          }
        }
      }
    }

    InetAddress adr = null;
    try {
      adr = InetAddress.getByName("0.0.0.0");
    } catch (UnknownHostException e) {
      adr = null;
      e.printStackTrace();
    }
    return adr;
  }
 @Test
 public void testNoInitializersFound() throws IOException {
   loader = new WebappServiceLoader<>(context);
   EasyMock.expect(servletContext.getAttribute(ServletContext.ORDERED_LIBS)).andReturn(null);
   EasyMock.expect(cl.getResources(CONFIG_FILE)).andReturn(Collections.<URL>emptyEnumeration());
   control.replay();
   Assert.assertTrue(loader.load(ServletContainerInitializer.class).isEmpty());
   control.verify();
 }
 public Enumeration<String> getHeaders(String name) {
   String headerValue = headers.get(name);
   if (headerValue != null) {
     String[] multiValuedHeader = headerValue.split(",");
     return Collections.enumeration(Arrays.asList(multiValuedHeader));
   } else {
     return Collections.emptyEnumeration();
   }
 }
 public Enumeration<String> getInitParameterNames() {
   return Collections.emptyEnumeration();
 }
Esempio n. 7
0
 @Override
 public Enumeration<String> doGetAttributeNames() {
   return Collections.emptyEnumeration();
 }
Esempio n. 8
0
 /**
  * Finds an enumeration of URLs for the resource with the specified name. This implementation just
  * returns an empty {@code Enumeration}; it should be overridden in subclasses.
  *
  * @param resName the name of the resource to find.
  * @return an enumeration of {@code URL} objects for the requested resource.
  * @throws IOException if an I/O error occurs.
  */
 protected Enumeration<URL> findResources(String resName) throws IOException {
   return Collections.emptyEnumeration();
 }