1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java Sat Jun 14 09:53:57 2008 +0200
1.3 @@ -0,0 +1,61 @@
1.4 +package org.apidesign.aserverinfo;
1.5 +
1.6 +import java.net.MalformedURLException;
1.7 +import java.net.URL;
1.8 +import org.junit.After;
1.9 +import org.junit.Before;
1.10 +import org.junit.Test;
1.11 +import static org.junit.Assert.*;
1.12 +import org.openide.util.Exceptions;
1.13 +
1.14 +public class AServerInfoTest {
1.15 +
1.16 + public AServerInfoTest() {
1.17 + }
1.18 +
1.19 + @Before
1.20 + public void setUp() {
1.21 + }
1.22 +
1.23 + @After
1.24 + public void tearDown() {
1.25 + }
1.26 +
1.27 + @Test
1.28 + public void showUseOfCumulativeFactory() throws Exception {
1.29 + class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
1.30 + int resets;
1.31 +
1.32 + public String getName() {
1.33 + return "API Design Server";
1.34 + }
1.35 +
1.36 + public URL getURL() {
1.37 + try {
1.38 + return new URL("http://www.apidesign.org");
1.39 + } catch (MalformedURLException ex) {
1.40 + Exceptions.printStackTrace(ex);
1.41 + return null;
1.42 + }
1.43 + }
1.44 +
1.45 + public void reset() {
1.46 + resets++;
1.47 + }
1.48 +
1.49 + }
1.50 +
1.51 + Prov prov = new Prov();
1.52 + AServerInfo info;
1.53 +
1.54 + // BEGIN: aserverinfo.cumulative.creation
1.55 + info = AServerInfo.empty().nameProvider(prov).urlProvider(prov).reset(prov);
1.56 + // END: aserverinfo.cumulative.creation
1.57 +
1.58 + assertEquals("API Design Server", info.getName());
1.59 + assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
1.60 + info.reset();
1.61 + assertEquals("Once reset", 1, prov.resets);
1.62 +
1.63 + }
1.64 +}
1.65 \ No newline at end of file