Example #1
0
  public MockCatalogBuilder style(String name) {
    String filename = name + ".sld";
    if (getClass().getResourceAsStream(filename) == null) {
      return this;
    }

    String sId = newId();
    Version version = Styles.Handler.SLD_10.getVersion();

    final StyleInfo s = createNiceMock(StyleInfo.class);
    styles.add(s);

    expect(s.getId()).andReturn(sId);
    expect(s.getName()).andReturn(name).anyTimes();
    expect(s.getFilename()).andReturn(filename).anyTimes();
    expect(s.getSLDVersion()).andReturn(version).anyTimes();
    try {
      expect(s.getStyle())
          .andReturn(
              Styles.style(Styles.parse(getClass().getResourceAsStream(filename), null, version)))
          .anyTimes();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    expect(catalog.getStyle(sId)).andReturn(s).anyTimes();
    expect(catalog.getStyleByName(name)).andReturn(s).anyTimes();

    s.accept((CatalogVisitor) anyObject());
    expectLastCall()
        .andAnswer(
            new VisitAnswer() {
              @Override
              protected void doVisit(CatalogVisitor visitor) {
                visitor.visit(s);
              }
            })
        .anyTimes();

    callback.onStyle(name, s, this);
    replay(s);
    return this;
  }