1 package org.apidesign.aserverinfo;
3 import java.net.MalformedURLException;
5 import org.junit.After;
6 import org.junit.Before;
8 import static org.junit.Assert.*;
9 import org.openide.util.Exceptions;
11 public class AServerInfoTest {
13 public AServerInfoTest() {
21 public void tearDown() {
25 public void showUseOfCumulativeFactory() throws Exception {
29 // BEGIN: aserverinfo.cumulative.creation
30 inf = AServerInfo.empty().nameProvider(p).urlProvider(p).reset(p);
31 // END: aserverinfo.cumulative.creation
33 assertEquals("API Design Server", inf.getName());
34 assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm());
36 assertEquals("Once reset", 1, p.resets);
41 public void showVerboseUseOfCumulativeFactory() throws Exception {
42 Prov prov = new Prov();
45 // BEGIN: aserverinfo.cumulative.creation.verbose
46 AServerInfo empty = AServerInfo.empty();
47 AServerInfo name = empty.nameProvider(prov);
48 AServerInfo urlAndName = name.urlProvider(prov);
49 info = urlAndName.reset(prov);
50 // END: aserverinfo.cumulative.creation.verbose
52 assertEquals("API Design Server", info.getName());
53 assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
55 assertEquals("Once reset", 1, prov.resets);
60 private static class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
63 public String getName() {
64 return "API Design Server";
69 return new URL("http://www.apidesign.org");
70 } catch (MalformedURLException ex) {
71 Exceptions.printStackTrace(ex);