Best Testng code snippet using org.testng.AssertJUnit.assertNull
Source: DurableTreeNGTest.java
...93 AssertJUnit.assertTrue(tree.contains(7));94 AssertJUnit.assertTrue(tree.contains(5));95 AssertJUnit.assertEquals(tree.successor(4).intValue(), 5);96 AssertJUnit.assertEquals(tree.predecessor(4).intValue(), 3);97 AssertJUnit.assertNull(tree.predecessor(1));98 AssertJUnit.assertEquals(tree.successor(1).intValue(), 3);99 AssertJUnit.assertEquals(tree.predecessor(7).intValue(), 6);100 AssertJUnit.assertNull(tree.successor(7));101 AssertJUnit.assertTrue(tree.contains(3));102 tree.remove(3, true);103 AssertJUnit.assertFalse(tree.contains(3));104 AssertJUnit.assertEquals(tree.successor(1).intValue(), 4);105 AssertJUnit.assertEquals(tree.predecessor(4).intValue(), 1);106 AssertJUnit.assertTrue(tree.isValidTree());107 tree.remove(7, true);108 AssertJUnit.assertFalse(tree.contains(7));109 AssertJUnit.assertNull(tree.successor(6));110 AssertJUnit.assertTrue(tree.isValidTree());111 tree.insert(3);112 tree.insert(7);113 DurableTree<Integer> restoredTree = DurableTreeFactory.restore(m_act, null, gtypes, handler, false);114 AssertJUnit.assertTrue(restoredTree.isValidTree());115 AssertJUnit.assertTrue(restoredTree.contains(4));116 AssertJUnit.assertFalse(restoredTree.contains(8));117 AssertJUnit.assertTrue(restoredTree.contains(7));118 AssertJUnit.assertTrue(restoredTree.contains(5));119 AssertJUnit.assertEquals(restoredTree.successor(4).intValue(), 5);120 AssertJUnit.assertEquals(restoredTree.predecessor(4).intValue(), 3);121 AssertJUnit.assertNull(restoredTree.predecessor(1));122 AssertJUnit.assertEquals(restoredTree.successor(1).intValue(), 3);123 AssertJUnit.assertEquals(restoredTree.predecessor(7).intValue(), 6);124 AssertJUnit.assertNull(restoredTree.successor(7));125 restoredTree.insert(10);126 AssertJUnit.assertEquals(restoredTree.successor(1).intValue(), 3);127 AssertJUnit.assertEquals(restoredTree.predecessor(10).intValue(), 7);128 restoredTree.destroy();129 }130 @Test(enabled = true)131 public void testInsertString() {132 DurableType gtypes[] = {DurableType.STRING};133 DurableTree<String> tree = DurableTreeFactory.create(m_act, null, gtypes, false);134 //strings are sorted lexicographically135 Long handler = tree.getHandler();136 tree.insert("bob");137 tree.insert("Alice");138 tree.insert("Dog");139 tree.insert("Fun");140 tree.insert("Ele");141 tree.insert("Cat");142 AssertJUnit.assertTrue(tree.isValidTree());143 AssertJUnit.assertTrue(tree.contains("Fun"));144 AssertJUnit.assertFalse(tree.contains("is"));145 AssertJUnit.assertTrue(tree.contains("Cat"));146 AssertJUnit.assertFalse(tree.contains("Bob"));147 AssertJUnit.assertEquals(tree.successor("Ele"), "Fun");148 AssertJUnit.assertEquals(tree.predecessor("Dog"), "Cat");149 AssertJUnit.assertNull(tree.predecessor("Alice"));150 AssertJUnit.assertEquals(tree.successor("Alice"), "Cat");151 AssertJUnit.assertEquals(tree.predecessor("Fun"), "Ele");152 AssertJUnit.assertNull(tree.successor("bob"));153 tree.remove("Cat", true);154 AssertJUnit.assertEquals(tree.predecessor("Dog"), "Alice");155 AssertJUnit.assertEquals(tree.successor("Alice"), "Dog");156 AssertJUnit.assertTrue(tree.isValidTree());157 tree.remove("Alice", true);158 AssertJUnit.assertNull(tree.predecessor("Dog"));159 tree.destroy();160 }161 @Test(enabled = true)162 public void testInsertRandomBigTrees() {163 DurableType gtypes[] = {DurableType.INTEGER};164 DurableTree<Integer> tree = DurableTreeFactory.create(m_act, null, gtypes, false);165 Long handler = tree.getHandler();166 for (int i = 0; i < 10 * 1024; i++) {167 int rand = randInt();168 tree.insert(rand);169 AssertJUnit.assertTrue(tree.contains(rand));170 }171 AssertJUnit.assertTrue(tree.isValidTree());172 tree.destroy();...
Source: NSSupportTest.java
...59 nssupport.pushContext();60 Assert.assertFalse(nssupport.isNamespaceDeclUris());61 nssupport.declarePrefix("xmlns", "");62 nssupport.processName("xmlns:name", parts, true);63 Assert.assertNull(parts[0]);64 Assert.assertNull(parts[1]);65 Assert.assertNull(parts[2]);66 nssupport.reset();67 nssupport.setNamespaceDeclUris(true);68 nssupport.declarePrefix("xmlns", "");69 nssupport.processName("xmlns:name", parts, true);70 Assert.assertTrue(parts[0].equals(NamespaceSupport.NSDECL));71 Assert.assertTrue(parts[1].equals("name"));72 Assert.assertTrue(parts[2].equals("xmlns:name"));73 nssupport.reset();74 nssupport.setNamespaceDeclUris(true);75 nssupport.declarePrefix("xml", "");76 nssupport.processName("xml:name", parts, true);77 Assert.assertTrue(parts[0].equals(NamespaceSupport.XMLNS));78 Assert.assertTrue(parts[1].equals("name"));79 Assert.assertTrue(parts[2].equals("xml:name"));80 }81 @Test82 public void testPopContext() {83 String[] parts = new String[3];84 NamespaceSupport nssupport = new NamespaceSupport();85 nssupport.pushContext();86 nssupport.declarePrefix("dc", "http://www.purl.org/dc");87 Assert.assertEquals(nssupport.getPrefix("http://www.purl.org/dc"), "dc");88 nssupport.popContext();89 Assert.assertNull(nssupport.getPrefix("http://www.purl.org/dc"));90 nssupport.processName("dc:name1", parts, false);91 Assert.assertNull(parts[0]);92 Assert.assertNull(parts[1]);93 Assert.assertNull(parts[2]);94 }95 @Test96 public void testPrefixAndUri1() {97 boolean hasdc = false;98 boolean hasdc1 = false;99 boolean hasdc2 = false;100 boolean hasdcnew = false;101 NamespaceSupport nssupport = new NamespaceSupport();102 nssupport.pushContext();103 nssupport.declarePrefix("dc", "http://www.purl.org/dc");104 nssupport.pushContext();105 nssupport.declarePrefix("dc1", "http://www.purl.org/dc");106 nssupport.declarePrefix("dc2", "http://www.purl.org/dc2");107 nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew");108 Enumeration enu1 = nssupport.getDeclaredPrefixes();109 while (enu1.hasMoreElements()) {110 String str = (String) enu1.nextElement();111 if (str.equals("dc")) {112 hasdc = true;113 } else if (str.equals("dc1")) {114 hasdc1 = true;115 } else if (str.equals("dc2")) {116 hasdc2 = true;117 } else if (str.equals("dcnew")) {118 hasdcnew = true;119 }120 }121 AssertJUnit.assertTrue(hasdcnew && hasdc1 && hasdc2);122 AssertJUnit.assertFalse(hasdc);123 }124 @Test125 public void testPrefixAndUri2() {126 boolean hasdc = false;127 boolean hasdc1 = false;128 boolean hasdc2 = false;129 boolean hasdcnew = false;130 NamespaceSupport nssupport = new NamespaceSupport();131 nssupport.pushContext();132 nssupport.declarePrefix("dc", "http://www.purl.org/dc");133 nssupport.pushContext();134 nssupport.declarePrefix("dc1", "http://www.purl.org/dc");135 nssupport.declarePrefix("dc2", "http://www.purl.org/dc2");136 nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew");137 Enumeration enu1 = nssupport.getPrefixes();138 while (enu1.hasMoreElements()) {139 String str = (String) enu1.nextElement();140 if (str.equals("dc")) {141 hasdc = true;142 } else if (str.equals("dc1")) {143 hasdc1 = true;144 } else if (str.equals("dc2")) {145 hasdc2 = true;146 } else if (str.equals("dcnew")) {147 hasdcnew = true;148 }149 }150 AssertJUnit.assertTrue(hasdcnew && hasdc1 && hasdc2 && hasdc);151 }152 @Test153 public void testPrefixAndUri3() {154 boolean hasdc = false;155 boolean hasdc1 = false;156 boolean hasdc2 = false;157 boolean hasdcnew = false;158 NamespaceSupport nssupport = new NamespaceSupport();159 nssupport.pushContext();160 nssupport.declarePrefix("dc", "http://www.purl.org/dc");161 nssupport.pushContext();162 nssupport.declarePrefix("dc1", "http://www.purl.org/dc");163 nssupport.declarePrefix("dc2", "http://www.purl.org/dc2");164 nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew");165 Enumeration enu1 = nssupport.getPrefixes("http://www.purl.org/dc");166 while (enu1.hasMoreElements()) {167 String str = (String) enu1.nextElement();168 if (str.equals("dc")) {169 hasdc = true;170 } else if (str.equals("dc1")) {171 hasdc1 = true;172 } else if (str.equals("dc2")) {173 hasdc2 = true;174 } else if (str.equals("dcnew")) {175 hasdcnew = true;176 }177 }178 AssertJUnit.assertTrue(hasdc1 && hasdc);179 AssertJUnit.assertFalse(hasdc2);180 AssertJUnit.assertFalse(hasdcnew);181 }182 @Test183 public void testPrefixAndUri4() {184 NamespaceSupport nssupport = new NamespaceSupport();185 nssupport.pushContext();186 nssupport.declarePrefix("dc", "http://www.purl.org/dc");187 nssupport.pushContext();188 nssupport.declarePrefix("dc1", "http://www.purl.org/dc");189 nssupport.declarePrefix("dc2", "http://www.purl.org/dc2");190 nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew");191 AssertJUnit.assertTrue(nssupport.getURI("dc").equals("http://www.purl.org/dc"));192 AssertJUnit.assertTrue(nssupport.getURI("dc1").equals("http://www.purl.org/dc"));193 AssertJUnit.assertTrue(nssupport.getURI("dc2").equals("http://www.purl.org/dc2"));194 AssertJUnit.assertTrue(nssupport.getURI("dcnew").equals("http://www.purl.org/dcnew"));195 // Negative test196 Assert.assertNull(nssupport.getURI("wrong_prefix"));197 Assert.assertNull(nssupport.getURI(""));198 }199}...
1package com.alibaba.cobar.client.transaction;2import static org.testng.AssertJUnit.assertEquals;3import static org.testng.AssertJUnit.assertNotNull;4import static org.testng.AssertJUnit.assertNull;5import static org.testng.AssertJUnit.assertTrue;6import static org.testng.AssertJUnit.fail;7import java.lang.reflect.Proxy;8import java.util.ArrayList;9import java.util.Date;10import java.util.List;11import org.springframework.transaction.PlatformTransactionManager;12import org.springframework.transaction.TransactionStatus;13import org.springframework.transaction.support.TransactionCallbackWithoutResult;14import org.springframework.transaction.support.TransactionTemplate;15import org.testng.annotations.Test;16import com.alibaba.cobar.client.AbstractTestNGCobarClientTest;17import com.alibaba.cobar.client.entities.Offer;18import com.alibaba.cobar.client.test.services.IOfferService;19/**20 * H2 In-Memory Database doesn't support transaction, so in this test case, we21 * need to turn to non-in-memory database to test the transaction.<br>22 * 23 * @author fujohnwang24 */25@Test(sequential=true)26public class MultipleDataSourcesTransactionManagerTest extends AbstractTestNGCobarClientTest {27 String selectSqlActionTwo = "com.alibaba.cobar.client.entities.Offer.findByMemberId";28 private Long[] memberIds = new Long[] { 1L, 129L, 257L, 2L, 130L,29 258L, 386L };30 public MultipleDataSourcesTransactionManagerTest() {31 super(new String[] {32 "META-INF/spring/cobar-client-appctx.xml",33 "META-INF/spring/datasources-appctx.xml",34 "META-INF/spring/namespace-sqlaction-composed-router-appctx.xml",35 "META-INF/spring/cobar-client-offer-services-appctx.xml" });36 }37 public void testOfferCreationOnMultipleShardsWithTransactionRollback() {38 new TransactionTemplate(((PlatformTransactionManager) getApplicationContext()39 .getBean("transactionManager"))).execute(new TransactionCallbackWithoutResult() {40 @Override41 protected void doInTransactionWithoutResult(TransactionStatus status) {42 try {43 Offer offer = new Offer();44 offer.setMemberId(1L);45 offer.setGmtUpdated(new Date());46 offer.setSubject("o1");47 getSqlMapClientTemplate().insert(48 "com.alibaba.cobar.client.entities.Offer.create", offer);49 offer = new Offer();50 offer.setMemberId(2L);51 offer.setGmtUpdated(new Date());52 offer.setSubject("o2");53 getSqlMapClientTemplate().insert(54 "com.alibaba.cobar.client.entities.Offer.create", offer);55 } finally {56 status.setRollbackOnly();57 }58 }59 });60 Long[] mids = new Long[] { 1L, 2L };61 for (Long mid : mids) {62 Offer parameter = new Offer();63 parameter.setMemberId(mid);64 assertNull(getSqlMapClientTemplate().queryForObject(selectSqlActionTwo, parameter));65 }66 }67 public void testOfferCreationOnMultipleShardsWithNormallyOfferService() {68 String selectSqlActionTwo = "com.alibaba.cobar.client.entities.Offer.findByMemberId";69 for (Long mid : memberIds) {70 Offer parameter = new Offer();71 parameter.setMemberId(mid);72 Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionTwo,73 parameter);74 assertNull(offer);75 }76 ((IOfferService) getApplicationContext().getBean("normalOfferService"))77 .createOffersInBatch(createOffersWithMemberIdsFrom(memberIds));78 for (Long mid : memberIds) {79 Offer parameter = new Offer();80 parameter.setMemberId(mid);81 Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionTwo,82 parameter);83 assertNotNull(offer);84 assertEquals(mid, offer.getMemberId());85 }86 }87 /**88 * need data stores that support transaction to test this behavior.89 */90 public void testOfferCreationOnMultipleShardsWithAbnormalOfferService() {91 String selectSqlActionTwo = "com.alibaba.cobar.client.entities.Offer.findByMemberId";92 for (Long mid : memberIds) {93 Offer parameter = new Offer();94 parameter.setMemberId(mid);95 Offer offer = (Offer) getSqlMapClientTemplate().queryForObject(selectSqlActionTwo,96 parameter);97 assertNull(offer);98 }99 try {100 Object offerService = getApplicationContext().getBean("abnormalOfferService");101 assertTrue(offerService instanceof Proxy);102 ((IOfferService) offerService)103 .createOffersInBatch(createOffersWithMemberIdsFrom(memberIds));104 fail();105 } catch (RuntimeException e) {106 // pass107 }108 for (Long mid : memberIds) {109 Offer parameter = new Offer();110 parameter.setMemberId(mid);111 assertNull(getSqlMapClientTemplate().queryForObject(selectSqlActionTwo, parameter));112 }113 }114 public List<Offer> createOffersWithMemberIdsFrom(Long[] mids) {115 List<Offer> offers = new ArrayList<Offer>();116 for (Long mid : mids) {117 Offer offer = new Offer();118 offer.setGmtUpdated(new Date());119 offer.setMemberId(mid);120 offer.setSubject("anything");121 offers.add(offer);122 }123 return offers;124 }125}...
Source: CocitTest.java
1package com.jiongsoft.cocitest;2import static org.testng.AssertJUnit.assertEquals;3import static org.testng.AssertJUnit.assertNotNull;4import static org.testng.AssertJUnit.assertNull;5import static org.testng.AssertJUnit.assertTrue;6import javax.servlet.http.HttpServletRequest;7import javax.servlet.http.HttpServletResponse;8import mockit.Expectations;9import mockit.Mocked;10import org.springframework.mock.web.MockHttpServletRequest;11import org.springframework.mock.web.MockHttpServletResponse;12import org.springframework.mock.web.MockServletContext;13import org.testng.annotations.BeforeMethod;14import org.testng.annotations.Test;15import com.jiongsoft.cocit.Cocit;16import com.jiongsoft.cocit.BeanFactory;17import com.jiongsoft.cocit.ActionContext;18import com.jiongsoft.cocit.service.ConfigManager;19import com.jiongsoft.cocit.sms.impl.ZrSmsClient;20import com.jiongsoft.cocit.util.Json;21import com.kmetop.demsy.Demsy;22import com.kmetop.demsy.comlib.impl.base.lib.DemsySoft;23import com.kmetop.demsy.config.SoftConfigManager;24import com.kmetop.demsy.engine.BizEngine;25import com.kmetop.demsy.engine.ModuleEngine;26public class CocitTest {27 MockServletContext context;28 @BeforeMethod29 public void setUp() {30 context = new MockServletContext();31 context.setContextPath("/");32 Cocit.init(context);33 }34 @Test35 public void destroy() {36 Cocit.destroy(context);37 assertNull(Cocit.getContextPath());38 try {39 Cocit.getBean("");40 assertTrue(false);41 } catch (NullPointerException e) {42 assertTrue(true);43 }44 assertNull(Cocit.getActionContext());45 }46 @Test47 public void getContextPath() {48 MockServletContext context = new MockServletContext();49 context.setContextPath(null);50 Cocit.init(context);51 assertEquals("", Cocit.getContextPath());52 context.setContextPath("/");53 Cocit.init(context);54 assertEquals("", Cocit.getContextPath());55 context.setContextPath("");56 Cocit.init(context);57 assertEquals("", Cocit.getContextPath());58 context.setContextPath("/test");59 Cocit.init(context);60 assertEquals("/test", Cocit.getContextPath());61 context.setContextPath("/test/");62 Cocit.init(context);63 assertEquals("/test", Cocit.getContextPath());64 context.setContextPath("test");65 Cocit.init(context);66 assertEquals("/test", Cocit.getContextPath());67 }68 @Test69 public void getBean() {70 Json json = Cocit.getBean(Json.class);71 assertNull(json);72 json = Cocit.getBean("json");73 assertNull(json);74 BeanFactory beanFactory = Cocit.getBean(BeanFactory.class);75 assertNotNull(beanFactory);76 beanFactory = Cocit.getBean("beanFactory");77 assertNotNull(beanFactory);78 assertNotNull(Cocit.getServiceFactory());79 assertNotNull(Cocit.getWidgetModelFactory());80 assertNotNull(Cocit.getWidgetRenderFactory());81 assertNull(Cocit.getOrmFactory());82 }83 @Test84 public void makeAndGetHttpContext() {85 final HttpServletRequest req = new MockHttpServletRequest();86 final HttpServletResponse res = new MockHttpServletResponse();87 new Expectations(Demsy.class, SoftConfigManager.class) {88 @Mocked89 DemsySoft mockDemsySoft;90 @Mocked91 BizEngine bizEngine;92 @Mocked93 ModuleEngine moduleEngine;94 @Mocked95 SoftConfigManager mockDemsyConfig;...
Source: SimpleTreeTest.java
1package org.molgenis.util;2import static org.testng.AssertJUnit.assertEquals;3import static org.testng.AssertJUnit.assertFalse;4import static org.testng.AssertJUnit.assertNotNull;5import static org.testng.AssertJUnit.assertNull;6import static org.testng.AssertJUnit.assertTrue;7import static org.testng.AssertJUnit.fail;8import org.testng.annotations.Test;9public class SimpleTreeTest10{11 @Test12 public void testCreate()13 {14 String name = "test";15 TestTree tree = new TestTree(name, null);16 assertEquals(name, tree.getName());17 assertFalse(tree.hasChildren());18 assertNotNull(tree.getChildren());19 assertTrue(tree.getChildren().isEmpty());20 assertNull(tree.getParent());21 assertEquals(tree, tree.getRoot());22 assertNotNull(tree.getAllChildren());23 assertTrue(tree.getAllChildren().isEmpty());24 assertNotNull(tree.getAllChildren(true));25 assertEquals(1, tree.getAllChildren(true).size());26 assertEquals(tree, tree.getAllChildren(true).get(0));27 assertNull(tree.getChild("xxx"));28 assertNull(tree.getChild(name));29 assertNull(tree.get("xxx"));30 assertNotNull(tree.get(name));31 assertEquals(tree, tree.get(name));32 assertNull(tree.getValue());33 assertNotNull(tree.getPath(","));34 assertEquals(name, tree.getPath(","));35 }36 @Test37 public void testCreateWithParent()38 {39 TestTree parent = new TestTree("parent", null);40 TestTree child = new TestTree("child", parent);41 assertTrue(parent.hasChildren());42 assertEquals(1, parent.getAllChildren().size());43 assertEquals(child, parent.getAllChildren().get(0));44 assertNotNull(child.getParent());45 assertEquals(child.getParent(), parent);46 assertEquals("parent,child", child.getPath(","));47 assertNotNull(child.getRoot());48 assertEquals(parent, child.getRoot());49 }50 @Test51 public void testSetParent()52 {53 TestTree parent = new TestTree("parent", null);54 TestTree child = new TestTree("child", null);55 child.setParent(parent);56 assertTrue(parent.hasChildren());57 assertEquals(1, parent.getAllChildren().size());58 assertEquals(child, parent.getAllChildren().get(0));59 assertNotNull(child.getParent());60 assertEquals(child.getParent(), parent);61 assertEquals("parent,child", child.getPath(","));62 assertNotNull(child.getRoot());63 assertEquals(parent, child.getRoot());64 TestTree duplicate = new TestTree("child", null);65 try66 {67 duplicate.setParent(parent);68 fail("Should have thrown IllegalArgumentException");69 }70 catch (IllegalArgumentException e)71 {72 // Expected73 }74 }75 @Test76 public void testGetChild()77 {78 TestTree parent = new TestTree("test", null);79 TestTree child1 = new TestTree("child1", parent);80 TestTree child2 = new TestTree("child2", parent);81 assertEquals(child1, parent.getChild("child1"));82 assertEquals(child2, parent.getChild("child2"));83 }84 @Test85 public void testSetValue()86 {87 String parentValue = "parentValue";88 String childValue = "childValue";89 TestTree parent = new TestTree("parent", null);90 parent.setValue(parentValue);91 TestTree child = new TestTree("child", null);92 child.setValue(childValue);93 child.setParent(parent);94 assertNotNull(parent.getValue());95 assertNotNull(parentValue, parent.getValue());96 assertNotNull(child.getValue());97 assertNotNull(childValue, child.getValue());98 }99 @Test100 public void testRemove()101 {102 TestTree parent = new TestTree("test", null);103 TestTree child1 = new TestTree("child1", parent);104 TestTree child2 = new TestTree("child2", parent);105 assertNotNull(parent.getAllChildren());106 assertEquals(2, parent.getAllChildren().size());107 child1.remove();108 assertNotNull(parent.getAllChildren());109 assertEquals(1, parent.getAllChildren().size());110 assertEquals(child2, parent.getAllChildren().get(0));111 assertNull(parent.getChild("child1"));112 }113 private static class TestTree extends SimpleTree<TestTree>114 {115 private static final long serialVersionUID = 2697117779184102294L;116 public TestTree(String name, TestTree parent)117 {118 super(name, parent);119 }120 }121}...
Source: ParameterTest.java
...20import static org.testng.AssertJUnit.assertEquals;21import static org.testng.AssertJUnit.assertFalse;22import static org.testng.AssertJUnit.assertNotNull;23import static org.testng.AssertJUnit.assertNotSame;24import static org.testng.AssertJUnit.assertNull;25import static org.testng.AssertJUnit.assertTrue;26import org.testng.annotations.Test;27/**28 * Tests Parameter.29 *30 * @author John Mazzitelli31 */32@Test33public class ParameterTest {34 /**35 * Tests constructors.36 *37 * @throws Exception38 */39 public void testParameterConstructors() throws Exception {40 Parameter p1;41 Parameter p2;42 ParameterDefinition def1;43 ParameterDefinition def2;44 p1 = new Parameter(null, null);45 assertNull(p1.getValue());46 assertNull(p1.getDefinition());47 p2 = new Parameter(null, null);48 assertEquals(p1, p2);49 // test copy constructor with all nulls in the parameter to copy50 p2 = new Parameter(p1);51 assertNotSame(p1, p2);52 assertEquals(p1, p2);53 def1 = new ParameterDefinition("one", "java.lang.String", true, true, true, "");54 p1 = new Parameter(def1, null);55 assertFalse(p1.equals(p2));56 assertNotNull(p1.getDefinition());57 def2 = new ParameterDefinition("one", "java.lang.StringBuffer", false, false, false, "desc");58 p2 = new Parameter(def2, null);59 assertEquals(p1.getDefinition(), p2.getDefinition()); // just def names are compared in equals()60 assertTrue(p1.equals(p2)); // the values are compared as well as defs...
Source: ProductUnitTest.java
...23package org.jboss.mobicents.seam.test;2425import static org.testng.AssertJUnit.assertEquals;26import static org.testng.AssertJUnit.assertNotNull;27import static org.testng.AssertJUnit.assertNull;28import static org.testng.AssertJUnit.assertTrue;29import static org.testng.AssertJUnit.fail;3031import javax.persistence.EntityManager;32import javax.persistence.EntityManagerFactory;33import javax.persistence.Persistence;34import javax.persistence.PersistenceException;3536import org.jboss.mobicents.seam.model.Product;37import org.jboss.seam.mock.SeamTest;38import org.testng.annotations.Test;3940public class ProductUnitTest 41 extends SeamTest42{ 43 EntityManager em() {44 EntityManagerFactory emf = Persistence.createEntityManagerFactory("dvdDatabase");45 EntityManager em = emf.createEntityManager();46 assertNotNull("entity manager", em);47 assertTrue("entity manager open", em.isOpen());48 return em;49 }505152 @Test53 public void testRequiredAttributes()54 throws Exception55 {56 Product p = new Product();5758 EntityManager em = em();59 try {60 em.persist(p);61 fail("empty product persisted");62 } catch (PersistenceException e) {63 // good64 } finally {65 em.close();66 }67 }6869 @Test 70 public void testCreateDelete() {71 EntityManager em = em();7273 Product p = new Product();74 p.setTitle("test");7576 em.getTransaction().begin();77 em.persist(p);78 em.getTransaction().commit();7980 long id = p.getProductId();81 assertTrue("product id set", id != 0);82 83 p = em.find(Product.class ,id);84 assertNotNull("find by id", p);85 assertEquals("id", id, p.getProductId());86 assertEquals("title", "test", p.getTitle());8788 em.getTransaction().begin();89 em.remove(p);90 em.getTransaction().commit();91 92 p = em.find(Product.class, id);93 assertNull("deleted product", p);94 }95 96}
...
Source: SpringCachingFrameworkTest.java
1package net.remmirath.spring.caching;2import static org.junit.Assert.assertNull;3import net.remmirath.spring.caching.SpringCachingServiceBean.K9;4import net.remmirath.spring.caching.SpringCachingServiceBean.KeyBase;5import org.slf4j.Logger;6import org.slf4j.LoggerFactory;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.test.context.ContextConfiguration;9import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;10import org.testng.AssertJUnit;11import org.testng.annotations.BeforeMethod;12import org.testng.annotations.Test;13/**14 * @author oleg15 *16 */17@ContextConfiguration(classes = { SpringCachingFrameworkTestContext.class })18public class SpringCachingFrameworkTest extends AbstractTestNGSpringContextTests {19 final Logger log = LoggerFactory.getLogger(this.getClass());20 @Autowired21 private AlertCollator alertCollator;22 @Autowired23 private SpringCachingServiceBean service;24 private KeyBase mustWorkWithSpELKey = new KeyBase(3,7);25 @BeforeMethod26 public void setup() {27 alertCollator.alertCount = 0;28 service.cacheEvictingMethod(mustWorkWithSpELKey);29 }30 @Test31 public void mustWorkWithSpEL() {32 AssertJUnit.assertEquals(0, alertCollator.alertCount);33 int result = service.cachedMethod(mustWorkWithSpELKey);34 AssertJUnit.assertEquals(1, alertCollator.alertCount);35 int result2 = service.cachedMethod(mustWorkWithSpELKey);36 AssertJUnit.assertEquals(1, alertCollator.alertCount);37 AssertJUnit.assertEquals(42, result);38 AssertJUnit.assertEquals(result, result2);39 mustEvict(mustWorkWithSpELKey);40 }41 public void mustEvict(KeyBase key) {42 service.cacheEvictingMethod(key);43 int result = service.cachedMethod(key);44 AssertJUnit.assertEquals(2, alertCollator.alertCount);45 AssertJUnit.assertEquals(42, result);46 int result2 = service.cachedMethod(key);47 AssertJUnit.assertEquals(2, alertCollator.alertCount);48 AssertJUnit.assertEquals(result, result2);49 }50 @Test51 public void mustSupportNullKey() {52 K9 key = null;53 Integer result = service.cachedMethodThatReturnsNull(key);54 assertNull(result);55 key = new K9(null);56 result = service.cachedMethodThatReturnsNull(key);57 }58 @Test(expectedExceptions=RuntimeException.class)59 public void mustCatchSpELErrors() {60 KeyBase key = new KeyBase(7,11);61 try {62 service.cachedMethodWrongSpEL(key);63 } catch (RuntimeException e) {64 log.debug("Exception 1!", e);65 throw e;66 }67 try {68 service.cachedMethodWrongSpEL2(key);...
assertNull
Using AI Code Generation
1[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ testng-assertj ---2[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ testng-assertj ---3[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ testng-assertj ---4[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ testng-assertj ---5[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ testng-assertj ---6[INFO] --- maven-assembly-plugin:2.4.1:single (default) @ testng-assertj ---
assertNull
Using AI Code Generation
1import org.testng.AssertJUnit;2import org.testng.annotations.Test;3public class TestNG_AssertJUnit {4 public void testAssertNull() {5 String str1 = "TestNG is working fine";6 String str2 = null;7 AssertJUnit.assertNull(str1);8 AssertJUnit.assertNull(str2);9 }10}11Method testAssertNull() should have no parameters12 at org.testng.internal.MethodHelper.validateParameters(MethodHelper.java:57)13 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:78)14 at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:57)15 at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:478)16 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)17 at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)18 at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169)19 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)20 at org.testng.TestRunner.privateRun(TestRunner.java:767)21 at org.testng.TestRunner.run(TestRunner.java:617)22 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)23 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)24 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)25 at org.testng.SuiteRunner.run(SuiteRunner.java:240)26 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)27 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)28 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)29 at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)30 at org.testng.TestNG.run(TestNG.java:1018)31 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:115)32 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:207)33 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:178)34 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)35 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)36 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
assertNull
Using AI Code Generation
1import org.testng.AssertJUnit;2AssertJUnit.assertNull("null", null);3AssertJUnit.assertNull("not null", "not null");4import org.testng.Assert;5Assert.assertNull("null", null);6Assert.assertNull("not null", "not null");7import static org.testng.AssertJUnit.assertNull;8assertNull("null", null);9assertNull("not null", "not null");10import static org.testng.Assert.assertNull;11assertNull("null", null);12assertNull("not null", "not null");13Assert.assertSame(Object, Object)14Assert.assertTrue(boolean)15Assert.fail()16Assert.fail(String)17Assert.assertFalse(boolean)18Assert.assertFalse(boolean, String)19Assert.assertEquals(Object, Object)20Assert.assertEquals(Object, Object, String)21Assert.assertEquals(Object, Object, String, double)22Assert.assertEquals(Object, Object, String, float)23Assert.assertEquals(Object, Object, String, long)24Assert.assertEquals(Object, Object, String, int)25Assert.assertEquals(Object, Object, String, short)26Assert.assertEquals(Object, Object, String, byte)27Assert.assertEquals(Object, Object, String, char)28Assert.assertEquals(Object, Object, String, boolean)29Assert.assertEquals(Object, Object, String, double, double)30Assert.assertEquals(Object, Object, String, float, float)31Assert.assertEquals(Object, Object, String, long, long)32Assert.assertEquals(Object, Object, String, int, int)33Assert.assertEquals(Object, Object, String, short, short)34Assert.assertEquals(Object, Object, String, byte, byte)35Assert.assertEquals(Object, Object, String, char, char)36Assert.assertEquals(Object, Object, String, boolean, boolean)37Assert.assertEquals(Object, Object, String, Object, Object)38Assert.assertEquals(Object, Object, String, Object, Object, String)39Assert.assertEquals(Object, Object, String, Object, Object, String, double)40Assert.assertEquals(Object, Object, String, Object, Object, String, float)41Assert.assertEquals(Object, Object, String, Object, Object, String, long)42Assert.assertEquals(Object, Object, String, Object, Object, String, int)43Assert.assertEquals(Object, Object, String, Object, Object, String, short)44Assert.assertEquals(Object, Object, String, Object, Object, String, byte)45Assert.assertEquals(Object, Object, String, Object, Object, String, char)46Assert.assertEquals(Object, Object,
assertNull
Using AI Code Generation
1package testng;2import org.testng.annotations.Test;3import org.testng.annotations.BeforeMethod;4import org.testng.annotations.AfterMethod;5public class TestNG_Test3 {6 public void f() {7 System.out.println("TestNG_Test3->f");8 }9 public void beforeMethod() {10 System.out.println("TestNG_Test3->beforeMethod");11 }12 public void afterMethod() {13 System.out.println("TestNG_Test3->afterMethod");14 }15}16package testng;17import org.testng.annotations.Test;18import org.testng.annotations.BeforeMethod;19import org.testng.annotations.AfterMethod;20public class TestNG_Test4 {21 public void f() {22 System.out.println("TestNG_Test4->f");23 }24 public void beforeMethod() {25 System.out.println("TestNG_Test4->beforeMethod");26 }27 public void afterMethod() {28 System.out.println("TestNG_Test4->afterMethod");29 }30}31package testng;32import org.testng.annotations.Test;33import org.testng.annotations.BeforeMethod;34import org.testng.annotations.AfterMethod;35public class TestNG_Test5 {36 public void f() {
assertNull
Using AI Code Generation
1package org.openqa.selenium.example;2import org.testng.AssertJUnit;3import org.testng.annotations.Test;4public class TestNGAssertJUnit {5 public void testAssertNull() {6 String str = null;7 AssertJUnit.assertNull(str);8 }9}10java -cp selenium-server-standalone-2.35.0.jar;testng-5.8.jar;org.openqa.selenium.example.TestNGAssertJUnit.java org.testng.TestNG testng.xml
Getting sequential logs while executing tests in parallel
Is there a Maven "compiler-only" scope for dependency artifacts
WebDriverException: unknown error: failed to change window state to maximized, current state is normal with Chrome 70 & Chromedriver 2.43 on MAC OS X
How to run multiple test classes in testng suite with only one web driver instance?
How do I test expectedExceptionsMessageRegExp (exception message) using TestNG?
TestNG dependsOnMethods from different class
TestNG- pass parameters to the constructor where parameters are decided based on the testname
set up an application with a database - tapestry-hibernate fail
Skip one maven test does not work
How to create a executable jar file for Testng and the runnnig point should be the Xml file
When you enable parallel then there will be some time between the beforeInvocation
and afterInvocation
in the logs as you have noticed and that difference in time varies from test to test hence the staggered output.
If what you want is the start and end messages next to each other then you are basically throwing out the time factor and as such can simply add your beforeInvocation
message to the afterInvocation
method as follows:
public class TestExecutionListener implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
}
@Override
public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
System.out.println("Testing : " + iInvokedMethod.getTestMethod().getMethodName());
System.out.println("Successfully Tested : " + iInvokedMethod.getTestMethod().getMethodName());
}
}
IMO this is the only way to do it as per your spec. However, if there is other information that must be gathered during the tests then perhaps you could buffer some logs in the TestExecutionListener
for example:
public class TestExecutionListener implements IInvokedMethodListener {
private Map<Integer, Deque<String>> logsMap = new HashMap<Integer, Deque<String>>();
public void log(IInvokedMethod iInvokedMethod, String log) {
if(!logsMap.containsKey(iInvokedMethod.getId())) {
logsMap.put(iInvokedMethod.getId(), new ArrayDeque<String>());
}
logsMap.get(iInvokedMethod.getId()).add(log);
}
@Override
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
log(iInvokedMethod, "Testing : " + iInvokedMethod.getTestMethod().getMethodName());
}
@Override
public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
log(iInvokedMethod, "Successfully Tested : " + iInvokedMethod.getTestMethod().getMethodName());
Deque<String> logs = logsMap.get(iInvokedMethod.getId());
while(!logs.isEmpty()) {
System.out.println(logs.poll());
}
}
}
Check out the latest blogs from LambdaTest on this topic:
Cross browser testing has been a type of testing which requires a tremendous amount of effort and time. The process of testing your web-app over different browsers, operating systems, devices, screen resolutions to evaluate the rendering of your web content for a variety of your audience is an activity. Especially, if approached manually. Automated cross browser testing with Selenium can help you save the time of routine test activities, helping you cut short on regression testing. However, people seldom like changes. If manual testing is popular in your organization, the management will obviously raise questions when you ask them to implement test automation.
There are many debates going on whether testers should know programming languages or not. Everyone has his own way of backing the statement. But when I went on a deep research into it, I figured out that no matter what, along with soft skills, testers must know some programming languages as well. Especially those that are popular in running automation tests.
Being an open-source framework allowed Selenium to be compatible with multiple test automation frameworks for different programming languages and if we talk about Automation testing with Selenium and JavaScript, there is a particular framework that never fails to take the spotlight and that is the Nightwatch.js. This is why I decided to come up with Nightwatch.js tutorial for beginners.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Automation Testing Tutorial.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on JUnit Tutorial.
TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.
You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!