Best junit code snippet using org.junit.Assert.assertFalse
Source:PacketTest.java  
...81		org.junit.Assert.assertEquals(PacketDNS.PKTHDRSIZ + boff, off);82		org.junit.Assert.assertEquals(qid, pkt2.getQID());83		org.junit.Assert.assertEquals(0, pkt2.opcode());84		org.junit.Assert.assertEquals(0, pkt2.rcode());85		org.junit.Assert.assertFalse(pkt2.isResponse());86		org.junit.Assert.assertFalse(pkt2.isAuth());87		org.junit.Assert.assertFalse(pkt2.isTruncated());88		org.junit.Assert.assertTrue(pkt2.recursionDesired());89		org.junit.Assert.assertFalse(pkt2.recursionAvailable());90		org.junit.Assert.assertEquals(1, pkt2.getQuestionCount());91		org.junit.Assert.assertEquals(0, pkt2.getAnswerCount());92		org.junit.Assert.assertEquals(0, pkt2.getAuthorityCount());93		org.junit.Assert.assertEquals(0, pkt2.getInfoCount());94		off = pkt2.parseQuestion(off, pkt2.getQuestionCount(), null, cb);95		org.junit.Assert.assertEquals(barr.length, off);96		org.junit.Assert.assertEquals(1, pkt2.getQuestionCount());97		org.junit.Assert.assertEquals(pkt2.getQuestionCount(), cb.qcallcnt);98		org.junit.Assert.assertEquals(0, cb.rrcallcnt);99		org.junit.Assert.assertEquals(0, cb.cb_qnum);100		org.junit.Assert.assertEquals(pkt2.getQuestionCount(), cb.cb_qcnt);101		org.junit.Assert.assertEquals(qid, cb.cb_qid);102		org.junit.Assert.assertEquals(qtype, cb.cb_qtype);103		org.junit.Assert.assertEquals(PacketDNS.QCLASS_INET, cb.cb_qclass);104		org.junit.Assert.assertEquals(qname, cb.cb_qname.toString());105		org.junit.Assert.assertNull(cb.cb_addr);106107		// decode again, with a Skip action on the questions section108		cb = new ParseQuestionHandler();109		pkt2.resetDecoder(barr, boff, barr.length - boff);110		off = pkt2.decodeHeader();111		org.junit.Assert.assertEquals(PacketDNS.PKTHDRSIZ + boff, off);112		org.junit.Assert.assertEquals(1, pkt2.getQuestionCount());113		off = pkt2.skipSection(off, PacketDNS.SECT_QUESTIONS, pkt2.getQuestionCount());114		org.junit.Assert.assertEquals(barr.length, off);115		org.junit.Assert.assertEquals(1, pkt2.getQuestionCount());116		org.junit.Assert.assertEquals(0, cb.qcallcnt);117		org.junit.Assert.assertEquals(0, cb.rrcallcnt);118	}119120	// This is based on the example in RFC 1035 section 4.1.4121	// We're not concerned with header contents or a valid preamble to the encoded names here. We just want to122	// initialise the packet buffer sufficiently to establish offsets.123	private void verifyCompressedNames(boolean is_tcp, boolean directbufs) throws Exception {124		java.lang.reflect.Method meth_encode = PacketDNS.class.getDeclaredMethod("encodeName", int.class, ByteChars.class);125		meth_encode.setAccessible(true);126		java.lang.reflect.Method meth_decode = PacketDNS.class.getDeclaredMethod("decodeName", int.class, ByteChars.class);127		meth_decode.setAccessible(true);128		String name_f = "F.ISI.ARPA";129		String label_foo = "FOO";130		String name_foo = label_foo+"."+name_f;131		String name_arpa = "ARPA";132		String name_last = "Final_Single-Label-Name";133		PacketDNS pkt = new PacketDNS(200, directbufs, 0, TimeProvider); //more than big enough134		byte filler = 125;135136		// encode the names with compression enabled137		pkt.resetEncoder(is_tcp, true);138		byte[] pktbuf = (byte[])DynLoader.getField(pkt, "pktbuf");139		int msgbase = (int)DynLoader.getField(pkt, "msgbase");140		int off_f = pkt.encodeHeader();141		java.util.Arrays.fill(pktbuf, filler);142		int off_foo = (int)meth_encode.invoke(pkt, off_f, new ByteChars(name_f));143		int off_arpa = (int)meth_encode.invoke(pkt, off_foo, new ByteChars(name_foo));144		int off_root = (int)meth_encode.invoke(pkt, off_arpa, new ByteChars(name_arpa));145		int off_last = (int)meth_encode.invoke(pkt, off_root, new ByteChars("")); //encode the root domain name146		//this next one is not part of the RFC-1035 example, but I want to follow the root domain name with another name147		int lmt = (int)meth_encode.invoke(pkt, off_last, new ByteChars(name_last));148		int enclen = lmt - off_f;149150		//manually verify the encoded names151		int ptr_arpa = off_f + 6; //calculate where the ARPA label should begin (F+ISI plus 2 label sizes)152		int off = off_f;153		for (String label : new String[]{"F", "ISI", name_arpa}) {154			if (label.equals(name_arpa)) org.junit.Assert.assertEquals(ptr_arpa, off); //sanity check ptr_arpa calculation155			org.junit.Assert.assertEquals(label.length(), pktbuf[off++]);156			org.junit.Assert.assertEquals(label, new ByteChars(pktbuf, off, label.length(), false).toString());157			off += label.length();158		}159		org.junit.Assert.assertEquals(0, pktbuf[off++]); //terminating NUL of F.ISI.ARPA160		String label = label_foo;161		org.junit.Assert.assertEquals(off_foo, off);162		org.junit.Assert.assertEquals(label.length(), pktbuf[off++]);163		org.junit.Assert.assertEquals(label, new ByteChars(pktbuf, off, label.length(), false).toString());164		off += label.length();165		org.junit.Assert.assertEquals(0xC0 & 0xff, pktbuf[off++] & 0xff); //next comes compressed pointer to name_f166		org.junit.Assert.assertEquals(off_f - msgbase, pktbuf[off++]);167		org.junit.Assert.assertEquals(off_arpa, off); //next comes "ARPA", represented entirely by a compressed pointer168		org.junit.Assert.assertEquals(0xC0 & 0xff, pktbuf[off++] & 0xff);169		org.junit.Assert.assertEquals(ptr_arpa - msgbase, pktbuf[off++]);170		org.junit.Assert.assertEquals(off_root, off); //next is the root domain name171		org.junit.Assert.assertEquals(0, pktbuf[off++]);172		label = name_last;173		org.junit.Assert.assertEquals(off_last, off);174		org.junit.Assert.assertEquals(label.length(), pktbuf[off++]);175		org.junit.Assert.assertEquals(label, new ByteChars(pktbuf, off, label.length(), false).toString());176		off += label.length();177		org.junit.Assert.assertEquals(0, pktbuf[off++]); //terminating NUL of final name178		org.junit.Assert.assertEquals(lmt, off);179		for (int idx = 0; idx != off_f; idx++) org.junit.Assert.assertEquals(filler, pktbuf[idx]);180		for (int idx = lmt; idx != pktbuf.length; idx++) org.junit.Assert.assertEquals(filler, pktbuf[idx]);181182		//now test the decoding of the compressed names - first is F.ISI.ARPA183		ByteChars domnam = new ByteChars(1);184		pkt.resetDecoder(pktbuf, msgbase, enclen);185		off_f = pkt.decodeHeader();186		off = (int)meth_decode.invoke(pkt, off_f, domnam);187		org.junit.Assert.assertEquals(name_f.toLowerCase(), domnam.toString());188		//then FOO.F.ISI.ARPA189		off = (int)meth_decode.invoke(pkt, off, domnam.clear());190		org.junit.Assert.assertEquals(name_foo.toLowerCase(), domnam.toString());191		//then ARPA192		off = (int)meth_decode.invoke(pkt, off, domnam.clear());193		org.junit.Assert.assertEquals(name_arpa.toLowerCase(), domnam.toString());194		//then the root domain195		off = (int)meth_decode.invoke(pkt, off, domnam.clear());196		org.junit.Assert.assertEquals(0, domnam.size());197		//then the final name we encoded198		off = (int)meth_decode.invoke(pkt, off, domnam.clear());199		org.junit.Assert.assertEquals(name_last.toLowerCase(), domnam.toString());200		org.junit.Assert.assertEquals(enclen, off - off_f);201202		// encode the names with compression disabled203		pkt.resetEncoder(is_tcp, false);204		pktbuf = (byte[])DynLoader.getField(pkt, "pktbuf");205		msgbase = (int)DynLoader.getField(pkt, "msgbase");206		off_f = pkt.encodeHeader();207		off = (int)meth_encode.invoke(pkt, off_f, new ByteChars(name_f));208		off = (int)meth_encode.invoke(pkt, off, new ByteChars(name_foo));209		off = (int)meth_encode.invoke(pkt, off, new ByteChars(name_arpa));210		off = (int)meth_encode.invoke(pkt, off, new ByteChars("")); //encode the root domain name211		off = (int)meth_encode.invoke(pkt, off, new ByteChars(name_last));212		int enclen2 = off - off_f;213		org.junit.Assert.assertTrue(enclen2 > enclen);214215		//now test the decoding of the uncompressed names216		pkt.resetDecoder(pktbuf, msgbase, enclen);217		off_f = pkt.decodeHeader();218		off = (int)meth_decode.invoke(pkt, off_f, domnam.clear());219		org.junit.Assert.assertEquals(name_f.toLowerCase(), domnam.toString());220		off = (int)meth_decode.invoke(pkt, off, domnam.clear());221		org.junit.Assert.assertEquals(name_foo.toLowerCase(), domnam.toString());222		off = (int)meth_decode.invoke(pkt, off, domnam.clear());223		org.junit.Assert.assertEquals(name_arpa.toLowerCase(), domnam.toString());224		off = (int)meth_decode.invoke(pkt, off, domnam.clear());225		org.junit.Assert.assertEquals(0, domnam.size());226		off = (int)meth_decode.invoke(pkt, off, domnam.clear());227		org.junit.Assert.assertEquals(name_last.toLowerCase(), domnam.toString());228		org.junit.Assert.assertEquals(enclen2, off - off_f);229	}230231	private void verifyHeader(boolean is_tcp, boolean directbufs) {232		int pktsiz = PacketDNS.PKTHDRSIZ;233		if (is_tcp) pktsiz += PacketDNS.TCPMSGLENSIZ;234		PacketDNS pkt = new PacketDNS(pktsiz+10, directbufs, 5, TimeProvider);235		verifyBlankHeader(pkt);236		pkt.resetEncoder(is_tcp, false);237		verifyBlankHeader(pkt);238		pkt.opcode(0xf);239		org.junit.Assert.assertEquals(0xf, pkt.opcode());240		org.junit.Assert.assertEquals(0, pkt.rcode());241		org.junit.Assert.assertFalse(pkt.isResponse());242		org.junit.Assert.assertFalse(pkt.isAuth());243		org.junit.Assert.assertFalse(pkt.isTruncated());244		org.junit.Assert.assertFalse(pkt.recursionDesired());245		org.junit.Assert.assertFalse(pkt.recursionAvailable());246247		pkt.resetEncoder(is_tcp, false);248		verifyBlankHeader(pkt);249		pkt.rcode(0xf);250		org.junit.Assert.assertEquals(0xf, pkt.rcode());251		org.junit.Assert.assertEquals(0, pkt.opcode());252		org.junit.Assert.assertFalse(pkt.isResponse());253		org.junit.Assert.assertFalse(pkt.isAuth());254		org.junit.Assert.assertFalse(pkt.isTruncated());255		org.junit.Assert.assertFalse(pkt.recursionDesired());256		org.junit.Assert.assertFalse(pkt.recursionAvailable());257258		pkt.resetEncoder(is_tcp, false);259		verifyBlankHeader(pkt);260		pkt.setResponse();261		org.junit.Assert.assertEquals(0, pkt.rcode());262		org.junit.Assert.assertEquals(0, pkt.opcode());263		org.junit.Assert.assertTrue(pkt.isResponse());264		org.junit.Assert.assertFalse(pkt.isAuth());265		org.junit.Assert.assertFalse(pkt.isTruncated());266		org.junit.Assert.assertFalse(pkt.recursionDesired());267		org.junit.Assert.assertFalse(pkt.recursionAvailable());268269		pkt.resetEncoder(is_tcp, false);270		verifyBlankHeader(pkt);271		pkt.setAuth();272		org.junit.Assert.assertEquals(0, pkt.rcode());273		org.junit.Assert.assertEquals(0, pkt.opcode());274		org.junit.Assert.assertFalse(pkt.isResponse());275		org.junit.Assert.assertTrue(pkt.isAuth());276		org.junit.Assert.assertFalse(pkt.isTruncated());277		org.junit.Assert.assertFalse(pkt.recursionDesired());278		org.junit.Assert.assertFalse(pkt.recursionAvailable());279280		pkt.resetEncoder(is_tcp, false);281		verifyBlankHeader(pkt);282		pkt.setTruncated();283		org.junit.Assert.assertEquals(0, pkt.rcode());284		org.junit.Assert.assertEquals(0, pkt.opcode());285		org.junit.Assert.assertFalse(pkt.isResponse());286		org.junit.Assert.assertFalse(pkt.isAuth());287		org.junit.Assert.assertTrue(pkt.isTruncated());288		org.junit.Assert.assertFalse(pkt.recursionDesired());289		org.junit.Assert.assertFalse(pkt.recursionAvailable());290291		pkt.resetEncoder(is_tcp, false);292		verifyBlankHeader(pkt);293		pkt.setRecursionDesired();294		org.junit.Assert.assertEquals(0, pkt.rcode());295		org.junit.Assert.assertEquals(0, pkt.opcode());296		org.junit.Assert.assertFalse(pkt.isResponse());297		org.junit.Assert.assertFalse(pkt.isAuth());298		org.junit.Assert.assertFalse(pkt.isTruncated());299		org.junit.Assert.assertTrue(pkt.recursionDesired());300		org.junit.Assert.assertFalse(pkt.recursionAvailable());301302		pkt.resetEncoder(is_tcp, false);303		verifyBlankHeader(pkt);304		pkt.setRecursionAvailable();305		org.junit.Assert.assertEquals(0, pkt.rcode());306		org.junit.Assert.assertEquals(0, pkt.opcode());307		org.junit.Assert.assertFalse(pkt.isResponse());308		org.junit.Assert.assertFalse(pkt.isAuth());309		org.junit.Assert.assertFalse(pkt.isTruncated());310		org.junit.Assert.assertFalse(pkt.recursionDesired());311		org.junit.Assert.assertTrue(pkt.recursionAvailable());312313		pkt.resetEncoder(is_tcp, false);314		verifyBlankHeader(pkt);315		pkt.setResponse();316		pkt.opcode(9);317		pkt.rcode(6);318		pkt.setTruncated();319		pkt.setRecursionAvailable();320		pkt.setHeader(251, 1, 2, 3, 4);321		int off = pkt.encodeHeader();322		java.nio.ByteBuffer niobuf = pkt.completeEncoding(off);323		org.junit.Assert.assertEquals(pktsiz, niobuf.limit());324		org.junit.Assert.assertEquals(0, niobuf.position());325		int tcp_incr = (is_tcp ? PacketDNS.TCPMSGLENSIZ : 0);326		int boff = 1; //add an extra unused byte at both ends of array327		byte[] barr = new byte[pktsiz+boff+1];328		niobuf.get(barr, boff, pktsiz);329		if (is_tcp) org.junit.Assert.assertEquals(pktsiz - PacketDNS.TCPMSGLENSIZ, ByteOps.decodeInt(barr, boff, PacketDNS.TCPMSGLENSIZ));330331		PacketDNS pkt2 = new PacketDNS(TimeProvider);332		boff += tcp_incr;333		pkt2.resetDecoder(barr, boff, pktsiz - tcp_incr);334		off = pkt2.decodeHeader();335		org.junit.Assert.assertEquals(PacketDNS.PKTHDRSIZ+boff, off);336		org.junit.Assert.assertEquals(251, pkt2.getQID());337		org.junit.Assert.assertEquals(9, pkt2.opcode());338		org.junit.Assert.assertEquals(6, pkt2.rcode());339		org.junit.Assert.assertTrue(pkt2.isResponse());340		org.junit.Assert.assertFalse(pkt2.isAuth());341		org.junit.Assert.assertTrue(pkt2.isTruncated());342		org.junit.Assert.assertFalse(pkt2.recursionDesired());343		org.junit.Assert.assertTrue(pkt2.recursionAvailable());344		org.junit.Assert.assertEquals(1, pkt2.getQuestionCount());345		org.junit.Assert.assertEquals(2, pkt2.getAnswerCount());346		org.junit.Assert.assertEquals(3, pkt2.getAuthorityCount());347		org.junit.Assert.assertEquals(4, pkt2.getInfoCount());348		try {349			pkt2.resetEncoder(is_tcp, false);350			org.junit.Assert.fail("resetEncoder() is expected to fail on read-only Packet");351		} catch (UnsupportedOperationException ex) {}352353		pkt.resetEncoder(is_tcp, false);354		verifyBlankHeader(pkt);355		org.junit.Assert.assertEquals(0, DynLoader.getField(pkt, "hdrflags"));356		pkt.opcode(0xf);357		org.junit.Assert.assertEquals(0xf, pkt.opcode());358		pkt.opcode(0);359		verifyBlankHeader(pkt);360		org.junit.Assert.assertEquals(0, DynLoader.getField(pkt, "hdrflags"));361		pkt.rcode(0xf);362		org.junit.Assert.assertEquals(0xf, pkt.rcode());363		pkt.rcode(0);364		verifyBlankHeader(pkt);365		org.junit.Assert.assertEquals(0, DynLoader.getField(pkt, "hdrflags"));366	}367368	private void verifyBlankHeader(PacketDNS pkt) {369		org.junit.Assert.assertEquals(0, pkt.getQID());370		org.junit.Assert.assertEquals(0, pkt.opcode());371		org.junit.Assert.assertEquals(0, pkt.rcode());372		org.junit.Assert.assertFalse(pkt.isResponse());373		org.junit.Assert.assertFalse(pkt.isAuth());374		org.junit.Assert.assertFalse(pkt.isTruncated());375		org.junit.Assert.assertFalse(pkt.recursionDesired());376		org.junit.Assert.assertFalse(pkt.recursionAvailable());377		org.junit.Assert.assertEquals(0, pkt.getQuestionCount());378		org.junit.Assert.assertEquals(0, pkt.getAnswerCount());379		org.junit.Assert.assertEquals(0, pkt.getAuthorityCount());380		org.junit.Assert.assertEquals(0, pkt.getInfoCount());381	}382383384	private static class ParseQuestionHandler implements PacketDNS.MessageCallback {385		public int qcallcnt;386		public int rrcallcnt;387		public int cb_qnum;388		public int cb_qcnt;389		public int cb_qid;390		public byte cb_qtype;
...Source:HashedSetTest.java  
...26	{27		java.util.Set<String> hset = allocSet(-1, 0);28		org.junit.Assert.assertEquals(0, hset.size());29		org.junit.Assert.assertTrue(hset.isEmpty());30		org.junit.Assert.assertFalse(hset.remove("nonsuch"));31		org.junit.Assert.assertFalse(hset.contains("nonsuch"));32		org.junit.Assert.assertFalse(hset.remove(null));33		org.junit.Assert.assertFalse(hset.contains(null));34		hset.clear();35		org.junit.Assert.assertEquals(0, hset.size());36		org.junit.Assert.assertTrue(hset.isEmpty());3738		java.util.Iterator<String> it = hset.iterator();39		int cnt = 0;40		while (it.hasNext()) {41			cnt++;42			it.next();43		}44		org.junit.Assert.assertEquals(0, cnt);4546		Object[] arr = hset.toArray();47		org.junit.Assert.assertEquals(0, arr.length);4849		String[] arr2 = hset.toArray(new String[hset.size()]);50		org.junit.Assert.assertEquals(0, arr2.length);51		org.junit.Assert.assertFalse(arr2 == arr);5253		String[] arr3 = hset.toArray(new String[2]);54		java.util.Arrays.fill(arr3, "marker");55		String[] arr3b = hset.toArray(arr3);56		org.junit.Assert.assertTrue(arr3 == arr3b);57		org.junit.Assert.assertNull(arr3[0]);58		org.junit.Assert.assertFalse(arr2 == arr3);59	}6061	@org.junit.Test62	public void testRegular()63	{64		java.util.Set<String> hset = allocSet(1, 1);65		org.junit.Assert.assertTrue(hset.isEmpty());66		org.junit.Assert.assertNotNull(hset.toString()); //for sake of code coverage67		org.junit.Assert.assertTrue(hset.add("one"));68		org.junit.Assert.assertFalse(hset.isEmpty());69		org.junit.Assert.assertTrue(hset.add("two"));70		org.junit.Assert.assertTrue(hset.add("three"));71		org.junit.Assert.assertEquals(3, hset.size());72		org.junit.Assert.assertFalse(hset.add("one"));73		org.junit.Assert.assertEquals(3, hset.size());74		org.junit.Assert.assertNotNull(hset.toString());7576		org.junit.Assert.assertTrue(hset.remove("one"));77		org.junit.Assert.assertEquals(2, hset.size());78		org.junit.Assert.assertFalse(hset.remove("one"));79		org.junit.Assert.assertEquals(2, hset.size());80		org.junit.Assert.assertFalse(hset.contains("one"));81		org.junit.Assert.assertTrue(hset.contains("two"));82		org.junit.Assert.assertTrue(hset.contains("three"));8384		//test the HashedSet-only get() method85		if (stype == SetTypeID.STYP_GREY) {86			HashedSet<String> hs = (HashedSet<String>)hset;87			String str = hs.get("two");88			org.junit.Assert.assertTrue(str == "two");89			String dup = new String("two");90			str = hs.get(dup);91			org.junit.Assert.assertFalse(str == dup);92			org.junit.Assert.assertTrue(str == "two");93			str = hs.get("nosuchvalue");94			org.junit.Assert.assertNull(str);95		}9697		final java.util.Set<String> jset_orig = new java.util.HashSet<String>();98		jset_orig.addAll(hset);99		org.junit.Assert.assertEquals(2, hset.size());100		org.junit.Assert.assertEquals(hset.size(), jset_orig.size());101		org.junit.Assert.assertTrue(jset_orig.contains("two"));102		org.junit.Assert.assertTrue(jset_orig.contains("three"));103104		String[] arr1 = hset.toArray(new String[5]);105		java.util.Arrays.fill(arr1, "marker");106		String[] arr1b = hset.toArray(arr1);107		org.junit.Assert.assertTrue(arr1 == arr1b);108		if ("two".equals(arr1[0])) {109			org.junit.Assert.assertSame("three", arr1[1]);110		} else {111			org.junit.Assert.assertSame("three", arr1[0]);112			org.junit.Assert.assertSame("two", arr1[1]);113		}114		org.junit.Assert.assertNull(arr1[2]);115116		java.util.Set<String> jset = new java.util.HashSet<String>();117		jset.addAll(jset_orig);118		java.util.Iterator<String> it = hset.iterator();119		int cnt = 0;120		while (it.hasNext()) {121			cnt++;122			jset.remove(it.next());123		}124		org.junit.Assert.assertEquals(2, cnt);125		org.junit.Assert.assertEquals(0, jset.size());126127		jset.addAll(jset_orig);128		Object[] arr = hset.toArray();129		org.junit.Assert.assertEquals(2, arr.length);130		for (int idx = 0; idx != arr.length; idx++) {131			boolean exists = jset.remove(arr[idx]);132			org.junit.Assert.assertTrue(exists);133		}134		org.junit.Assert.assertEquals(0, jset.size());135136		jset.addAll(jset_orig);137		String[] arr2 = hset.toArray(new String[0]);138		org.junit.Assert.assertEquals(2, arr2.length);139		for (int idx = 0; idx != arr.length; idx++) {140			boolean exists = jset.remove(arr[idx]);141			org.junit.Assert.assertTrue(exists);142		}143		org.junit.Assert.assertEquals(0, jset.size());144145		hset.clear();146		org.junit.Assert.assertTrue(hset.isEmpty());147		org.junit.Assert.assertEquals(0, hset.size());148	}149150	@org.junit.Test151	public void testNullMember()152	{153		java.util.Set<String> hset = allocSet(-1, 0);154		org.junit.Assert.assertTrue(hset.isEmpty());155		org.junit.Assert.assertTrue(hset.add(null));156		org.junit.Assert.assertFalse(hset.isEmpty());157		org.junit.Assert.assertEquals(1, hset.size());158		org.junit.Assert.assertTrue(hset.contains(null));159		org.junit.Assert.assertNotNull(hset.toString());160		org.junit.Assert.assertFalse(hset.add(null));161		org.junit.Assert.assertEquals(1, hset.size());162		org.junit.Assert.assertTrue(hset.contains(null));163		org.junit.Assert.assertTrue(hset.add("two"));164		org.junit.Assert.assertEquals(2, hset.size());165		org.junit.Assert.assertTrue(hset.contains("two"));166		org.junit.Assert.assertTrue(hset.contains(null));167168		org.junit.Assert.assertTrue(hset.remove(null));169		org.junit.Assert.assertEquals(1, hset.size());170		org.junit.Assert.assertFalse(hset.contains(null));171		org.junit.Assert.assertFalse(hset.remove(null));172		org.junit.Assert.assertEquals(1, hset.size());173		org.junit.Assert.assertTrue(hset.contains("two"));174		org.junit.Assert.assertTrue(hset.remove("two"));175		org.junit.Assert.assertFalse(hset.contains("two"));176		org.junit.Assert.assertTrue(hset.isEmpty());177		org.junit.Assert.assertEquals(0, hset.size());178179		org.junit.Assert.assertTrue(hset.add(null));180		org.junit.Assert.assertFalse(hset.isEmpty());181		org.junit.Assert.assertEquals(1, hset.size());182		org.junit.Assert.assertTrue(hset.contains(null));183184		java.util.Iterator<String> it = hset.iterator();185		int cnt = 0;186		while (it.hasNext()) {187			cnt++;188			org.junit.Assert.assertNull(it.next());189		}190		org.junit.Assert.assertEquals(1, cnt);191192		Object[] arr = hset.toArray();193		org.junit.Assert.assertEquals(1, arr.length);194		for (int idx = 0; idx != arr.length; idx++) {195			org.junit.Assert.assertNull(arr[idx]);196		}197198		String[] arr2 = hset.toArray(new String[hset.size()]);199		org.junit.Assert.assertEquals(1, arr2.length);200		for (int idx = 0; idx != arr.length; idx++) {201			org.junit.Assert.assertNull(arr[idx]);202		}203204		hset.clear();205		org.junit.Assert.assertTrue(hset.isEmpty());206		org.junit.Assert.assertEquals(0, hset.size());207208		org.junit.Assert.assertTrue(hset.add("one"));209		org.junit.Assert.assertTrue(hset.add(null));210		org.junit.Assert.assertEquals(2, hset.size());211		org.junit.Assert.assertTrue(hset.contains("one"));212		org.junit.Assert.assertTrue(hset.contains(null));213214		if (stype == SetTypeID.STYP_GREY) {215			HashedSet<String> hs = (HashedSet<String>)hset;216			org.junit.Assert.assertNull(hs.get(null));217		}218	}219220	@org.junit.Test221	public void testCollections()222	{223		java.util.Set<String> jset_orig = new java.util.HashSet<String>();224		jset_orig.add("one");225		jset_orig.add("two");226		jset_orig.add("three");227228		java.util.Set<String> hset = allocSet(-1, 0);229		java.util.Set<String> jset = new java.util.HashSet<String>();230		jset.addAll(jset_orig);231		org.junit.Assert.assertTrue(hset.addAll(jset));232		org.junit.Assert.assertEquals(3, hset.size());233		org.junit.Assert.assertTrue(hset.containsAll(jset));234		org.junit.Assert.assertFalse(hset.addAll(jset));235		org.junit.Assert.assertEquals(3, hset.size());236		org.junit.Assert.assertTrue(hset.containsAll(jset));237238		jset.remove("one");239		org.junit.Assert.assertTrue(hset.retainAll(jset));240		org.junit.Assert.assertEquals(2, hset.size());241		org.junit.Assert.assertTrue(hset.containsAll(jset));242		org.junit.Assert.assertFalse(hset.retainAll(jset));243		org.junit.Assert.assertEquals(2, hset.size());244		org.junit.Assert.assertTrue(hset.containsAll(jset));245246		hset.add("extra");247		org.junit.Assert.assertTrue(hset.removeAll(jset));248		org.junit.Assert.assertEquals(1, hset.size());249		org.junit.Assert.assertTrue(hset.contains("extra"));250		org.junit.Assert.assertFalse(hset.containsAll(jset));251		org.junit.Assert.assertFalse(hset.removeAll(jset));252		org.junit.Assert.assertEquals(1, hset.size());253		org.junit.Assert.assertTrue(hset.contains("extra"));254	}255256	@org.junit.Test257	final public void testRecycledIterators()258	{259		if (stype != SetTypeID.STYP_GREY) return;260		HashedSet<Integer> hset = new HashedSet<Integer>();261		hset.add(1);262		hset.add(2);263		hset.add(3);264		int itercnt_exp = hset.size();265266		java.util.Iterator<Integer> iter = hset.recycledIterator();267		int itercnt = 0;268		boolean found_it = false;269		while (iter.hasNext()) {270			int num = iter.next();271			if (num == 2) found_it = true;272			itercnt++;273		}274		org.junit.Assert.assertEquals(itercnt, itercnt_exp);275		org.junit.Assert.assertTrue(found_it);276277		java.util.Iterator<Integer> iter2 = hset.recycledIterator();278		org.junit.Assert.assertSame(iter, iter2);279		itercnt = 0;280		found_it = false;281		while (iter.hasNext()) {282			int num = iter.next();283			if (num == 2) found_it = true;284			itercnt++;285		}286		org.junit.Assert.assertEquals(itercnt, itercnt_exp);287		org.junit.Assert.assertTrue(found_it);288	}289290	@org.junit.Test291	final public void testGrow()292	{293		if (stype == SetTypeID.STYP_JDK) return;294		final HashedSet<String> hset = new HashedSet<String>(3, 10);295		final int cap1 = getCapacity(hset);296		int cnt = 0;297		String str1 = null;298		String strlast = null;299300		while (getCapacity(hset) == cap1) {301			String str = String.valueOf(++cnt);302			boolean isnew = hset.add(str);303			org.junit.Assert.assertTrue(isnew);304			if (str1 == null) str1 = str;305			strlast = str;306		}307		int cap2 = getCapacity(hset);308		int cap3 = hset.trimToSize();309		org.junit.Assert.assertEquals(cap2, cap3);310		org.junit.Assert.assertEquals(cap3, getCapacity(hset));311		org.junit.Assert.assertEquals(cap3, hset.trimToSize());312		org.junit.Assert.assertTrue(hset.contains(str1));313		org.junit.Assert.assertTrue(hset.contains(strlast));314		hset.clear();315		org.junit.Assert.assertEquals(1, hset.trimToSize());316		org.junit.Assert.assertEquals(1, getCapacity(hset));317	}318319	@org.junit.Test320	final public void bulktest()321	{322		java.text.DecimalFormat formatter = new java.text.DecimalFormat("#,###");323		long total_duration = 0;324		long min_duration = Long.MAX_VALUE;325		long[] duration = new long[SOAK_RUNS];326		int warmuploops = SOAK_WARMUPS;327		for (int loop = 0; loop != warmuploops + duration.length; loop++) {328			long time1 = System.nanoTime();329			runSoak();330			if (loop < warmuploops) continue;331			int idx = loop - warmuploops;332			duration[idx] = System.nanoTime() - time1;333			if (duration[idx] < min_duration) min_duration = duration[idx];334			total_duration += duration[idx];335		}336		System.out.print("Set="+stype+" bulktest: ");337		String dlm = "";338		for (int loop = 0; loop != duration.length; loop++) {339			System.out.print(dlm+formatter.format(duration[loop]));340			dlm = " : ";341		}342		System.out.println(" - Avg="+formatter.format(total_duration/duration.length)343								+", Min="+formatter.format(min_duration));344	}345346	private void runSoak()347	{348		final int cap = SOAK_SIZE; //ramp up to investigate manually349		java.util.Set<String> set = allocSet(0, 5);350		// general put-get351		for (int v = 0; v != cap; v++) {352			String s = String.valueOf(v);353			org.junit.Assert.assertTrue(set.add(s));354			org.junit.Assert.assertFalse(set.add(s));355		}356		org.junit.Assert.assertEquals(cap, set.size());357		for (int v = 0; v != cap; v++) org.junit.Assert.assertFalse(set.add(String.valueOf(v)));358		org.junit.Assert.assertEquals(cap, set.size());359		org.junit.Assert.assertFalse(set.remove(null));360		org.junit.Assert.assertEquals(cap, set.size());361		org.junit.Assert.assertEquals(cap, set.size());362		org.junit.Assert.assertTrue(set.add(null));363		org.junit.Assert.assertEquals(cap+1, set.size());364		for (int v = 0; v != cap; v++) org.junit.Assert.assertTrue(set.contains(String.valueOf(v)));365		org.junit.Assert.assertTrue(set.contains(null));366		// iterators367		java.util.HashSet<String> jset = new java.util.HashSet<String>();368		java.util.Iterator<String> it = set.iterator();369		while (it.hasNext()) {370			jset.add(it.next());371			it.remove();372		}373		org.junit.Assert.assertEquals(0, set.size());374		org.junit.Assert.assertEquals(cap+1, jset.size());375		for (int v = 0; v != cap; v++) {376			String s = String.valueOf(v);377			org.junit.Assert.assertFalse(set.contains(s));378			org.junit.Assert.assertTrue(jset.contains(s));379		}380		org.junit.Assert.assertTrue(jset.contains(null));381		org.junit.Assert.assertFalse(set.contains(null));382		//restore and remove383		set.addAll(jset);384		org.junit.Assert.assertEquals(cap+1, jset.size());385		org.junit.Assert.assertEquals(cap+1, set.size());386		org.junit.Assert.assertTrue(set.contains(null));387		for (int v = 0; v != cap; v++) {388			String s = String.valueOf(v);389			org.junit.Assert.assertTrue(set.contains(s));390			org.junit.Assert.assertTrue(set.remove(s));391			org.junit.Assert.assertFalse(set.contains(s));392			org.junit.Assert.assertFalse(set.remove(s));393			org.junit.Assert.assertFalse(set.contains(s));394		}395		org.junit.Assert.assertEquals(1, set.size());396		org.junit.Assert.assertTrue(set.contains(null));397		org.junit.Assert.assertTrue(set.remove(null));398		org.junit.Assert.assertFalse(set.contains(null));399		org.junit.Assert.assertEquals(0, set.size());400		org.junit.Assert.assertEquals(cap+1, jset.size());401	}402403	private java.util.Set<String> allocSet(int initcap, float factor) {404		switch (stype) {405		case STYP_JDK:406			if (initcap == -1) return new java.util.HashSet<String>();407			return new java.util.HashSet<String>(initcap, factor);408		case STYP_GREY:409			if (initcap == -1) return new HashedSet<String>();410			return new HashedSet<String>(initcap, factor);411		default:412			throw new IllegalStateException("Missing case for set-type="+stype);
...Source:TestBeforeAndAfter.java  
...49            }50            private void myAfter() {51                org.junit.Assert.assertTrue(beforeCalled[0]);52                org.junit.Assert.assertTrue(methodCalled[0]);53                org.junit.Assert.assertFalse(afterCalled[0]);54                afterCalled[0] = true;55                afterCounter[0]++;56            }57            private void myBefore() {58                org.junit.Assert.assertFalse(beforeCalled[0]);59                org.junit.Assert.assertFalse(methodCalled[0]);60                org.junit.Assert.assertFalse(afterCalled[0]);61                beforeCalled[0] = true;62                beforeCounter[0]++;63            }64            @TestCase65            @Before("myBefore")66            @After("myAfter")67            @TestData("mySetup")68            public void test(int i) {69                org.junit.Assert.assertFalse(afterCalled[0]);70                org.junit.Assert.assertTrue(beforeCalled[0]);71                methodCalled[0] = true;72                methodCounter[0]++;73            }74        }, TU.EMPTY_ARGV);75        Assert.assertTrue(status.isOK());76        Assert.assertTrue(afterCalled[0]);77        Assert.assertTrue(beforeCalled[0]);78        Assert.assertTrue(methodCalled[0]);79        Assert.assertEquals(3, methodCounter[0]);80        Assert.assertEquals(1, afterCounter[0]);81        Assert.assertEquals(1, beforeCounter[0]);82    }83    @Test84    public void plain_NoArgs() {85        final boolean[] afterCalled = new boolean[1];86        final boolean[] beforeCalled = new boolean[1];87        final boolean[] methodCalled = new boolean[1];88        final int[] methodCounter = new int[]{0};89        final int[] afterCounter = new int[]{0};90        final int[] beforeCounter = new int[]{0};91        com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {92            protected Values mySetup() {93                return DataFactory.createColumn(1, 2, 3);94            }95            private void myAfter() {96                org.junit.Assert.assertTrue(beforeCalled[0]);97                org.junit.Assert.assertTrue(methodCalled[0]);98                org.junit.Assert.assertFalse(afterCalled[0]);99                afterCalled[0] = true;100                afterCounter[0]++;101            }102            private void myBefore() {103                org.junit.Assert.assertFalse(beforeCalled[0]);104                org.junit.Assert.assertFalse(methodCalled[0]);105                org.junit.Assert.assertFalse(afterCalled[0]);106                beforeCalled[0] = true;107                beforeCounter[0]++;108            }109            @Before("myBefore")110            @After("myAfter")111            @TestCase112            public void testWithNoArguments() {113                org.junit.Assert.assertFalse(afterCalled[0]);114                org.junit.Assert.assertTrue(beforeCalled[0]);115                methodCalled[0] = true;116                methodCounter[0]++;117            }118        }, TU.EMPTY_ARGV);119        Assert.assertTrue(status.isOK());120        Assert.assertTrue(afterCalled[0]);121        Assert.assertTrue(beforeCalled[0]);122        Assert.assertTrue(methodCalled[0]);123        Assert.assertEquals(1, methodCounter[0]);124        Assert.assertEquals(1, afterCounter[0]);125        Assert.assertEquals(1, beforeCounter[0]);126    }127    @Test128    public void beforeThrowsException() {129        final boolean[] afterCalled = new boolean[1];130        final boolean[] beforeCalled = new boolean[1];131        final boolean[] methodCalled = new boolean[1];132        final int[] methodCounter = new int[]{0};133        final int[] afterCounter = new int[]{0};134        final int[] beforeCounter = new int[]{0};135        com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {136            protected Values mySetup() {137                return DataFactory.createColumn(1, 2, 3);138            }139            private void myAfter() {140                afterCalled[0] = true;141                afterCounter[0]++;142                org.junit.Assert.fail("This must not be called");143            }144            private void myBefore() {145                org.junit.Assert.assertFalse(beforeCalled[0]);146                org.junit.Assert.assertFalse(methodCalled[0]);147                org.junit.Assert.assertFalse(afterCalled[0]);148                beforeCalled[0] = true;149                beforeCounter[0]++;150                throw new RuntimeException("Exception thrown from before");151            }152            @TestCase153            @Before("myBefore")154            @After("myAfter")155            @TestData("mySetup")156            public void test(int i) {157                methodCalled[0] = true;158                methodCounter[0]++;159                org.junit.Assert.fail("This must not be called");160            }161        }, TU.EMPTY_ARGV);162        Assert.assertFalse(status.isOK());163        Assert.assertFalse(afterCalled[0]);164        Assert.assertTrue(beforeCalled[0]);165        Assert.assertFalse(methodCalled[0]);166        Assert.assertEquals(0, methodCounter[0]);167        Assert.assertEquals(0, afterCounter[0]);168        Assert.assertEquals(1, beforeCounter[0]);169    }170    @Test171    public void beforeThrowsException_NoParams() {172        final boolean[] afterCalled = new boolean[1];173        final boolean[] beforeCalled = new boolean[1];174        final boolean[] methodCalled = new boolean[1];175        final int[] methodCounter = new int[]{0};176        final int[] afterCounter = new int[]{0};177        final int[] beforeCounter = new int[]{0};178        com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {179            protected Values mySetup() {180                return DataFactory.createColumn(1, 2, 3);181            }182            private void myAfter() {183                afterCalled[0] = true;184                afterCounter[0]++;185                org.junit.Assert.fail("This must not be called");186            }187            private void myBefore() {188                org.junit.Assert.assertFalse(beforeCalled[0]);189                org.junit.Assert.assertFalse(methodCalled[0]);190                org.junit.Assert.assertFalse(afterCalled[0]);191                beforeCalled[0] = true;192                beforeCounter[0]++;193                throw new RuntimeException("Exception thrown from before");194            }195            @TestCase196            @Before("myBefore")197            @After("myAfter")198            public void test() {199                methodCalled[0] = true;200                methodCounter[0]++;201                org.junit.Assert.fail("This must not be called");202            }203        }, TU.EMPTY_ARGV);204        Assert.assertFalse(status.isOK());205        Assert.assertFalse(afterCalled[0]);206        Assert.assertTrue(beforeCalled[0]);207        Assert.assertFalse(methodCalled[0]);208        Assert.assertEquals(0, methodCounter[0]);209        Assert.assertEquals(0, afterCounter[0]);210        Assert.assertEquals(1, beforeCounter[0]);211    }212}...Source:AdminInputValidationTest.java  
...12        assertTrue(AdminInputValidation.configName("4094320823"));13    }14    @org.junit.jupiter.api.Test15    void invalidConfigName() {16        assertFalse(AdminInputValidation.name(""));17        assertFalse(AdminInputValidation.name("   "));18        assertFalse(AdminInputValidation.name("My;Computer"));19        assertFalse(AdminInputValidation.name("My:Computer"));20    }21    @org.junit.jupiter.api.Test22    void validName() {23        assertTrue(AdminInputValidation.name("x230"));24        assertTrue(AdminInputValidation.name("X230"));25        assertTrue(AdminInputValidation.name("X 230"));26        assertTrue(AdminInputValidation.name("X-230!"));27        assertTrue(AdminInputValidation.name("4299032"));28    }29    @org.junit.jupiter.api.Test30    void invalidName() {31        assertFalse(AdminInputValidation.name(""));32        assertFalse(AdminInputValidation.name("   "));33        assertFalse(AdminInputValidation.name("X;230"));34    }35    @org.junit.jupiter.api.Test36    void validBrand() {37        assertTrue(AdminInputValidation.brand("Intel"));38        assertTrue(AdminInputValidation.brand("intel"));39        assertTrue(AdminInputValidation.brand("Intel Corporations"));40        assertTrue(AdminInputValidation.brand("Intel-Corporations"));41        assertTrue(AdminInputValidation.brand("8491289"));42    }43    @org.junit.jupiter.api.Test44    void invalidBrand() {45        assertFalse(AdminInputValidation.brand(""));46        assertFalse(AdminInputValidation.brand("   "));47        assertFalse(AdminInputValidation.brand("Intel;corporations"));48    }49    @org.junit.jupiter.api.Test50    void validPrice() {51        assertTrue(AdminInputValidation.price(0.1));52        assertTrue(AdminInputValidation.price(99999));53        assertTrue(AdminInputValidation.price(5.5));54    }55    @org.junit.jupiter.api.Test56    void invalidPrice() {57        assertFalse(AdminInputValidation.price(0));58        assertFalse(AdminInputValidation.price(-1));59        assertFalse(AdminInputValidation.price(100000));60    }61    @org.junit.jupiter.api.Test62    void validPerformanceValue() {63        assertTrue(AdminInputValidation.performanceValue(0.1));64        assertTrue(AdminInputValidation.performanceValue(100));65    }66    @org.junit.jupiter.api.Test67    void invalidPerformanceValue() {68        assertFalse(AdminInputValidation.performanceValue(-1));69        assertFalse(AdminInputValidation.performanceValue(0));70        assertFalse(AdminInputValidation.performanceValue(101));71    }72    @org.junit.jupiter.api.Test73    void validDimensions() {74        assertTrue(AdminInputValidation.dimensions("5x5x5"));75        assertTrue(AdminInputValidation.dimensions("999x999x999"));76    }77    @org.junit.jupiter.api.Test78    void invalidDimensions() {79        assertFalse(AdminInputValidation.dimensions("5X5X5"));80        assertFalse(AdminInputValidation.dimensions("-1x-1x-1"));81        assertFalse(AdminInputValidation.dimensions(""));82        assertFalse(AdminInputValidation.dimensions("      "));83        assertFalse(AdminInputValidation.dimensions("12 by 12 by 12"));84    }85    @org.junit.jupiter.api.Test86    void validColor() {87        assertTrue(AdminInputValidation.color("Blue"));88        assertTrue(AdminInputValidation.color("Lightblue"));89        assertTrue(AdminInputValidation.color("Light blue"));90        assertTrue(AdminInputValidation.color("Light-blue"));91    }92    @org.junit.jupiter.api.Test93    void invalidColor() {94        assertFalse(AdminInputValidation.color("blue"));95        assertFalse(AdminInputValidation.color("DArk blue"));96        assertFalse(AdminInputValidation.color("Blue-SKY"));97        assertFalse(AdminInputValidation.color("LightBlue"));98    }99    @org.junit.jupiter.api.Test100    void validClockSpeed() {101        assertTrue(AdminInputValidation.clockSpeed(100));102        assertTrue(AdminInputValidation.clockSpeed(0.1));103        assertTrue(AdminInputValidation.clockSpeed(50));104    }105    @org.junit.jupiter.api.Test106    void invalidClockSpeed() {107        assertFalse(AdminInputValidation.clockSpeed(0));108        assertFalse(AdminInputValidation.clockSpeed(-1));109        assertFalse(AdminInputValidation.clockSpeed(-100));110        assertFalse(AdminInputValidation.clockSpeed(101));111    }112    @org.junit.jupiter.api.Test113    void validCores() {114        assertTrue(AdminInputValidation.cores(128));115        assertTrue(AdminInputValidation.cores(2));116        assertTrue(AdminInputValidation.cores(50));117    }118    @org.junit.jupiter.api.Test119    void invalidCores() {120        assertFalse(AdminInputValidation.cores(0));121        assertFalse(AdminInputValidation.cores(3));122        assertFalse(AdminInputValidation.cores(129));123        assertFalse(AdminInputValidation.cores(-0));124        assertFalse(AdminInputValidation.cores(-1));125    }126    @org.junit.jupiter.api.Test127    void validLanguage() {128        assertTrue(AdminInputValidation.language("NOR"));129        assertTrue(AdminInputValidation.language("ENG"));130        assertTrue(AdminInputValidation.language("FRA"));131        assertTrue(AdminInputValidation.language("SWE"));132        assertTrue(AdminInputValidation.language("TOR"));133    }134    @org.junit.jupiter.api.Test135    void invalidLanguage() {136        assertFalse(AdminInputValidation.language("Norsk"));137        assertFalse(AdminInputValidation.language("English"));138        assertFalse(AdminInputValidation.language("Engelsk"));139        assertFalse(AdminInputValidation.language("Heisan"));140        assertFalse(AdminInputValidation.language("Tegnespråk"));141    }142    @org.junit.jupiter.api.Test143    void validCapacity() {144        assertTrue(AdminInputValidation.capacity(1));145        assertTrue(AdminInputValidation.capacity(50));146        assertTrue(AdminInputValidation.capacity(5000));147        assertTrue(AdminInputValidation.capacity(20000));148    }149    @org.junit.jupiter.api.Test150    void invalidCapacity() {151        assertFalse(AdminInputValidation.capacity(-1));152        assertFalse(AdminInputValidation.capacity(-100));153        assertFalse(AdminInputValidation.capacity(0));154        assertFalse(AdminInputValidation.capacity(20001));155    }156    @org.junit.jupiter.api.Test157    void validMemory() {158        assertTrue(AdminInputValidation.memory(2));159        assertTrue(AdminInputValidation.memory(50));160        assertTrue(AdminInputValidation.memory(5000));161        assertTrue(AdminInputValidation.memory(256000));162    }163    @org.junit.jupiter.api.Test164    void invalidMemory() {165        assertFalse(AdminInputValidation.memory(-1));166        assertFalse(AdminInputValidation.memory(-100));167        assertFalse(AdminInputValidation.memory(0));168        assertFalse(AdminInputValidation.memory(256001));169    }170    @org.junit.jupiter.api.Test171    void validMemorySpeed() {172        assertTrue(AdminInputValidation.memorySpeed(1));173        assertTrue(AdminInputValidation.memorySpeed(50));174        assertTrue(AdminInputValidation.memorySpeed(5000));175        assertTrue(AdminInputValidation.memorySpeed(10000));176    }177    @org.junit.jupiter.api.Test178    void invalidMemorySpeed() {179        assertFalse(AdminInputValidation.memorySpeed(0));180        assertFalse(AdminInputValidation.memorySpeed(-1));181        assertFalse(AdminInputValidation.memorySpeed(-100));182        assertFalse(AdminInputValidation.memorySpeed(10001));183    }184    @org.junit.jupiter.api.Test185    void validWatt() {186        assertTrue(AdminInputValidation.watt(1));187        assertTrue(AdminInputValidation.watt(50));188        assertTrue(AdminInputValidation.watt(5000));189        assertTrue(AdminInputValidation.watt(10000));190    }191    @org.junit.jupiter.api.Test192    void invalidWatt() {193        assertFalse(AdminInputValidation.watt(10001));194        assertFalse(AdminInputValidation.watt(-1));195        assertFalse(AdminInputValidation.watt(-100));196        assertFalse(AdminInputValidation.watt(0));197    }198    @org.junit.jupiter.api.Test199    void validSize() {200        assertTrue(AdminInputValidation.size(1));201        assertTrue(AdminInputValidation.size(27));202        assertTrue(AdminInputValidation.size(50));203        assertTrue(AdminInputValidation.size(300));204    }205    @org.junit.jupiter.api.Test206    void invalidSize() {207        assertFalse(AdminInputValidation.size(301));208        assertFalse(AdminInputValidation.size(0));209        assertFalse(AdminInputValidation.size(-1));210        assertFalse(AdminInputValidation.size(-100));211    }212}...Source:DigitUtilityTest.java  
...13//        this.digitUtility.initKansuji("ja");14//    }15    @Test16    void testIsHankakusuji() {17        org.junit.Assert.assertFalse(this.digitUtility.isZenkakusuji('1'));18        org.junit.Assert.assertTrue(this.digitUtility.isZenkakusuji('ï¼'));19        org.junit.Assert.assertFalse(this.digitUtility.isZenkakusuji('ä¸'));20        org.junit.Assert.assertFalse(this.digitUtility.isZenkakusuji('ã'));21    }22    @Test23    void testIsZenkakusuji() {24    }25    @Test26    void testIsArabic() {27        org.junit.Assert.assertTrue(this.digitUtility.isArabic('1'));28        org.junit.Assert.assertTrue(this.digitUtility.isArabic('ï¼'));29        org.junit.Assert.assertFalse(this.digitUtility.isArabic('ä¸'));30        org.junit.Assert.assertFalse(this.digitUtility.isArabic('ã'));31    }32    @Test33    void testIsKansuji() {34        org.junit.Assert.assertFalse(this.digitUtility.isKansuji('1'));35        org.junit.Assert.assertFalse(this.digitUtility.isKansuji('ï¼'));36        org.junit.Assert.assertTrue(this.digitUtility.isKansuji('ä¸'));37        org.junit.Assert.assertFalse(this.digitUtility.isKansuji('ã'));38    }39    @Test40    void testIsKansuji09() {41        org.junit.Assert.assertFalse(this.digitUtility.isKansuji09('1'));42        org.junit.Assert.assertFalse(this.digitUtility.isKansuji09('ï¼'));43        org.junit.Assert.assertTrue(this.digitUtility.isKansuji09('ä¸'));44        org.junit.Assert.assertFalse(this.digitUtility.isKansuji09('å'));45        org.junit.Assert.assertFalse(this.digitUtility.isKansuji09('ä¸'));46        org.junit.Assert.assertFalse(this.digitUtility.isKansuji09('ã'));47    }48    @Test49    void testIsKansujiKuraiSen() {50        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiSen('1'));51        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiSen('ï¼'));52        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiSen('ä¸'));53        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKuraiSen('å'));54        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKuraiSen('ç¾'));55        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKuraiSen('å'));56        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiSen('ä¸'));57        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiSen('ã'));58    }59    @Test60    void testIsKansujiKuraiMan() {61        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiMan('1'));62        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiMan('ï¼'));63        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiMan('ä¸'));64        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiMan('å'));65        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKuraiMan('ä¸'));66        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKuraiMan('å'));67        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKuraiMan('å
'));68        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKuraiMan('ã'));69    }70    @Test71    void testIsKansujiKurai() {72        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKurai('1'));73        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKurai('ï¼'));74        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKurai('ä¸'));75        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKurai('å'));76        org.junit.Assert.assertTrue(this.digitUtility.isKansujiKurai('ä¸'));77        org.junit.Assert.assertFalse(this.digitUtility.isKansujiKurai('ã'));78    }79    @Test80    void testIsNumber() {81        org.junit.Assert.assertTrue(this.digitUtility.isNumber('1'));82        org.junit.Assert.assertTrue(this.digitUtility.isNumber('ï¼'));83        org.junit.Assert.assertTrue(this.digitUtility.isNumber('ä¸'));84        org.junit.Assert.assertTrue(this.digitUtility.isNumber('å'));85        org.junit.Assert.assertTrue(this.digitUtility.isNumber('ä¸'));86        org.junit.Assert.assertFalse(this.digitUtility.isNumber('ã'));87    }88//    @Test89//    void testIsComma() {90//91//        // Assertions.fail('ã¾ã å®è£
ããã¦ãã¾ãã');92//    }93//94//95    @Test96    void testIsDecimalPoint() {97        // Assertions.fail('ã¾ã å®è£
ããã¦ãã¾ãã');98        org.junit.Assert.assertTrue(this.digitUtility.isDecimalPoint('ï¼'));99    }100//...Source:M6Test.java  
...32            Assertions.assertEquals(sub1, sub1);33            Assertions.assertNotEquals(sub1, neg1);34            Assertions.assertEquals(neg1, neg1);35            Assertions.assertNotEquals(neg1, mult1);36            org.junit.jupiter.api.Assertions.assertFalse(lit1.accept(makeEql(lit2)));37            org.junit.jupiter.api.Assertions.assertTrue(lit1.accept(makeEql(lit1)));38            org.junit.jupiter.api.Assertions.assertFalse(mult1.accept(makeEql(lit2)));39            org.junit.jupiter.api.Assertions.assertTrue(mult1.accept(makeEql(mult1)));40            org.junit.jupiter.api.Assertions.assertFalse(mult1.accept(makeEql(divd1)));41            org.junit.jupiter.api.Assertions.assertTrue(divd1.accept(makeEql(divd1)));42            org.junit.jupiter.api.Assertions.assertFalse(divd1.accept(makeEql(add1)));43            org.junit.jupiter.api.Assertions.assertTrue(add1.accept(makeEql(add1)));44            org.junit.jupiter.api.Assertions.assertFalse(add1.accept(makeEql(sub1)));45            org.junit.jupiter.api.Assertions.assertTrue(sub1.accept(makeEql(sub1)));46            org.junit.jupiter.api.Assertions.assertFalse(sub1.accept(makeEql(neg1)));47            org.junit.jupiter.api.Assertions.assertTrue(neg1.accept(makeEql(neg1)));48            org.junit.jupiter.api.Assertions.assertFalse(neg1.accept(makeEql(mult1)));49            org.junit.jupiter.api.Assertions.assertTrue(lit1.accept(makeEquals(lit1)));50            org.junit.jupiter.api.Assertions.assertFalse(mult1.accept(makeEquals(lit2)));51            org.junit.jupiter.api.Assertions.assertTrue(mult1.accept(makeEquals(mult1)));52            org.junit.jupiter.api.Assertions.assertFalse(mult1.accept(makeEquals(divd1)));53            org.junit.jupiter.api.Assertions.assertTrue(divd1.accept(makeEquals(divd1)));54            org.junit.jupiter.api.Assertions.assertFalse(divd1.accept(makeEquals(add1)));55            org.junit.jupiter.api.Assertions.assertTrue(add1.accept(makeEquals(add1)));56            org.junit.jupiter.api.Assertions.assertFalse(add1.accept(makeEquals(sub1)));57            org.junit.jupiter.api.Assertions.assertTrue(sub1.accept(makeEquals(sub1)));58            org.junit.jupiter.api.Assertions.assertFalse(sub1.accept(makeEquals(neg1)));59            org.junit.jupiter.api.Assertions.assertTrue(neg1.accept(makeEquals(neg1)));60            org.junit.jupiter.api.Assertions.assertFalse(neg1.accept(makeEquals(mult1)));61            org.junit.jupiter.api.Assertions.assertTrue(new Sub(new Lit(1.0), new Lit(73.0)).accept(makeEql(new Sub(new Lit(1.0), new Lit(73.0)))));62            org.junit.jupiter.api.Assertions.assertFalse(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0)).accept(makeEql(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(3.0)))));63            org.junit.jupiter.api.Assertions.assertTrue(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0)).accept(makeEql(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0)))));64            org.junit.jupiter.api.Assertions.assertTrue(new Neg(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0))).accept(makeEql(new Neg(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0))))));65            org.junit.jupiter.api.Assertions.assertFalse(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0)).accept(makeEql(new Neg(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(4.0))))));66            org.junit.jupiter.api.Assertions.assertFalse(new Divd(new Lit(6.0), new Lit(2.0)).accept(makeEql(new Divd(new Lit(8.0), new Lit(2.0)))));67            org.junit.jupiter.api.Assertions.assertTrue(new Divd(new Lit(6.0), new Lit(2.0)).accept(makeEql(new Divd(new Lit(6.0), new Lit(2.0)))));68            org.junit.jupiter.api.Assertions.assertTrue(new Add(new Lit(5.0), new Lit(3.0)).accept(makeEql(new Add(new Lit(5.0), new Lit(3.0)))));69            org.junit.jupiter.api.Assertions.assertFalse(new Add(new Lit(5.0), new Lit(3.0)).accept(makeEql(new Mult(new Divd(new Lit(5.0), new Lit(2.0)), new Lit(3.0)))));70        }71        default VisitorDivdMultNeg<Boolean> makeEql(Exp exp) { return new Eql(exp); }72        default VisitorDivdMultNeg<Boolean> makeEquals(Exp exp) { return new Equals(exp); }73    }74    private static class ActualTest implements M5Test.TestTemplate {}75    @Test76    public void testTest() { new ActualTest().test(); }77}...Source:AnalyzedImportTest.java  
...21	private static final String ORG_JUNIT = "org.junit";22	private static final String ORG_JUNIT_TEST = "org.junit.Test";23	private static final String ORG_JUNIT_STAR = "org.junit.*";24	private static final String ORG_JUNIT_ASSERT = "org.junit.Assert";25	private static final String ORG_JUNIT_ASSERT_FALSE = "org.junit.Assert.assertFalse";26	private static final String ORG_JUNIT_ASSERT_EQUALS = "org.junit.Assert.assertEquals";27	private static final String ORG_JUNIT_ASSERT_STAR = "org.junit.Assert.*";28	@Test29	public void testBasicImport() {30		AnalyzedImport i = new AnalyzedImport(loc(), ORG_JUNIT_TEST, false,31				false);32		assertEquals(ORG_JUNIT_TEST, i.getStatement());33		assertFalse(i.isAsterisk());34		assertFalse(i.isStaticImport());35		assertTrue(i.matchesClass(ORG_JUNIT_TEST));36		assertFalse(i.matchesClass(ORG_JUNIT));37		assertFalse(i.matchesClass(ORG_JUNIT_STAR));38		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT));39		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_FALSE));40		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_STAR));41		assertFalse(i.importsMethodStatically(ORG_JUNIT_TEST));42		assertFalse(i.importsMethodStatically(ORG_JUNIT));43		assertFalse(i.importsMethodStatically(ORG_JUNIT_STAR));44		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT));45		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_FALSE));46		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_EQUALS));47		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_STAR));48	}49	@Test50	public void testPackageImport() {51		AnalyzedImport i = new AnalyzedImport(loc(), ORG_JUNIT, false, true);52		assertEquals(ORG_JUNIT, i.getStatement());53		assertTrue(i.isAsterisk());54		assertFalse(i.isStaticImport());55		assertTrue(i.matchesClass(ORG_JUNIT_TEST));56		assertFalse(i.matchesClass(ORG_JUNIT));57		assertFalse(i.matchesClass(ORG_JUNIT_STAR));58		assertTrue(i.matchesClass(ORG_JUNIT_ASSERT));59		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_FALSE));60		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_STAR));61		assertFalse(i.importsMethodStatically(ORG_JUNIT_TEST));62		assertFalse(i.importsMethodStatically(ORG_JUNIT));63		assertFalse(i.importsMethodStatically(ORG_JUNIT_STAR));64		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT));65		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_FALSE));66		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_EQUALS));67		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_STAR));68	}69	@Test70	public void testStaticImport() {71		AnalyzedImport i = new AnalyzedImport(loc(), ORG_JUNIT_ASSERT_FALSE,72				true, false);73		assertEquals(ORG_JUNIT_ASSERT_FALSE, i.getStatement());74		assertFalse(i.isAsterisk());75		assertTrue(i.isStaticImport());76		assertFalse(i.matchesClass(ORG_JUNIT_TEST));77		assertFalse(i.matchesClass(ORG_JUNIT));78		assertFalse(i.matchesClass(ORG_JUNIT_STAR));79		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT));80		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_FALSE));81		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_STAR));82		assertFalse(i.importsMethodStatically(ORG_JUNIT_TEST));83		assertFalse(i.importsMethodStatically(ORG_JUNIT));84		assertFalse(i.importsMethodStatically(ORG_JUNIT_STAR));85		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT));86		assertTrue(i.importsMethodStatically(ORG_JUNIT_ASSERT_FALSE));87		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_EQUALS));88		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_STAR));89	}90	@Test91	public void testStaticStarImport() {92		AnalyzedImport i = new AnalyzedImport(loc(), ORG_JUNIT_ASSERT, true,93				true);94		assertEquals(ORG_JUNIT_ASSERT, i.getStatement());95		assertTrue(i.isAsterisk());96		assertTrue(i.isStaticImport());97		assertFalse(i.matchesClass(ORG_JUNIT_TEST));98		assertFalse(i.matchesClass(ORG_JUNIT));99		assertFalse(i.matchesClass(ORG_JUNIT_STAR));100		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT));101		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_FALSE));102		assertFalse(i.matchesClass(ORG_JUNIT_ASSERT_STAR));103		assertFalse(i.importsMethodStatically(ORG_JUNIT_TEST));104		assertFalse(i.importsMethodStatically(ORG_JUNIT));105		assertFalse(i.importsMethodStatically(ORG_JUNIT_STAR));106		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT));107		assertTrue(i.importsMethodStatically(ORG_JUNIT_ASSERT_EQUALS));108		assertTrue(i.importsMethodStatically(ORG_JUNIT_ASSERT_FALSE));109		assertFalse(i.importsMethodStatically(ORG_JUNIT_ASSERT_STAR));110	}111	private Location loc() {112		return new Location(15, 35);113	}114}...Source:Test.java  
1package com.revature.util; 2import static org.junit.Assert.assertEquals;3import static org.junit.Assert.assertFalse;4import static org.junit.Assert.assertTrue;5import com.revature.dao.*;6import com.revature.models.Account;7import com.revature.models.User;8import com.revature.service.AccountService;9import com.revature.service.AccountServiceImpl;10public class Test {11	AccountService ac = new AccountServiceImpl();12	AccountDAO aDao = new AccountDAOImpl();13	UserDAO uDao = new UserDAOImpl();14	15	public void main(String[] args) {16		this.TestEmail();17	}18	19	20	@org.junit.Test21	public void TestEmail() {22		assertTrue(ac.verifyEmailInput("testh@d.ds"));23		assertTrue(ac.verifyEmailInput("test@h.ds"));24		assertFalse(ac.verifyEmailInput("test@h.s"));25		assertFalse(ac.verifyEmailInput("testh.ss"));26		assertFalse(ac.verifyEmailInput("@h.ss"));27	}28	29	@org.junit.Test30	public void TestPhoneNumber() {31		assertTrue(ac.verifyPhoneNumberInput("1111111111"));32		assertTrue(ac.verifyPhoneNumberInput("1234567890"));33		assertFalse(ac.verifyPhoneNumberInput("111"));34		assertFalse(ac.verifyPhoneNumberInput("@@@@@@@@@@"));35		assertFalse(ac.verifyPhoneNumberInput("%11"));36	}37	38	@org.junit.Test39	public void TestUsername() {40		assertTrue(ac.verifyUsernameInput("12345@78"));41		assertTrue(ac.verifyUsernameInput("12345abc"));42		assertFalse(ac.verifyUsernameInput(""));43		assertFalse(ac.verifyUsernameInput("1234"));44		assertFalse(ac.verifyUsernameInput("123ab"));45	}46	47	@org.junit.Test48	public void TestPassword() {49		assertTrue(ac.verifyUsernameInput("123456@8"));50		assertTrue(ac.verifyUsernameInput("12345abc"));51		assertFalse(ac.verifyUsernameInput(""));52		assertFalse(ac.verifyUsernameInput("1234"));53		assertFalse(ac.verifyUsernameInput("123ab"));54	}55	56	@org.junit.Test57	public void TestInsertAccount() {58		Account account1 = new Account(1, 8, 100, false);59		Account account2 = new Account(1, 8, 100, false);60		Account account3 = new Account(1, 8, 100, false);61		Account account4 = new Account(1, 8, 100, false);62		assertTrue(aDao.InsertAccount(account1));63		assertTrue(aDao.InsertAccount(account2));64		assertTrue(aDao.InsertAccount(account3));65		assertTrue(aDao.InsertAccount(account4));66	}67	...assertFalse
Using AI Code Generation
1import org.junit.Assert;2import org.junit.Test;3import org.hamcrest.MatcherAssert;4import org.hamcrest.Matchers;5import org.hamcrest.CoreMatchers;6import org.hamcrest.collection.IsArrayContaining;7import org.hamcrest.collection.IsIterableContainingInOrder;8import org.hamcrest.collection.IsIterableContainingInAnyOrder;9import org.hamcrest.collection.IsMapContaining;10import org.hamcrest.collection.IsMapContaining;11import org.hamcrest.collection.IsMapContaining;12public class AssertsTest {13	public void testAssertFalse() {14		Assert.assertFalse(false);15	}16	public void testAssertTrue() {17		Assert.assertTrue(true);18	}19	public void testAssertNotNull() {20		Assert.assertNotNull(new Object());21	}22	public void testAssertNull() {23		Assert.assertNull(null);24	}25	public void testAssertSame() {26		Integer aNumber = Integer.valueOf(768);27		Assert.assertSame(aNumber, aNumber);28	}29	public void testAssertNotSame() {30		Assert.assertNotSame(Integer.valueOf(768), Integer.valueOf(768));31	}32	public void testFail() {33		Assert.fail("Not yet implemented");34	}35	public void testAssertThatHamcrestCoreMatchers() {36		MatcherAssert.assertThat("good", CoreMatchers.is("good"));37		MatcherAssert.assertThat("good", CoreMatchers.not("bad"));38		MatcherAssert.assertThat("good", CoreMatchers.anyOf(CoreMatchers.is("good"), CoreMatchers.is("bad")));39		MatcherAssert.assertThat("good", CoreMatchers.allOf(CoreMatchers.startsWith("good"), CoreMatchers.endsWith("good")));40	}assertFalse
Using AI Code Generation
1import org.junit.Assert;2import org.junit.Test;3public class TestAssertFalse {4   public void testAssertFalse() {5      Assert.assertFalse("failure - should be false", false);6   }7}8import org.junit.Assert;9import org.junit.Test;10public class TestAssertTrue {11   public void testAssertTrue() {12      Assert.assertTrue("failure - should be true", true);13   }14}15import org.junit.Assert;16import org.junit.Test;17public class TestAssertNotNull {18   public void testAssertNotNull() {19      Assert.assertNotNull("should not be null", new Object());20   }21}22import org.junit.Assert;23import org.junit.Test;24public class TestAssertNull {25   public void testAssertNull() {26      Assert.assertNull("should be null", null);27   }28}29import org.junit.Assert;30import org.junit.Test;31public class TestAssertSame {32   public void testAssertSame() {33      Integer aNumber = Integer.valueOf(768);34      Assert.assertSame("should be same", aNumber, aNumber);35   }36}37import org.junit.Assert;38import org.junit.Test;39public class TestAssertNotSame {40   public void testAssertNotSame() {41      Integer aNumber = Integer.valueOf(768);42      Integer bNumber = Integer.valueOf(768);43      Assert.assertNotSame("should not be same", aNumber, bNumber);44   }45}46import org.junit.Assert;47import org.junit.Test;48public class TestAssertEquals {49   public void testAssertEquals() {50      Assert.assertEquals("failure - strings are not equal", "text", "text");51   }52}53import org.junit.Assert;54import org.junit.Test;55public class TestAssertArrayEquals {56   public void testAssertArrayEquals() {57      byte[] expected = "trial".getBytes();58      byte[] actual = "trial".getBytes();59      Assert.assertArrayEquals("failure - byte arrays not same", expected, actualassertFalse
Using AI Code Generation
1assertFalse("message", variable);2assertTrue("message", variable);3assertEquals("message", expectedValue, actualValue);4assertNotEquals("message", expectedValue, actualValue);5assertArrayEquals("message", expectedArray, actualArray);6assertSame("message", expectedObject, actualObject);7assertNotSame("message", expectedObject, actualObject);8assertNull("message", variable);9assertNotNull("message", variable);10assertSame("message", expectedObject, actualObject);11assertNotSame("message", expectedObject, actualObject);12fail("message");13assertThat("message", actualValue, matcher);14assertThrows(expectedException, () -> { code });15assertDoesNotThrow(() -> { code });16assertAll("message", () -> { code }, () -> { code });17assertTimeout(Duration.ofSeconds(1), () -> { code });18assertTimeoutPreemptively(Duration.ofSeconds(1), () -> { code });19assertTimeoutPreemptively(Duration.ofSeconds(1), () -> { code });20assertIterableEquals(expectedIterable, actualIterable);21assertLinesMatch(expectedLines, actualassertFalse
Using AI Code Generation
1import org.junit.Test;2import static org.junit.Assert.*;3public class assertFalseExample {4  public void testAssertFalse() {5    assertFalse("failure - should be false", false);6  }7}8	at org.junit.Assert.assertEquals(Assert.java:115)9	at org.junit.Assert.assertEquals(Assert.java:144)10	at assertFalseExample.testAssertFalse(assertFalseExample.java:10)11assertNotEquals() method of org.junit.Assert class12Syntax of assertNotEquals() method13public static void assertNotEquals(String message, Object expected, Object actual)14Example of assertNotEquals() method15import org.junit.Test;16import static org.junit.Assert.*;17public class assertNotEqualsExample {18  public void testAssertNotEquals() {19    assertNotEquals("failure - should not be equal", new Object(), new Object());20  }21}22	at org.junit.Assert.assertEquals(Assert.java:115)23	at org.junit.Assert.assertEquals(Assert.java:144)24	at assertNotEqualsExample.testAssertNotEquals(assertNotEqualsExample.java:10)25assertNotNull() method of org.junit.Assert class26Syntax of assertNotNull() method27public static void assertNotNull(String message, Object object)28Example of assertNotNull() method29import org.junit.Test;30import static org.junit.Assert.*;31public class assertNotNullExample {32  public void testAssertNotNull()assertFalse
Using AI Code Generation
1import org.junit.Assert;2import org.junit.Test;3public class TestAssertFalse {4	public void testAssertFalse() {5		Assert.assertFalse("failure - should be false", false);6	}7}8import org.junit.Assert;9import org.junit.Test;10public class TestAssertTrue {11	public void testAssertTrue() {12		Assert.assertTrue("failure - should be true", true);13	}14}15import org.junit.Assert;16import org.junit.Test;17public class TestAssertEquals {18	public void testAssertEquals() {19		Assert.assertEquals("failure - strings are not equal", "text", "text");20	}21}22import org.junit.Assert;23import org.junit.Test;24public class TestAssertNotEquals {25	public void testAssertNotEquals() {26		Assert.assertNotEquals("failure - strings are equal", "text", "text1");27	}28}29import org.junit.Assert;30import org.junit.Test;31public class TestAssertArrayEquals {32	public void testAssertArrayEquals() {33		byte[] expected = "trial".getBytes();34		byte[] actual = "trial".getBytes();35		Assert.assertArrayEquals("failure - byte arrays not same", expected, actual);36	}37}38import org.junit.Assert;39import org.junit.Test;40public class TestAssertSame {41	public void testAssertSame() {42		String expected = "text";43		String actual = "text";44		Assert.assertSame("failure - strings are not same", expected, actual);45	}46}47import org.junit.Assert;48import org.junit.Test;49public class TestAssertNotSame {50	public void testAssertNotSame() {51		String expected = "text";52		String actual = "text1";53		Assert.assertNotSame("failureassertFalse
Using AI Code Generation
1    public static void main(String[] args) {2        TestCase tc = new TestCase("test");3        TestSuite ts = new TestSuite();4        ts.addTest(tc);5        TestResult tr = new TestResult();6        ts.run(tr);7        System.out.println("Number of test cases = " + tr.runCount());8    }9    public static class TestCase extends junit.framework.TestCase {10        public TestCase(String name) {11            super(name);12        }13        public void test() {14            assertFalse("Test failed", true);15        }16    }17}18Related posts: JUnit AssertTrue() Method Example JUnit AssertEquals() Method Example JUnit AssertNotNull() Method Example JUnit AssertNull() Method Example JUnit AssertSame() Method Example JUnit AssertNotSame() Method Example JUnit AssertArrayEquals() Method Example JUnit AssertEquals() Method Example JUnit AssertNotEquals() Method Example JUnit AssertFalse() Method Example JUnit AssertTrue() Method Example JUnit AssertEquals() Method Example JUnit AssertNotNull() Method Example JUnit AssertNull() Method Example JUnit AssertSame() Method Example JUnit AssertNotSame() Method Example JUnit AssertArrayEquals() Method Example JUnit AssertEquals() Method Example JUnit AssertNotEquals() Method Example JUnit AssertFalse() Method Example JUnit AssertTrue() Method Example JUnit AssertEquals() Method Example JUnit AssertNotNull() Method Example JUnit AssertNull() Method Example JUnit AssertSame() Method Example JUnit AssertNotSame() Method Example JUnit AssertArrayEquals() Method Example JUnit AssertEquals() Method Example JUnit AssertNotEquals() Method Example JUnit AssertFalse() Method Example JUnit AssertTrue() Method Example JUnit AssertEquals() Method Example JUnit AssertNotNull() Method Example JUnit AssertNull() Method Example JUnit AssertSame() Method Example JUnit AssertNotSame() Method Example JUnit AssertArrayEquals() Method Example JUnit AssertEquals() Method Example JUnit AssertNotEquals() Method Example JUnit AssertFalse() Method Example JUnit AssertTrue() Method Example JUnit AssertEquals() Method Example JUnit AssertNotNull() Method Example JUnit AssertNull() Method Example JUnit AssertSame() Method Example JUnit AssertNotSame() MethodassertFalse
Using AI Code Generation
1import org.junit.Assert;2import org.junit.Test;3public class TestAssertFalse {4public void testAssertFalse() {5boolean booleanVar = true;6Assert.assertFalse(booleanVar);7}8}9at org.junit.Assert.assertEquals(Assert.java:115)10at org.junit.Assert.assertEquals(Assert.java:144)11at org.junit.Assert.assertFalse(Assert.java:65)12at org.junit.Assert.assertFalse(Assert.java:75)13at TestAssertFalse.testAssertFalse(TestAssertFalse.java:20)LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!
