twitter/src/test/java/org/apidesign/html/demo/twitter/TwitterClientTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Tue, 13 Aug 2013 21:11:28 +0200
changeset 44 e3305312184c
parent 0 6fe609b8f0fb
permissions -rw-r--r--
Simplified, rewritten to 0.4 and made compilable on JDK8
     1 /**
     2  * The MIT License (MIT)
     3  *
     4  * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5  *
     6  * Permission is hereby granted, free of charge, to any person obtaining a copy
     7  * of this software and associated documentation files (the "Software"), to deal
     8  * in the Software without restriction, including without limitation the rights
     9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    10  * copies of the Software, and to permit persons to whom the Software is
    11  * furnished to do so, subject to the following conditions:
    12  *
    13  * The above copyright notice and this permission notice shall be included in
    14  * all copies or substantial portions of the Software.
    15  *
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    22  * THE SOFTWARE.
    23  */
    24 package org.apidesign.html.demo.twitter;
    25 
    26 import java.util.List;
    27 import static org.testng.Assert.*;
    28 import org.testng.annotations.BeforeMethod;
    29 import org.testng.annotations.Test;
    30 
    31 /** We can unit test the TwitterModel smoothly.
    32  *
    33  * @author Jaroslav Tulach <jtulach@netbeans.org>
    34  */
    35 public class TwitterClientTest {
    36     private TwitterModel model;
    37     
    38 
    39     @BeforeMethod
    40     public void initModel() {
    41         model = new TwitterModel();
    42     }
    43 
    44     @Test public void testIsValidToAdd() {
    45         model.setUserNameToAdd("Joe");
    46         Tweeters t = new Tweeters();
    47         t.setName("test");
    48         model.getSavedLists().add(t);
    49         model.setActiveTweetersName("test");
    50         
    51         assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
    52         TwitterClient.addUser(model);
    53         assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
    54         assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
    55         
    56         List<String> mod = model.getActiveTweeters();
    57         assertTrue(model.isHasUnsavedChanges(), "We have modifications");
    58         assertEquals(mod.size(), 1, "One element in the list");
    59         assertEquals(mod.get(0), "Joe", "Its name is Joe");
    60         
    61         assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
    62         
    63         TwitterClient.saveChanges(model);
    64         assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
    65         
    66         assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
    67     }
    68     
    69     @Test public void httpAtTheEnd() {
    70         String res = TwitterClient.Twt.html("Ahoj http://kuk");
    71         assertEquals(res, "Ahoj <a href='http://kuk'>http://kuk</a>");
    72     }
    73 }