ko-archetype/src/main/resources/archetype-resources/src/test/java/TwitterClientTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 13 May 2013 14:25:37 +0200
changeset 1202 5f04bdbc6ee1
child 1222 345274016cb9
permissions -rw-r--r--
Moving archetype tests into separate module - at that moment it is possible to use the previously generated archetype
     1 package ${package};
     2 
     3 import java.util.List;
     4 import net.java.html.json.Context;
     5 import static org.testng.Assert.*;
     6 import org.testng.annotations.BeforeMethod;
     7 import org.testng.annotations.Test;
     8 
     9 /** We can unit test the TwitterModel smoothly.
    10  */
    11 public class TwitterClientTest {
    12     private TwitterModel model;
    13     
    14 
    15     @BeforeMethod
    16     public void initModel() {
    17         model = new TwitterModel(Context.EMPTY);
    18     }
    19 
    20     @Test public void testIsValidToAdd() {
    21         model.setUserNameToAdd("Joe");
    22         Tweeters t = new Tweeters(Context.EMPTY);
    23         t.setName("test");
    24         model.getSavedLists().add(t);
    25         model.setActiveTweetersName("test");
    26         
    27         assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
    28         TwitterClient.addUser(model);
    29         assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
    30         assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
    31         
    32         List<String> mod = model.getActiveTweeters();
    33         assertTrue(model.isHasUnsavedChanges(), "We have modifications");
    34         assertEquals(mod.size(), 1, "One element in the list");
    35         assertEquals(mod.get(0), "Joe", "Its name is Joe");
    36         
    37         assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
    38         
    39         TwitterClient.saveChanges(model);
    40         assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
    41         
    42         assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
    43     }
    44     
    45     @Test public void httpAtTheEnd() {
    46         String res = TwitterClient.Twt.html("Ahoj http://kuk");
    47         assertEquals(res, "Ahoj <a href='http://kuk'>http://kuk</a>");
    48     }
    49 }