/** 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()); }
/** 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))); }
/** 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")); }
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); }
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())); } }