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 {
27 AServerInfo.NameProvider np = p;
28 AServerInfo.URLProvider up = p;
29 AServerInfo.ResetHandler res = p;
32 // BEGIN: aserverinfo.cumulative.creation
33 inf = AServerInfo.empty().nameProvider(np).urlProvider(up).reset(res);
34 // END: aserverinfo.cumulative.creation
36 assertEquals("API Design Server", inf.getName());
37 assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm());
39 assertEquals("Once reset", 1, p.resets);
44 public void showVerboseUseOfCumulativeFactory() throws Exception {
45 Prov prov = new Prov();
48 // BEGIN: aserverinfo.cumulative.creation.verbose
49 AServerInfo empty = AServerInfo.empty();
50 AServerInfo name = empty.nameProvider(prov);
51 AServerInfo urlAndName = name.urlProvider(prov);
52 info = urlAndName.reset(prov);
53 // END: aserverinfo.cumulative.creation.verbose
55 assertEquals("API Design Server", info.getName());
56 assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
58 assertEquals("Once reset", 1, prov.resets);
63 private static class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
66 public String getName() {
67 return "API Design Server";
72 return new URL("http://www.apidesign.org");
73 } catch (MalformedURLException ex) {
74 Exceptions.printStackTrace(ex);