samples/aserverinfo/test/org/apidesign/aserverinfo/AServerInfoTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 09 Nov 2008 16:20:01 +0100
changeset 291 9cbb8364c4ae
parent 154 0fd5e9c500b9
permissions -rw-r--r--
Renaming arguments
jtulach@91
     1
package org.apidesign.aserverinfo;
jtulach@91
     2
jtulach@91
     3
import java.net.MalformedURLException;
jtulach@91
     4
import java.net.URL;
jtulach@91
     5
import org.junit.After;
jtulach@91
     6
import org.junit.Before;
jtulach@91
     7
import org.junit.Test;
jtulach@91
     8
import static org.junit.Assert.*;
jtulach@91
     9
import org.openide.util.Exceptions;
jtulach@91
    10
jtulach@91
    11
public class AServerInfoTest {
jtulach@91
    12
jtulach@91
    13
    public AServerInfoTest() {
jtulach@91
    14
    }
jtulach@91
    15
jtulach@91
    16
    @Before
jtulach@91
    17
    public void setUp() {
jtulach@91
    18
    }
jtulach@91
    19
jtulach@91
    20
    @After
jtulach@91
    21
    public void tearDown() {
jtulach@91
    22
    }
jtulach@91
    23
jtulach@91
    24
    @Test
jtulach@91
    25
    public void showUseOfCumulativeFactory() throws Exception {
jtulach@154
    26
        Prov p = new Prov();
jtulach@291
    27
        AServerInfo.NameProvider np = p;
jtulach@291
    28
        AServerInfo.URLProvider up = p;
jtulach@291
    29
        AServerInfo.ResetHandler res = p;
jtulach@154
    30
        AServerInfo inf;
jtulach@91
    31
        
jtulach@91
    32
        // BEGIN: aserverinfo.cumulative.creation
jtulach@291
    33
        inf = AServerInfo.empty().nameProvider(np).urlProvider(up).reset(res);
jtulach@91
    34
        // END: aserverinfo.cumulative.creation
jtulach@91
    35
        
jtulach@154
    36
        assertEquals("API Design Server", inf.getName());
jtulach@154
    37
        assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm());
jtulach@154
    38
        inf.reset();
jtulach@154
    39
        assertEquals("Once reset", 1, p.resets);
jtulach@91
    40
        
jtulach@91
    41
    }
jtulach@114
    42
    
jtulach@114
    43
    @Test
jtulach@114
    44
    public void showVerboseUseOfCumulativeFactory() throws Exception {
jtulach@114
    45
        Prov prov = new Prov();
jtulach@114
    46
        AServerInfo info;
jtulach@114
    47
        
jtulach@114
    48
        // BEGIN: aserverinfo.cumulative.creation.verbose
jtulach@114
    49
        AServerInfo empty = AServerInfo.empty();
jtulach@114
    50
        AServerInfo name = empty.nameProvider(prov);
jtulach@114
    51
        AServerInfo urlAndName = name.urlProvider(prov);
jtulach@114
    52
        info = urlAndName.reset(prov);
jtulach@114
    53
        // END: aserverinfo.cumulative.creation.verbose
jtulach@114
    54
        
jtulach@114
    55
        assertEquals("API Design Server", info.getName());
jtulach@114
    56
        assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
jtulach@114
    57
        info.reset();
jtulach@114
    58
        assertEquals("Once reset", 1, prov.resets);
jtulach@114
    59
        
jtulach@114
    60
    }
jtulach@114
    61
    
jtulach@114
    62
    
jtulach@114
    63
    private static class Prov implements AServerInfo.NameProvider, AServerInfo.URLProvider, AServerInfo.ResetHandler {
jtulach@114
    64
        int resets;
jtulach@114
    65
jtulach@114
    66
        public String getName() {
jtulach@114
    67
            return "API Design Server";
jtulach@114
    68
        }
jtulach@114
    69
jtulach@114
    70
        public URL getURL() {
jtulach@114
    71
            try {
jtulach@114
    72
                return new URL("http://www.apidesign.org");
jtulach@114
    73
            } catch (MalformedURLException ex) {
jtulach@114
    74
                Exceptions.printStackTrace(ex);
jtulach@114
    75
                return null;
jtulach@114
    76
            }
jtulach@114
    77
        }
jtulach@114
    78
jtulach@114
    79
        public void reset() {
jtulach@114
    80
            resets++;
jtulach@114
    81
        }
jtulach@114
    82
jtulach@114
    83
    }
jtulach@114
    84
        
jtulach@91
    85
}