jaroslav@931: /** jaroslav@931: * Back 2 Browser Bytecode Translator jaroslav@931: * Copyright (C) 2012 Jaroslav Tulach jaroslav@931: * jaroslav@931: * This program is free software: you can redistribute it and/or modify jaroslav@931: * it under the terms of the GNU General Public License as published by jaroslav@931: * the Free Software Foundation, version 2 of the License. jaroslav@931: * jaroslav@931: * This program is distributed in the hope that it will be useful, jaroslav@931: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@931: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@931: * GNU General Public License for more details. jaroslav@931: * jaroslav@931: * You should have received a copy of the GNU General Public License jaroslav@931: * along with this program. Look for COPYING file in the top folder. jaroslav@931: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@931: */ jaroslav@931: package org.apidesign.bck2brwsr.demo.twitter; jaroslav@931: jaroslav@931: import static org.testng.Assert.*; jaroslav@931: import org.testng.annotations.BeforeMethod; jaroslav@931: import org.testng.annotations.Test; jaroslav@931: jaroslav@931: /** We can unit test the TwitterModel smoothly. jaroslav@931: * jaroslav@931: * @author Jaroslav Tulach jaroslav@931: */ jaroslav@931: public class TwitterClientTest { jaroslav@931: private TwitterModel model; jaroslav@931: jaroslav@931: jaroslav@931: @BeforeMethod jaroslav@931: public void initModel() { jaroslav@931: model = new TwitterModel().applyBindings(); jaroslav@931: } jaroslav@931: jaroslav@931: @Test public void testIsValidToAdd() { jaroslav@931: model.setUserNameToAdd("Joe"); jaroslav@931: Tweeters t = new Tweeters(); jaroslav@931: t.setName("test"); jaroslav@931: model.getSavedLists().add(t); jaroslav@931: model.setActiveTweetersName("test"); jaroslav@931: jaroslav@931: assertTrue(model.isUserNameToAddIsValid(), "Joe is OK"); jaroslav@931: TwitterClient.addUser(model); jaroslav@931: assertFalse(model.isUserNameToAddIsValid(), "Can't add Joe for the 2nd time"); jaroslav@931: assertEquals(t.getUserNames().size(), 0, "Original tweeters list remains empty"); jaroslav@931: jaroslav@931: Tweeters mod = model.getModifiedList(); jaroslav@931: assertNotNull(mod, "Modified list is not filled in"); jaroslav@931: assertTrue(model.isHasUnsavedChanges(), "We have modifications"); jaroslav@931: assertEquals(mod.getUserNames().size(), 1, "One element in the list"); jaroslav@931: assertEquals(mod.getUserNames().get(0), "Joe", "Its name is Joe"); jaroslav@931: jaroslav@931: assertSame(model.getActiveTweeters(), mod, "Editing list is the modified one"); jaroslav@931: jaroslav@931: TwitterClient.saveChanges(model); jaroslav@931: assertFalse(model.isHasUnsavedChanges(), "Does not have anything to save"); jaroslav@931: assertNull(model.getModifiedList(), "No list modified"); jaroslav@931: jaroslav@931: assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one"); jaroslav@931: jaroslav@931: assertFalse(model.getSavedLists().contains(t), "No longer contains old list"); jaroslav@931: } jaroslav@931: jaroslav@931: }