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@956: import java.util.List; jaroslav@1024: import net.java.html.json.Context; 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@1024: model = new TwitterModel(Context.EMPTY); jaroslav@931: } jaroslav@931: jaroslav@931: @Test public void testIsValidToAdd() { jaroslav@931: model.setUserNameToAdd("Joe"); jaroslav@1024: Tweeters t = new Tweeters(Context.EMPTY); 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@956: List mod = model.getActiveTweeters(); jaroslav@931: assertTrue(model.isHasUnsavedChanges(), "We have modifications"); jaroslav@956: assertEquals(mod.size(), 1, "One element in the list"); jaroslav@956: assertEquals(mod.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: jaroslav@931: assertSame(model.getActiveTweeters(), mod, "Still editing the old modified one"); jaroslav@931: } jaroslav@931: jaroslav@956: @Test public void httpAtTheEnd() { jaroslav@956: String res = TwitterClient.Twt.html("Ahoj http://kuk"); jaroslav@956: assertEquals(res, "Ahoj http://kuk"); jaroslav@956: } jaroslav@931: }