samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:53:57 +0200
changeset 91 3280450405a0
child 114 c479228609ea
permissions -rw-r--r--
review2: Note about Tune and DVB Central. Finished example with AServerInfo
     1 package org.apidesign.aserverinfo;
     2 
     3 import java.net.MalformedURLException;
     4 import java.net.URL;
     5 import org.junit.After;
     6 import org.junit.Before;
     7 import org.junit.Test;
     8 import static org.junit.Assert.*;
     9 import org.openide.util.Exceptions;
    10 
    11 public class AServerInfoTest {
    12 
    13     public AServerInfoTest() {
    14     }
    15 
    16     @Before
    17     public void setUp() {
    18     }
    19 
    20     @After
    21     public void tearDown() {
    22     }
    23 
    24     @Test
    25     public void showUseOfCumulativeFactory() throws Exception {
    26         class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
    27             int resets;
    28             
    29             public String getName() {
    30                 return "API Design Server";
    31             }
    32 
    33             public URL getURL() {
    34                 try {
    35                     return new URL("http://www.apidesign.org");
    36                 } catch (MalformedURLException ex) {
    37                     Exceptions.printStackTrace(ex);
    38                     return null;
    39                 }
    40             }
    41 
    42             public void reset() {
    43                 resets++;
    44             }
    45             
    46         }
    47         
    48         Prov prov = new Prov();
    49         AServerInfo info;
    50         
    51         // BEGIN: aserverinfo.cumulative.creation
    52         info = AServerInfo.empty().nameProvider(prov).urlProvider(prov).reset(prov);
    53         // END: aserverinfo.cumulative.creation
    54         
    55         assertEquals("API Design Server", info.getName());
    56         assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
    57         info.reset();
    58         assertEquals("Once reset", 1, prov.resets);
    59         
    60     }
    61 }