ko/archetype/src/main/resources/archetype-resources/src/test/java/TwitterClientTest.java
changeset 1272 3ee4ec9577bc
parent 1222 345274016cb9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ko/archetype/src/main/resources/archetype-resources/src/test/java/TwitterClientTest.java	Mon Sep 09 15:26:12 2013 +0200
     1.3 @@ -0,0 +1,50 @@
     1.4 +package ${package};
     1.5 +
     1.6 +import java.util.List;
     1.7 +import net.java.html.BrwsrCtx;
     1.8 +import net.java.html.json.Models;
     1.9 +import static org.testng.Assert.*;
    1.10 +import org.testng.annotations.BeforeMethod;
    1.11 +import org.testng.annotations.Test;
    1.12 +
    1.13 +/** We can unit test the TwitterModel smoothly.
    1.14 + */
    1.15 +public class TwitterClientTest {
    1.16 +    private TwitterModel model;
    1.17 +    
    1.18 +
    1.19 +    @BeforeMethod
    1.20 +    public void initModel() {
    1.21 +        model = Models.bind(new TwitterModel(), BrwsrCtx.EMPTY);
    1.22 +    }
    1.23 +
    1.24 +    @Test public void testIsValidToAdd() {
    1.25 +        model.setUserNameToAdd("Joe");
    1.26 +        Tweeters t = Models.bind(new Tweeters(), BrwsrCtx.EMPTY);
    1.27 +        t.setName("test");
    1.28 +        model.getSavedLists().add(t);
    1.29 +        model.setActiveTweetersName("test");
    1.30 +        
    1.31 +        assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
    1.32 +        TwitterClient.addUser(model);
    1.33 +        assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
    1.34 +        assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
    1.35 +        
    1.36 +        List<String> mod = model.getActiveTweeters();
    1.37 +        assertTrue(model.isHasUnsavedChanges(), "We have modifications");
    1.38 +        assertEquals(mod.size(), 1, "One element in the list");
    1.39 +        assertEquals(mod.get(0), "Joe", "Its name is Joe");
    1.40 +        
    1.41 +        assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
    1.42 +        
    1.43 +        TwitterClient.saveChanges(model);
    1.44 +        assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
    1.45 +        
    1.46 +        assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
    1.47 +    }
    1.48 +    
    1.49 +    @Test public void httpAtTheEnd() {
    1.50 +        String res = TwitterClient.Twt.html("Ahoj http://kuk");
    1.51 +        assertEquals(res, "Ahoj <a href='http://kuk'>http://kuk</a>");
    1.52 +    }
    1.53 +}