public void testHttpOpenHandler() throws MalformedURLException {
    LineConvertor convertor = LineConvertors.httpUrl();

    List<ConvertedLine> lines = new ArrayList<ConvertedLine>();
    assertNull(convertor.convert("nourl1"));
    lines.addAll(convertor.convert("NetBeans site: http://www.netbeans.org"));
    lines.addAll(convertor.convert("https://www.netbeans.org"));

    assertEquals(2, lines.size());
    assertEquals("NetBeans site: http://www.netbeans.org", lines.get(0).getText());
    assertEquals("https://www.netbeans.org", lines.get(1).getText());

    for (ConvertedLine line : lines) {
      assertNotNull(line.getListener());
      line.getListener().outputLineAction(null);
    }

    HttpOpenHandler handler = Lookup.getDefault().lookup(HttpOpenHandler.class);
    assertTrue(handler instanceof TestHttpOpenHandler);

    List<URL> opened = ((TestHttpOpenHandler) handler).getOpened();
    assertEquals(2, opened.size());
    assertEquals(new URL("http://www.netbeans.org"), opened.get(0));
    assertEquals(new URL("https://www.netbeans.org"), opened.get(1));
  }
  public void testFilePattern() {
    TestConvertor fallback = new TestConvertor();
    LineConvertor convertor =
        LineConvertors.proxy(
            LineConvertors.filePattern(
                null, Pattern.compile("myline:\\s*(myfile\\w*\\.\\w{3})\\s.*"), null, 1, -1),
            fallback);

    List<ConvertedLine> lines = new ArrayList<ConvertedLine>();
    lines.addAll(convertor.convert("otherline: something.txt"));
    lines.addAll(convertor.convert("myline: myfile01.txt other stuff"));
    lines.addAll(convertor.convert("total mess"));
    lines.addAll(convertor.convert("myline: myfile02.txt other stuff"));
    lines.addAll(convertor.convert("otherline: http://www.netbeans.org"));

    List<String> ignored = new ArrayList<String>();
    Collections.addAll(
        ignored, "otherline: something.txt", "total mess", "otherline: http://www.netbeans.org");
    assertEquals(ignored, fallback.getLines());

    assertEquals(2, lines.size());
    assertEquals("myline: myfile01.txt other stuff", lines.get(0).getText());
    assertEquals("myline: myfile02.txt other stuff", lines.get(1).getText());

    for (ConvertedLine line : lines) {
      assertNotNull(line.getListener());
    }
  }
  public void testFilePatternWithLocator() {
    TestConvertor fallback = new TestConvertor();
    TestFileLocator locator = new TestFileLocator();

    LineConvertor convertor =
        LineConvertors.proxy(
            LineConvertors.filePattern(
                locator, Pattern.compile("myline:\\s*(myfile\\w*\\.\\w{3})\\s.*"), null, 1, -1),
            fallback);

    List<ConvertedLine> lines = new ArrayList<ConvertedLine>();
    lines.addAll(convertor.convert("myline: myfile01.txt other stuff"));
    lines.addAll(convertor.convert("myline: myfile02.txt other stuff"));

    assertEquals(2, lines.size());
    assertEquals("myline: myfile01.txt other stuff", lines.get(0).getText());
    assertEquals("myline: myfile02.txt other stuff", lines.get(1).getText());

    for (ConvertedLine line : lines) {
      line.getListener()
          .outputLineAction(
              new OutputEvent(InputOutput.NULL) {
                @Override
                public String getLine() {
                  return "line";
                }
              });
    }

    List<String> paths = new ArrayList<String>();
    Collections.addAll(paths, "myfile01.txt", "myfile02.txt");
    assertEquals(paths, locator.getPaths());
  }
  public void testHttpUrl() {
    TestConvertor fallback = new TestConvertor();
    LineConvertor convertor = LineConvertors.proxy(LineConvertors.httpUrl(), fallback);

    List<ConvertedLine> lines = new ArrayList<ConvertedLine>();
    lines.addAll(convertor.convert("nourl1"));
    lines.addAll(convertor.convert("NetBeans site: http://www.netbeans.org"));
    lines.addAll(convertor.convert("nourl2"));
    lines.addAll(convertor.convert("https://www.netbeans.org"));
    lines.addAll(convertor.convert("nourl3"));

    List<String> ignored = new ArrayList<String>();
    Collections.addAll(ignored, "nourl1", "nourl2", "nourl3");
    assertEquals(ignored, fallback.getLines());

    assertEquals(2, lines.size());
    assertEquals("NetBeans site: http://www.netbeans.org", lines.get(0).getText());
    assertEquals("https://www.netbeans.org", lines.get(1).getText());

    for (ConvertedLine line : lines) {
      assertNotNull(line.getListener());
    }
  }