javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClientTest.java
branchmodel
changeset 931 9a7df12648b9
child 955 dad881565d0a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/javaquery/demo-twitter/src/test/java/org/apidesign/bck2brwsr/demo/twitter/TwitterClientTest.java	Thu Apr 04 13:12:17 2013 +0200
     1.3 @@ -0,0 +1,66 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator
     1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. Look for COPYING file in the top folder.
    1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +package org.apidesign.bck2brwsr.demo.twitter;
    1.22 +
    1.23 +import static org.testng.Assert.*;
    1.24 +import org.testng.annotations.BeforeMethod;
    1.25 +import org.testng.annotations.Test;
    1.26 +
    1.27 +/** We can unit test the TwitterModel smoothly.
    1.28 + *
    1.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.30 + */
    1.31 +public class TwitterClientTest {
    1.32 +    private TwitterModel model;
    1.33 +    
    1.34 +
    1.35 +    @BeforeMethod
    1.36 +    public void initModel() {
    1.37 +        model = new TwitterModel().applyBindings();
    1.38 +    }
    1.39 +
    1.40 +    @Test public void testIsValidToAdd() {
    1.41 +        model.setUserNameToAdd("Joe");
    1.42 +        Tweeters t = new Tweeters();
    1.43 +        t.setName("test");
    1.44 +        model.getSavedLists().add(t);
    1.45 +        model.setActiveTweetersName("test");
    1.46 +        
    1.47 +        assertTrue(model.isUserNameToAddIsValid(), "Joe is OK");
    1.48 +        TwitterClient.addUser(model);
    1.49 +        assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time");
    1.50 +        assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty");
    1.51 +        
    1.52 +        Tweeters mod = model.getModifiedList();
    1.53 +        assertNotNull(mod, "Modified list is not filled in");
    1.54 +        assertTrue(model.isHasUnsavedChanges(), "We have modifications");
    1.55 +        assertEquals(mod.getUserNames().size(), 1, "One element in the list");
    1.56 +        assertEquals(mod.getUserNames().get(0), "Joe", "Its name is Joe");
    1.57 +        
    1.58 +        assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one");
    1.59 +        
    1.60 +        TwitterClient.saveChanges(model);
    1.61 +        assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save");
    1.62 +        assertNull(model.getModifiedList(), "No list modified");
    1.63 +        
    1.64 +        assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one");
    1.65 +        
    1.66 +        assertFalse(model.getSavedLists().contains(t), "No longer contains old list");
    1.67 +    }
    1.68 +    
    1.69 +}