/** descendingkeySet.toArray returns contains all keys */ public void testDescendingDescendingKeySetToArray() { ConcurrentNavigableMap map = dmap5(); Set s = map.descendingKeySet(); Object[] ar = s.toArray(); assertEquals(5, ar.length); assertTrue(s.containsAll(Arrays.asList(ar))); ar[0] = m10; assertFalse(s.containsAll(Arrays.asList(ar))); }
public static String _c1(c1options x) { assertEquals(true, x.flag()); assertEquals(33, x.a()); assertEquals("bb", x.bb(), "bb"); assertEquals(Arrays.asList(new File("f1.txt"), new File("f2.txt")), x.input()); assertEquals(false, x.notset()); assertEquals(Arrays.asList("-a", "--a", "a"), x._arguments()); return "a"; }
/** . */ public void testPathBetween() { List path; Graph<String, DefaultWeightedEdge> g = create(); path = findPathBetween(g, V1, V2); assertEquals(Arrays.asList(new DefaultEdge[] {e12}), path); path = findPathBetween(g, V1, V4); assertEquals(Arrays.asList(new DefaultEdge[] {e12, e24}), path); path = findPathBetween(g, V1, V5); assertEquals(Arrays.asList(new DefaultEdge[] {e12, e24, e45}), path); path = findPathBetween(g, V3, V4); assertEquals(Arrays.asList(new DefaultEdge[] {e13, e12, e24}), path); }
public void testSimple() throws Exception { File tmp = new File("tmp"); PersistentMap<String> pm = new PersistentMap<String>(new File(tmp, "simple"), String.class); try { assertNull(pm.put("abc", "def")); assertEquals("def", pm.get("abc")); pm.close(); PersistentMap<String> pm2 = new PersistentMap<String>(new File(tmp, "simple"), String.class); assertEquals("def", pm2.get("abc")); assertEquals(Arrays.asList("abc"), new ArrayList<String>(pm2.keySet())); for (Map.Entry<String, String> e : pm2.entrySet()) { e.setValue("XXX"); } assertEquals("XXX", pm2.get("abc")); pm2.close(); } finally { pm.close(); IO.delete(tmp); } }
public static void testCollections() throws Exception { CollectionsTest trt = set(CollectionsTest.class, new int[] {1, 2, 3}); List<String> source = Arrays.asList("1", "2", "3"); assertTrue(trt.collection() instanceof Collection); assertEqualList(source, trt.collection()); assertTrue(trt.list() instanceof List); assertEqualList(source, trt.list()); assertTrue(trt.set() instanceof Set); assertEqualList(source, trt.set()); assertTrue(trt.queue() instanceof Queue); assertEqualList(source, trt.queue()); // assertTrue( trt.deque() instanceof Deque); // assertEqualList( source, trt.deque()); assertTrue(trt.stack() instanceof Stack); assertEqualList(source, trt.stack()); assertTrue(trt.arrayList() instanceof ArrayList); assertEqualList(source, trt.arrayList()); assertTrue(trt.linkedList() instanceof LinkedList); assertEqualList(source, trt.linkedList()); assertTrue(trt.linkedHashSet() instanceof LinkedHashSet); assertEqualList(source, trt.linkedHashSet()); assertTrue(trt.myList() instanceof MyList); assertEqualList(source, trt.myList()); }
/** * Encodes a sample string, decodes it and makes sure that the decoded string has the same value * as the original */ public void testEncodeDecode() { String data = "string to encode"; byte[] expectedReturn = data.getBytes(); byte[] encodedData = base64.encode(data.getBytes()); byte[] actualReturn = base64.decode(encodedData); assertTrue("encode decode failed.", Arrays.equals(expectedReturn, actualReturn)); }
/** Checks that sync has exactly the given queued threads. */ void assertHasQueuedThreads(AbstractQueuedLongSynchronizer sync, Thread... expected) { Collection<Thread> actual = sync.getQueuedThreads(); assertEquals(expected.length > 0, sync.hasQueuedThreads()); assertEquals(expected.length, sync.getQueueLength()); assertEquals(expected.length, actual.size()); assertEquals(expected.length == 0, actual.isEmpty()); assertEquals(new HashSet<Thread>(actual), new HashSet<Thread>(Arrays.asList(expected))); }
/** addAll of a collection with null elements throws NPE */ public void testAddAll2() { try { Succeed q = new Succeed(); Integer[] ints = new Integer[SIZE]; q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) { } }
/** Checks that condition c has exactly the given waiter threads. */ void assertHasWaitersLocked(Mutex sync, ConditionObject c, Thread... threads) { assertEquals(threads.length > 0, sync.hasWaiters(c)); assertEquals(threads.length, sync.getWaitQueueLength(c)); assertEquals(threads.length == 0, sync.getWaitingThreads(c).isEmpty()); assertEquals(threads.length, sync.getWaitingThreads(c).size()); assertEquals( new HashSet<Thread>(sync.getWaitingThreads(c)), new HashSet<Thread>(Arrays.asList(threads))); }
public boolean equals(Object other) { Persistent1 otherPersistent1 = (Persistent1) other; if (int1 != otherPersistent1.int1) { System.out.println("int1 failed"); return false; } if (float1 != otherPersistent1.float1) { System.out.println("float1 failed"); return false; } if (long1 != otherPersistent1.long1) { System.out.println("long1 failed"); return false; } if (boolean1 != otherPersistent1.boolean1) { System.out.println("boolean1 failed"); return false; } if (string1 != otherPersistent1.string1 && (string1 != null && !string1.equals(otherPersistent1.string1) && otherPersistent1.string1 != null)) { System.out.println("string1 failed"); return false; } if (date1 != otherPersistent1.date1 && (date1 != null && !date1.equals(otherPersistent1.date1) && otherPersistent1.date1 != null)) { System.out.println("date1 failed"); return false; } if (bytes1 != otherPersistent1.bytes1 && (bytes1 != null && !Arrays.equals(bytes1, otherPersistent1.bytes1) && otherPersistent1.bytes1 != null)) { System.out.println("bytes1 failed"); return false; } if (codable1 != otherPersistent1.codable1 && (codable1 != null && !codable1.equals(otherPersistent1.codable1) && otherPersistent1.codable1 != null)) { System.out.println("codable1 failed"); return false; } return true; }
/** addAll throws ISE if an add fails */ public void testAddAll4() { try { Fail q = new Fail(); Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (IllegalStateException success) { } }
/** * addAll of a collection with any null elements throws NPE after possibly adding some elements */ public void testAddAll3() { try { Succeed q = new Succeed(); Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) { } }
/** Values.toArray contains all values */ public void testDescendingValuesToArray() { ConcurrentNavigableMap map = dmap5(); Collection v = map.values(); Object[] ar = v.toArray(); ArrayList s = new ArrayList(Arrays.asList(ar)); assertEquals(5, ar.length); assertTrue(s.contains("A")); assertTrue(s.contains("B")); assertTrue(s.contains("C")); assertTrue(s.contains("D")); assertTrue(s.contains("E")); }
/** * Encodes a sample string, decodes it and makes sure that the decoded string has the same value * as the original */ public void testEncodeDecode1() { String data = "string to encode"; byte[] expectedReturn = data.getBytes(); byte[] encodedData = base64.encode(data.getBytes()); String encodedString = new String(encodedData); byte[] actualReturn = base64.decode(encodedString); assertTrue("encode decode failed.", Arrays.equals(expectedReturn, actualReturn)); assertEquals("Original and destination string do not match", data, new String(actualReturn)); }
private void checkHashSet( SimulatedArchivalUnit sau, boolean namesOnly, boolean filter, byte[] expected) throws Exception { enableFilter(sau, filter); CachedUrlSet set = sau.getAuCachedUrlSet(); byte[] hash = getHash(set, namesOnly); assertEquals(expected, hash); String parent = sau.getUrlRoot() + "/branch1"; CachedUrlSetSpec spec = new RangeCachedUrlSetSpec(parent); set = sau.makeCachedUrlSet(spec); byte[] hash2 = getHash(set, namesOnly); assertFalse(Arrays.equals(hash, hash2)); }
public void testMBU(Model m) { Statement[] sArray = statements(m, "moon orbits earth; earth orbits sun"); List<Statement> sList = Arrays.asList(statements(m, "I drink tea; you drink coffee")); m.add(sArray); testContains(m, sArray); m.add(sList); testContains(m, sList); testContains(m, sArray); /* */ m.remove(sArray); testOmits(m, sArray); testContains(m, sList); m.remove(sList); testOmits(m, sArray); testOmits(m, sList); }
// // Return the methods of an interface in a deterministic // order. Class.getMethods() does not do us this favor. // private Method[] sortMethods(Class iface) throws Exception { Method[] raw = iface.getMethods(); int count = raw.length; Method[] cooked = new Method[count]; MethodSortable[] sortables = new MethodSortable[count]; for (int i = 0; i < count; i++) { sortables[i] = new MethodSortable(raw[i]); } Arrays.sort(sortables); for (int i = 0; i < count; i++) { cooked[i] = sortables[i].getMethod(); } return cooked; }
// debug print the list of methods which have disappeared from the SQL interface private void printVanishedMethodList(HashSet<String> vanishedMethodList) { int count = vanishedMethodList.size(); if (count == 0) { return; } println("--------------- VANISHED METHODS ------------------"); println("--"); String[] result = new String[count]; vanishedMethodList.toArray(result); Arrays.sort(result); for (int i = 0; i < count; i++) { println(result[i]); } }
// debug print the list of methods which throw SQLFeatureNotSupportedException private void printUnsupportedList(HashSet<String> unsupportedList) { int count = unsupportedList.size(); if (count == 0) { return; } println("--------------- UNSUPPORTED METHODS ------------------"); println("--"); String[] result = new String[count]; unsupportedList.toArray(result); Arrays.sort(result); for (int i = 0; i < count; i++) { println(result[i]); } }
/** Creates an Message through the advance createMessage() method and inspects its parameters. */ public void testCreateMessage2() { String body = "This is an IM coming from the tested implementation" + " on " + new Date().toString(); String contentType = "text/html"; String encoding = "UTF-16"; String subject = "test message"; net.java.sip.communicator.service.protocol.Message msg = opSetBasicIM.createMessage(body.getBytes(), contentType, encoding, subject); assertEquals("message body", body, msg.getContent()); assertTrue("message body bytes", Arrays.equals(body.getBytes(), msg.getRawData())); assertEquals("message length", body.length(), msg.getSize()); assertEquals("message content type", contentType, msg.getContentType()); assertEquals("message encoding", encoding, msg.getEncoding()); assertNotNull("message uid", msg.getMessageUID()); // a further test on message uid. net.java.sip.communicator.service.protocol.Message msg2 = opSetBasicIM.createMessage(body); assertFalse("message uid", msg.getMessageUID().equals(msg2.getMessageUID())); }
// Debug print the list of method failures which we don't understand private void printNotUnderstoodList(HashSet<String> notUnderstoodList) { int count = notUnderstoodList.size(); if (count == 0) { return; } println("\n\n"); println("--------------- NOT UNDERSTOOD METHODS ------------------"); println("--"); String[] result = new String[count]; notUnderstoodList.toArray(result); Arrays.sort(result); for (int i = 0; i < count; i++) { println(result[i]); } }
/** * Tests the handling of the -sub facility * * @throws Exception */ public static void testSub() throws Exception { Workspace ws = Workspace.getWorkspace(new File("test/ws")); Project project = ws.getProject("p4-sub"); File[] files = project.build(); Arrays.sort(files); System.err.println(Processor.join(project.getErrors(), "\n")); System.err.println(Processor.join(project.getWarnings(), "\n")); assertEquals(0, project.getErrors().size()); assertEquals(0, project.getWarnings().size()); assertNotNull(files); assertEquals(3, files.length); Jar a = new Jar(files[0]); Jar b = new Jar(files[1]); Manifest ma = a.getManifest(); Manifest mb = b.getManifest(); assertEquals("base", ma.getMainAttributes().getValue("Base-Header")); assertEquals("base", mb.getMainAttributes().getValue("Base-Header")); assertEquals("a", ma.getMainAttributes().getValue("Sub-Header")); assertEquals("b", mb.getMainAttributes().getValue("Sub-Header")); }
/** Creates an Message through the simple createMessage() method and inspects its parameters. */ public void testCreateMessage1() { String body = "This is an IM coming from the tested implementation" + " on " + new Date().toString(); net.java.sip.communicator.service.protocol.Message msg = opSetBasicIM1.createMessage(body); assertEquals("message body", body, msg.getContent()); assertTrue("message body bytes", Arrays.equals(body.getBytes(), msg.getRawData())); assertEquals("message length", body.length(), msg.getSize()); assertEquals( "message content type", OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE, msg.getContentType()); assertEquals( "message encoding", OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, msg.getEncoding()); assertNotNull("message uid", msg.getMessageUID()); // a further test on message uid. net.java.sip.communicator.service.protocol.Message msg2 = opSetBasicIM1.createMessage(body); assertFalse("message uid", msg.getMessageUID().equals(msg2.getMessageUID())); }
public void testCommand() throws Exception { CommandLine getopt = new CommandLine(rp); assertEquals("[cmda, cmdb]", getopt.getCommands(new X()).keySet().toString()); getopt.execute(new X(), "cmda", Arrays.asList("-e", "help")); }
/** * Test the converter. * * @throws URISyntaxException */ public static void testConverter() throws URISyntaxException { { // Test collections as value TestReturnTypes trt = set(TestReturnTypes.class, Arrays.asList(55)); assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean())); assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte())); assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort())); assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt())); assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong())); assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat())); assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble())); assertEquals(Arrays.asList(true), trt.rBooleans()); assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes()); assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts()); assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts()); assertEquals(Arrays.asList(new Long(55L)), trt.rLongs()); assertEquals(Arrays.asList(new Float(55F)), trt.rFloats()); assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles()); assertEquals(Arrays.asList("55"), trt.rStrings()); assertEquals(Arrays.asList(new URI("55")), trt.rURIs()); assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean())); assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte())); assertTrue(Arrays.equals(new Short[] {55}, trt.raShort())); assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt())); assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong())); assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat())); assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble())); assertTrue(Arrays.equals(new String[] {"55"}, trt.raString())); assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI())); } { // Test primitive arrays as value TestReturnTypes trt = set(TestReturnTypes.class, new int[] {55}); assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean())); assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte())); assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort())); assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt())); assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong())); assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat())); assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble())); assertEquals(Arrays.asList(true), trt.rBooleans()); assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes()); assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts()); assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts()); assertEquals(Arrays.asList(new Long(55L)), trt.rLongs()); assertEquals(Arrays.asList(new Float(55F)), trt.rFloats()); assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles()); assertEquals(Arrays.asList("55"), trt.rStrings()); assertEquals(Arrays.asList(new URI("55")), trt.rURIs()); assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean())); assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte())); assertTrue(Arrays.equals(new Short[] {55}, trt.raShort())); assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt())); assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong())); assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat())); assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble())); assertTrue(Arrays.equals(new String[] {"55"}, trt.raString())); assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI())); } { // Test single value TestReturnTypes trt = set(TestReturnTypes.class, 55); assertEquals(true, trt.rpBoolean()); assertEquals(55, trt.rpByte()); assertEquals(55, trt.rpShort()); assertEquals(55, trt.rpInt()); assertEquals(55L, trt.rpLong()); assertEquals(55.0D, trt.rpDouble()); assertEquals(55.0F, trt.rpFloat()); assertEquals((Boolean) true, trt.rBoolean()); assertEquals(new Byte((byte) 55), trt.rByte()); assertEquals(new Short((short) 55), trt.rShort()); assertEquals(Integer.valueOf(55), trt.rInt()); assertEquals(new Long(55L), trt.rLong()); assertEquals(new Float(55F), trt.rFloat()); assertEquals(new Double(55), trt.rDouble()); assertEquals("55", trt.rString()); assertEquals(new URI("55"), trt.rURI()); assertTrue(Arrays.equals(new boolean[] {true}, trt.rpaBoolean())); assertTrue(Arrays.equals(new byte[] {55}, trt.rpaByte())); assertTrue(Arrays.equals(new short[] {55}, trt.rpaShort())); assertTrue(Arrays.equals(new int[] {55}, trt.rpaInt())); assertTrue(Arrays.equals(new long[] {55}, trt.rpaLong())); assertTrue(Arrays.equals(new float[] {55}, trt.rpaFloat())); assertTrue(Arrays.equals(new double[] {55}, trt.rpaDouble())); assertEquals(Arrays.asList(true), trt.rBooleans()); assertEquals(Arrays.asList(new Byte((byte) 55)), trt.rBytes()); assertEquals(Arrays.asList(new Short((short) 55)), trt.rShorts()); assertEquals(Arrays.asList(Integer.valueOf(55)), trt.rInts()); assertEquals(Arrays.asList(new Long(55L)), trt.rLongs()); assertEquals(Arrays.asList(new Float(55F)), trt.rFloats()); assertEquals(Arrays.asList(new Double(55D)), trt.rDoubles()); assertEquals(Arrays.asList("55"), trt.rStrings()); assertEquals(Arrays.asList(new URI("55")), trt.rURIs()); assertTrue(Arrays.equals(new Boolean[] {true}, trt.raBoolean())); assertTrue(Arrays.equals(new Byte[] {55}, trt.raByte())); assertTrue(Arrays.equals(new Short[] {55}, trt.raShort())); assertTrue(Arrays.equals(new Integer[] {55}, trt.raInt())); assertTrue(Arrays.equals(new Long[] {55L}, trt.raLong())); assertTrue(Arrays.equals(new Float[] {55F}, trt.raFloat())); assertTrue(Arrays.equals(new Double[] {55D}, trt.raDouble())); assertTrue(Arrays.equals(new String[] {"55"}, trt.raString())); assertTrue(Arrays.equals(new URI[] {new URI("55")}, trt.raURI())); } }