src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
Voronoi { public static VoronoiResults findAll(PointD[] points) { return findAll(points, RectD.EMPTY); } private Voronoi(PointD[] points, RectD[] clip, boolean findDelaunay); static VoronoiResults findAll(PointD[] points); static VoronoiResults findAll(PointD[] points, RectD clip); static PointI[] findDelaunay(PointD[] points); static Subdivision findDelaunaySubdivision(PointD[] points); }
@Test public void testVoronoiWithEdgesHittingCorners() { final RectD clip = new RectD(-10, -10, 10, 10); final PointD[] points1 = new PointD[]{ new PointD(-5, 0), new PointD(0, 5), new PointD(5, 0) }; testVoronoiResults(Voronoi.findAll(points1, clip)); final PointD[] points2 = new PointD[]{ new PointD(0, 5), new PointD(5, 0), new PointD(0, -5) }; testVoronoiResults(Voronoi.findAll(points2, clip)); final PointD[] points3 = new PointD[]{ new PointD(5, 0), new PointD(0, -5), new PointD(-5, 0), }; testVoronoiResults(Voronoi.findAll(points3, clip)); final PointD[] points4 = new PointD[]{ new PointD(0, -5), new PointD(-5, 0), new PointD(0, 5) }; testVoronoiResults(Voronoi.findAll(points4, clip)); } @Test public void testVoronoiWithRegionTouchingThreeCorners() { final RectD clip = new RectD(-10, -10, 10, 10); final PointD[] points1 = new PointD[]{ new PointD(-1, -1), new PointD(-9, -7), new PointD(-8, -9), }; testVoronoiResults(Voronoi.findAll(points1, clip)); final PointD[] points2 = new PointD[]{ new PointD(1, -1), new PointD(9, -7), new PointD(8, -9), }; testVoronoiResults(Voronoi.findAll(points2, clip)); final PointD[] points3 = new PointD[]{ new PointD(-1, 1), new PointD(-9, 7), new PointD(-8, 9), }; testVoronoiResults(Voronoi.findAll(points3, clip)); final PointD[] points4 = new PointD[]{ new PointD(1, 1), new PointD(9, 7), new PointD(8, 9), }; testVoronoiResults(Voronoi.findAll(points4, clip)); } @Test public void testVoronoiWithRegionTouchingTwoOppositeSides() { final RectD clip = new RectD(-10, -10, 10, 10); final PointD[] points1 = new PointD[]{ new PointD(-5, 0), new PointD(0, 0), new PointD(5, 0), }; testVoronoiResults(Voronoi.findAll(points1, clip)); final PointD[] points2 = new PointD[]{ new PointD(0, -5), new PointD(0, 0), new PointD(0, 5), }; testVoronoiResults(Voronoi.findAll(points2, clip)); final PointD[] points3 = new PointD[]{ new PointD(-5, -5), new PointD(0, 0), new PointD(5, 5), }; testVoronoiResults(Voronoi.findAll(points3, clip)); final PointD[] points4 = new PointD[]{ new PointD(-5, 5), new PointD(0, 0), new PointD(5, -5), }; testVoronoiResults(Voronoi.findAll(points4, clip)); } @Test public void testVoronoiWithTwoSites() { final RectD clip = new RectD(-10, -10, 10, 10); final PointD[] points1 = new PointD[]{ new PointD(-5, 0), new PointD(5, 0) }; testVoronoiResults(Voronoi.findAll(points1, clip)); final PointD[] points2 = new PointD[]{ new PointD(0, 5), new PointD(0, -5) }; testVoronoiResults(Voronoi.findAll(points2, clip)); final PointD[] points3 = new PointD[]{ new PointD(-5, 5), new PointD(5, -5), }; testVoronoiResults(Voronoi.findAll(points3, clip)); final PointD[] points4 = new PointD[]{ new PointD(-5, -5), new PointD(5, 5) }; testVoronoiResults(Voronoi.findAll(points4, clip)); }
PointDComparatorX extends PointDComparator { @Override public int compare(PointD a, PointD b) { return (epsilon == 0 ? compareExact(a, b) : compareEpsilon(a, b, epsilon)); } PointDComparatorX(); PointDComparatorX(double epsilon); @Override int compare(PointD a, PointD b); int compareEpsilon(PointD a, PointD b); static int compareEpsilon(PointD a, PointD b, double epsilon); static int compareExact(PointD a, PointD b); }
@Test public void testCompare() { assertEquals(0, comparer.epsilon, 0); assertEquals(0, comparer.compare(new PointD(1, 2), new PointD(1, 2))); assertEquals(-1, comparer.compare(new PointD(1, 2), new PointD(2, 2))); assertEquals(-1, comparer.compare(new PointD(1, 2), new PointD(1, 3))); assertEquals(+1, comparer.compare(new PointD(1, 2), new PointD(0, 2))); assertEquals(+1, comparer.compare(new PointD(1, 2), new PointD(1, 1))); assertEquals(0, comparer001.epsilon, 0.01); assertEquals(-1, comparer001.compare(new PointD(1, 2), new PointD(1.1, 2))); assertEquals(-1, comparer001.compare(new PointD(1, 2), new PointD(1, 2.1))); assertEquals(+1, comparer001.compare(new PointD(1, 2), new PointD(0.9, 2))); assertEquals(+1, comparer001.compare(new PointD(1, 2), new PointD(1, 1.9))); assertEquals(0, comparer05.epsilon, 0.5); assertEquals(0, comparer05.compare(new PointD(1, 2), new PointD(1.1, 2))); assertEquals(0, comparer05.compare(new PointD(1, 2), new PointD(1, 2.1))); assertEquals(0, comparer05.compare(new PointD(1, 2), new PointD(0.9, 2))); assertEquals(0, comparer05.compare(new PointD(1, 2), new PointD(1, 1.9))); }
PointDComparatorX extends PointDComparator { public int compareEpsilon(PointD a, PointD b) { return compareEpsilon(a, b, epsilon); } PointDComparatorX(); PointDComparatorX(double epsilon); @Override int compare(PointD a, PointD b); int compareEpsilon(PointD a, PointD b); static int compareEpsilon(PointD a, PointD b, double epsilon); static int compareExact(PointD a, PointD b); }
@Test public void testCompareEpsilon() { assertEquals(0, comparer.epsilon, 0); assertEquals(0, comparer.compareEpsilon(new PointD(1, 2), new PointD(1, 2))); assertEquals(-1, comparer.compareEpsilon(new PointD(1, 2), new PointD(2, 2))); assertEquals(-1, comparer.compareEpsilon(new PointD(1, 2), new PointD(1, 3))); assertEquals(+1, comparer.compareEpsilon(new PointD(1, 2), new PointD(0, 2))); assertEquals(+1, comparer.compareEpsilon(new PointD(1, 2), new PointD(1, 1))); assertEquals(0, comparer001.epsilon, 0.01); assertEquals(-1, comparer001.compareEpsilon(new PointD(1, 2), new PointD(1.1, 2))); assertEquals(-1, comparer001.compareEpsilon(new PointD(1, 2), new PointD(1, 2.1))); assertEquals(+1, comparer001.compareEpsilon(new PointD(1, 2), new PointD(0.9, 2))); assertEquals(+1, comparer001.compareEpsilon(new PointD(1, 2), new PointD(1, 1.9))); assertEquals(0, comparer05.epsilon, 0.5); assertEquals(0, comparer05.compareEpsilon(new PointD(1, 2), new PointD(1.1, 2))); assertEquals(0, comparer05.compareEpsilon(new PointD(1, 2), new PointD(1, 2.1))); assertEquals(0, comparer05.compareEpsilon(new PointD(1, 2), new PointD(0.9, 2))); assertEquals(0, comparer05.compareEpsilon(new PointD(1, 2), new PointD(1, 1.9))); } @Test public void testCompareEpsilonStatic() { assertEquals(-1, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(1.1, 2), 0.01)); assertEquals(-1, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(1, 2.1), 0.01)); assertEquals(+1, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(0.9, 2), 0.01)); assertEquals(+1, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(1, 1.9), 0.01)); assertEquals(0, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(1.1, 2), 0.5)); assertEquals(0, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(1, 2.1), 0.5)); assertEquals(0, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(0.9, 2), 0.5)); assertEquals(0, PointDComparatorX.compareEpsilon(new PointD(1, 2), new PointD(1, 1.9), 0.5)); }
PointDComparatorX extends PointDComparator { public static int compareExact(PointD a, PointD b) { if (a == b) return 0; if (a.x < b.x) return -1; if (a.x > b.x) return +1; if (a.y < b.y) return -1; if (a.y > b.y) return +1; return 0; } PointDComparatorX(); PointDComparatorX(double epsilon); @Override int compare(PointD a, PointD b); int compareEpsilon(PointD a, PointD b); static int compareEpsilon(PointD a, PointD b, double epsilon); static int compareExact(PointD a, PointD b); }
@Test public void testCompareExact() { assertEquals(0, PointDComparatorX.compareExact(new PointD(1, 2), new PointD(1, 2))); assertEquals(-1, PointDComparatorX.compareExact(new PointD(1, 2), new PointD(2, 2))); assertEquals(-1, PointDComparatorX.compareExact(new PointD(1, 2), new PointD(1, 3))); assertEquals(+1, PointDComparatorX.compareExact(new PointD(1, 2), new PointD(0, 2))); assertEquals(+1, PointDComparatorX.compareExact(new PointD(1, 2), new PointD(1, 1))); assertEquals(-1, PointDComparatorX.compareExact(new PointD(1, 2), new PointD(2, 1))); assertEquals(+1, PointDComparatorX.compareExact(new PointD(2, 1), new PointD(1, 2))); }
QuadTree extends AbstractMap<PointD, V> { @Override public V put(PointD key, V value) { Node<V> node = findNode(key); if (node == null) throw new IllegalArgumentException("key not in bounds"); if (node._entries != null && node._entries.containsKey(key)) { final V oldValue = node._entries.get(key); node._entries.put(key, value); return oldValue; } while (node.level() < MAX_LEVEL && !node.hasCapacity()) { if (node._entries != null) node.split(); node = node.findOrCreateChild(key); } assert(!node._entries.containsKey(key)); node._entries.put(key, value); _size++; return null; } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testConstructor() { final QuadTree<String> tree = new QuadTree<>(new RectD(0, 0, 100, 100)); tree.put(new PointD(10, 10), "foo value"); tree.put(new PointD(20, 20), "bar value"); assertEquals(2, tree.size()); final QuadTree<String> clone = new QuadTree<>(new RectD(0, 0, 100, 100), tree); assertEquals(2, clone.size()); } @Test public void testEquals() { final QuadTree<String> tree = new QuadTree<>(_tree.bounds); tree.put(firstKey, "first value"); tree.put(secondKey, "second value"); tree.put(thirdKey, "third value"); assertTrue(_tree.equals(tree)); tree.put(secondKey, "foo value"); assertFalse(_tree.equals(tree)); tree.put(secondKey, "second value"); assertTrue(_tree.equals(tree)); tree.put(fourthKey, "second value"); assertFalse(_tree.equals(tree)); }
Fortran { public static double max(double... args) { double max = Double.NEGATIVE_INFINITY; for (double n: args) if (n > max) max = n; return max; } private Fortran(); static double aint(double n); static float aint(float n); static double anint(double n); static float anint(float n); static int ceiling(double n); static int ceiling(float n); static int floor(double n); static int floor(float n); static long knint(double n); static long knint(float n); static double max(double... args); static float max(float... args); static int max(int... args); static long max(long... args); static double min(double... args); static float min(float... args); static int min(int... args); static long min(long... args); static double modulo(double a, double p); static float modulo(float a, float p); static int modulo(int a, int p); static long modulo(long a, long p); static int nint(double n); static int nint(float n); static double sum(double... args); static float sum(float... args); static int sum(int... args); static long sum(long... args); }
@Test public void testMax() { assertEquals(Double.NEGATIVE_INFINITY, Fortran.max(new double[] {}), DELTA); assertEquals(-5d, Fortran.max(new double[] { -5 }), DELTA); assertEquals(5d, Fortran.max(new double[] { -2, 5, 1, 3, 4 }), DELTA); assertEquals(Float.NEGATIVE_INFINITY, Fortran.max(new float[] {}), DELTA); assertEquals(-5f, Fortran.max(new float[] { -5 }), DELTA); assertEquals(5f, Fortran.max(new float[] { -2, 5, 1, 3, 4 }), DELTA); assertEquals(Integer.MIN_VALUE, Fortran.max(new int[] {})); assertEquals(-5, Fortran.max(new int[] { -5 })); assertEquals(5, Fortran.max(new int[] { -2, 5, 1, 3, 4 })); assertEquals(Long.MIN_VALUE, Fortran.max(new long[] {})); assertEquals(-5L, Fortran.max(new long[] { -5 })); assertEquals(5L, Fortran.max(new long[] { -2, 5, 1, 3, 4 })); }
QuadTree extends AbstractMap<PointD, V> { public boolean containsKey(PointD key, Node<V> node) { if (key == null) throw new NullPointerException("key"); if (checkLeaf(node) && node._entries.containsKey(key)) return true; node = findNode(key); return (checkLeaf(node) && node._entries.containsKey(key)); } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testKeys() { assertEquals(_tree.size(), _tree.keySet().size()); for (PointD key: _tree.keySet()) assertTrue(_tree.containsKey(key)); } @Test public void testContainsKey() { assertTrue(_tree.containsKey(firstKey)); assertTrue(_tree.containsKey(secondKey)); assertTrue(_tree.containsKey(thirdKey)); assertFalse(_tree.containsKey(fourthKey)); assertFalse(_tree.containsKey(invalidKey)); }
QuadTree extends AbstractMap<PointD, V> { public boolean containsValue(V value, Node<V> node) { if (checkLeaf(node) && node._entries.containsValue(value)) return true; node = findNodeByValue(value); return (node != null); } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testValues() { assertEquals(_tree.size(), _tree.values().size()); for (String value: _tree.values()) assertTrue(_tree.containsValue(value)); } @Test public void testContainsValue() { assertTrue(_tree.containsValue("first value")); assertTrue(_tree.containsValue("second value")); assertTrue(_tree.containsValue("third value")); assertFalse(_tree.containsValue("fourth value")); assertFalse(_tree.containsValue(null)); }
QuadTree extends AbstractMap<PointD, V> { @Override public Set<Entry<PointD, V>> entrySet() { return _entrySet; } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testContains() { assertTrue(_tree.entrySet().contains(createEntry(firstKey, "first value"))); assertTrue(_tree.entrySet().contains(createEntry(secondKey, "second value"))); assertTrue(_tree.entrySet().contains(createEntry(thirdKey, "third value"))); assertFalse(_tree.entrySet().contains(createEntry(firstKey, "second value"))); assertFalse(_tree.entrySet().contains(createEntry(fourthKey, "fourth value"))); assertFalse(_tree.entrySet().contains(createEntry(invalidKey, null))); } @Test public void testIterator() { final Iterator<Map.Entry<PointD, String>> iter = _tree.entrySet().iterator(); assertTrue(iter.hasNext()); assertEquals(createEntry(firstKey, "first value"), iter.next()); assertTrue(iter.hasNext()); assertEquals(createEntry(thirdKey, "third value"), iter.next()); assertTrue(iter.hasNext()); assertEquals(createEntry(secondKey, "second value"), iter.next()); assertFalse(iter.hasNext()); } @Test public void testToArray() { final Map.Entry<PointD, String>[] array = _tree.entrySet().toArray(new Map.Entry[_tree.size()]); assertEquals(_tree.size(), array.length); for (int i = 0; i < _tree.size(); i++) assertTrue(_tree.entrySet().contains(array[i])); }
QuadTree extends AbstractMap<PointD, V> { public void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex) { for (Map.Entry<PointD, V> entry: entrySet()) array[arrayIndex++] = entry; } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testCopyTo() { final Map.Entry<PointD, String>[] array = new Map.Entry[4]; try { _tree.copyTo(array, 3); fail("expected ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException e) { } _tree.copyTo(array, 0); for (int i = 0; i < _tree.size(); i++) assertTrue(_tree.entrySet().contains(array[i])); _tree.copyTo(array, 1); for (int i = 0; i < _tree.size(); i++) assertTrue(_tree.entrySet().contains(array[i + 1])); } @Test public void testCopyToEmpty() { _tree.clear(); final Map.Entry<PointD, String>[] array = new Map.Entry[0]; _tree.copyTo(array, 0); }
QuadTree extends AbstractMap<PointD, V> { @Override public V get(Object key) { final Node<V> node = findNode((PointD) key); return (checkLeaf(node) ? node._entries.get(key) : null); } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testGet() { assertEquals("first value", _tree.get(firstKey)); assertEquals(null, _tree.get(invalidKey)); }
Fortran { public static double min(double... args) { double min = Double.POSITIVE_INFINITY; for (double n: args) if (n < min) min = n; return min; } private Fortran(); static double aint(double n); static float aint(float n); static double anint(double n); static float anint(float n); static int ceiling(double n); static int ceiling(float n); static int floor(double n); static int floor(float n); static long knint(double n); static long knint(float n); static double max(double... args); static float max(float... args); static int max(int... args); static long max(long... args); static double min(double... args); static float min(float... args); static int min(int... args); static long min(long... args); static double modulo(double a, double p); static float modulo(float a, float p); static int modulo(int a, int p); static long modulo(long a, long p); static int nint(double n); static int nint(float n); static double sum(double... args); static float sum(float... args); static int sum(int... args); static long sum(long... args); }
@Test public void testMin() { assertEquals(Double.POSITIVE_INFINITY, Fortran.min(new double[] {}), DELTA); assertEquals(5d, Fortran.min(new double[] { 5 }), DELTA); assertEquals(-2d, Fortran.min(new double[] { -2, 5, 1, 3, 4 }), DELTA); assertEquals(Float.POSITIVE_INFINITY, Fortran.min(new float[] {}), DELTA); assertEquals(5f, Fortran.min(new float[] { 5 }), DELTA); assertEquals(-2f, Fortran.min(new float[] { -2, 5, 1, 3, 4 }), DELTA); assertEquals(Integer.MAX_VALUE, Fortran.min(new int[] {})); assertEquals(5, Fortran.min(new int[] { 5 })); assertEquals(-2, Fortran.min(new int[] { -2, 5, 1, 3, 4 })); assertEquals(Long.MAX_VALUE, Fortran.min(new long[] {})); assertEquals(5L, Fortran.min(new long[] { 5 })); assertEquals(-2L, Fortran.min(new long[] { -2, 5, 1, 3, 4 })); }
QuadTree extends AbstractMap<PointD, V> { public Node<V> move(PointD oldKey, PointD newKey, Node<V> node) { if (!checkLeaf(node) || !node._entries.containsKey(oldKey)) { node = findNode(oldKey); if (node == null) throw new NoSuchElementException("oldKey"); } final V value = node._entries.get(oldKey); node._entries.remove(oldKey); if (node.bounds.containsOpen(newKey)) node._entries.put(newKey, value); else { --_size; if (node._entries.isEmpty() && node.parent != null) { node.parent.removeChild(node); node = null; } put(newKey, value); } return node; } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testMove() { QuadTree.Node<String> node = _tree.move(firstKey, new PointD(10, 10), null); assertFalse(_tree.containsKey(firstKey)); assertEquals("first value", _tree.get(new PointD(10, 10))); node = _tree.move(secondKey, new PointD(30, 30), node); assertFalse(_tree.containsKey(secondKey)); assertEquals("second value", _tree.get(new PointD(30, 30))); }
QuadTree extends AbstractMap<PointD, V> { @Override public V remove(Object key) { final PointD realKey = (PointD) key; final Node<V> node = findNode(realKey); if (!checkLeaf(node) || !node._entries.containsKey(realKey)) return null; --_size; final V oldValue = node._entries.get(realKey); node._entries.remove(realKey); if (node._entries.isEmpty() && node.parent != null) node.parent.removeChild(node); return oldValue; } QuadTree(RectD bounds); QuadTree(RectD bounds, int capacity); QuadTree(RectD bounds, Map<PointD, V> map); boolean containsKey(PointD key, Node<V> node); boolean containsValue(V value, Node<V> node); void copyTo(Map.Entry<PointD, V>[] array, int arrayIndex); Node<V> findNode(int level, int gridX, int gridY); Node<V> findNode(PointD key); Node<V> findNodeByValue(V value); Map<PointD, V> findRange(PointD center, double radius); Map<PointD, V> findRange(RectD range); Node<V> move(PointD oldKey, PointD newKey, Node<V> node); Map<Integer, Node<V>> nodes(); void setProbeUseBitMask(boolean value); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Entry<PointD, V>> entrySet(); @Override V get(Object key); @Override V put(PointD key, V value); @Override void putAll(Map<? extends PointD, ? extends V> map); @Override V remove(Object key); @Override boolean remove(Object key, Object value); @Override V replace(PointD key, V value); @Override boolean replace(PointD key, V oldValue, V newValue); final static int MAX_LEVEL; final static int PROBE_LEVEL; final RectD bounds; final int capacity; final Node<V> rootNode; }
@Test public void testRemove() { assertEquals("second value", _tree.remove(secondKey)); assertNull(_tree.remove(fourthKey)); assertEquals(2, _tree.size()); assertEquals("first value", _tree.remove(firstKey)); assertEquals("third value", _tree.remove(thirdKey)); assertEquals(0, _tree.size()); }
MathUtils { public static int compare(double a, double b, double epsilon) { if (epsilon < 0) throw new IllegalArgumentException("epsilon < 0"); final double delta = a - b; if (Math.abs(delta) <= epsilon) return 0; return (delta < 0 ? -1 : 1); } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testCompare() { assertEquals( 0, MathUtils.compare(0.0, 0.0, EPSILON)); assertEquals( 0, MathUtils.compare(0f, 0f, EPSILON)); assertEquals(-1, MathUtils.compare(0.0, 1.0, EPSILON)); assertEquals( 0, MathUtils.compare(-Double.MIN_NORMAL, Double.MIN_NORMAL, EPSILON)); assertEquals(+1, MathUtils.compare(0.0, -1.0, EPSILON)); assertEquals( 0, MathUtils.compare(Double.MIN_NORMAL, -Double.MIN_NORMAL, EPSILON)); assertEquals(-1, MathUtils.compare(0f, 1f, EPSILON)); assertEquals( 0, MathUtils.compare(-Float.MIN_NORMAL, Float.MIN_NORMAL, EPSILON)); assertEquals(+1, MathUtils.compare(0f, -1f, EPSILON)); assertEquals( 0, MathUtils.compare(Float.MIN_NORMAL, -Float.MIN_NORMAL, EPSILON)); } @Test public void testCompareMin() { assertEquals( 0, MathUtils.compare(0.0, 0.0, Double.MIN_NORMAL)); assertEquals( 0, MathUtils.compare(0.0, Double.MIN_NORMAL, Double.MIN_NORMAL)); assertEquals( 0, MathUtils.compare(0.0, -Double.MIN_NORMAL, Double.MIN_NORMAL)); assertEquals(-1, MathUtils.compare(0.0, 1.0, Double.MIN_NORMAL)); assertEquals(-1, MathUtils.compare(-Double.MIN_NORMAL, Double.MIN_NORMAL, Double.MIN_NORMAL)); assertEquals(+1, MathUtils.compare(0.0, -1.0, Double.MIN_NORMAL)); assertEquals(+1, MathUtils.compare(Double.MIN_NORMAL, -Double.MIN_NORMAL, Double.MIN_NORMAL)); assertEquals( 0, MathUtils.compare(0f, 0f, Float.MIN_NORMAL)); assertEquals( 0, MathUtils.compare(0f, Float.MIN_NORMAL, Float.MIN_NORMAL)); assertEquals( 0, MathUtils.compare(0f, -Float.MIN_NORMAL, Float.MIN_NORMAL)); assertEquals(-1, MathUtils.compare(0f, 1f, Float.MIN_NORMAL)); assertEquals(-1, MathUtils.compare(-Float.MIN_NORMAL, Float.MIN_NORMAL, Float.MIN_NORMAL)); assertEquals(+1, MathUtils.compare(0f, -1f, Float.MIN_NORMAL)); assertEquals(+1, MathUtils.compare(Float.MIN_NORMAL, -Float.MIN_NORMAL, Float.MIN_NORMAL)); }
MathUtils { public static boolean equals(double a, double b, double epsilon) { if (epsilon < 0) throw new IllegalArgumentException("epsilon < 0"); return (Math.abs(a - b) <= epsilon); } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testEquals() { assertTrue(MathUtils.equals(0.0, 0.0, EPSILON)); assertTrue(MathUtils.equals(0f, 0f, EPSILON)); assertFalse(MathUtils.equals(0.0, 1.0, EPSILON)); assertTrue(MathUtils.equals(-Double.MIN_NORMAL, Double.MIN_NORMAL, EPSILON)); assertFalse(MathUtils.equals(0.0, -1.0, EPSILON)); assertTrue(MathUtils.equals(Double.MIN_NORMAL, -Double.MIN_NORMAL, EPSILON)); assertFalse(MathUtils.equals(0f, 1f, EPSILON)); assertTrue(MathUtils.equals(-Float.MIN_NORMAL, Float.MIN_NORMAL, EPSILON)); assertFalse(MathUtils.equals(0f, -1f, EPSILON)); assertTrue(MathUtils.equals(Float.MIN_NORMAL, -Float.MIN_NORMAL, EPSILON)); } @Test public void testEqualsMin() { assertTrue(MathUtils.equals(0.0, 0.0, Double.MIN_NORMAL)); assertTrue(MathUtils.equals(0.0, Double.MIN_NORMAL, Double.MIN_NORMAL)); assertTrue(MathUtils.equals(0.0, -Double.MIN_NORMAL, Double.MIN_NORMAL)); assertFalse(MathUtils.equals(0.0, 1.0, Double.MIN_NORMAL)); assertFalse(MathUtils.equals(-Double.MIN_NORMAL, Double.MIN_NORMAL, Double.MIN_NORMAL)); assertFalse(MathUtils.equals(0.0, -1.0, Double.MIN_NORMAL)); assertFalse(MathUtils.equals(Double.MIN_NORMAL, -Double.MIN_NORMAL, Double.MIN_NORMAL)); assertTrue(MathUtils.equals(0f, 0f, Float.MIN_NORMAL)); assertTrue(MathUtils.equals(0f, Float.MIN_NORMAL, Float.MIN_NORMAL)); assertTrue(MathUtils.equals(0f, -Float.MIN_NORMAL, Float.MIN_NORMAL)); assertFalse(MathUtils.equals(0f, 1f, Float.MIN_NORMAL)); assertFalse(MathUtils.equals(-Float.MIN_NORMAL, Float.MIN_NORMAL, Float.MIN_NORMAL)); assertFalse(MathUtils.equals(0f, -1f, Float.MIN_NORMAL)); assertFalse(MathUtils.equals(Float.MIN_NORMAL, -Float.MIN_NORMAL, Float.MIN_NORMAL)); }
MathUtils { public static <T> T getAny(T[] array) { try { return array[RANDOM.nextInt(array.length)]; } catch (ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("empty array", e); } } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testGetAny() { final String[] array = new String[] { "a" }; assertEquals("a", MathUtils.<String>getAny(array)); assertEquals("a", MathUtils.<String>getAny(Arrays.asList(array))); assertEquals("a", MathUtils.<String>getAny(new HashSet<>(Arrays.asList(array)))); try { MathUtils.<String>getAny(new String[] {}); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { MathUtils.<String>getAny(new HashSet<>()); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { MathUtils.<String>getAny(new ArrayList<>()); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
MathUtils { public static boolean isPrime(int candidate) { if (candidate <= 0) throw new IllegalArgumentException("candidate <= 0"); if ((candidate & 1) == 0) return (candidate == 2); final int root = (int) Math.sqrt(candidate); for (int i = 3; i <= root; i += 2) if ((candidate % i) == 0) return false; return true; } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testIsPrime() { assertTrue(MathUtils.isPrime(1)); assertTrue(MathUtils.isPrime(2)); assertTrue(MathUtils.isPrime(3)); assertTrue(MathUtils.isPrime(3559)); assertFalse(MathUtils.isPrime(4)); assertFalse(MathUtils.isPrime(3561)); try { MathUtils.isPrime(0); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { MathUtils.isPrime(-1); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
MathUtils { public static double normalize(double[] array) { if (array == null) throw new NullPointerException("array"); double sum = 0; for (double element: array) { if (element < 0) throw new IllegalArgumentException("array element < 0"); sum += element; } if (sum != 0) { for (int i = 0; i < array.length; i++) array[i] /= sum; } else { final double value = 1.0 / array.length; for (int i = 0; i < array.length; i++) array[i] = value; } return sum; } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testNormalize() { final double[] doubles = { 3, 4, 5 }; assertEquals(12.0, MathUtils.normalize(doubles), Double.MIN_NORMAL); assertEquals(3.0/12.0, doubles[0], Double.MIN_NORMAL); assertEquals(4.0/12.0, doubles[1], Double.MIN_NORMAL); assertEquals(5.0/12.0, doubles[2], Double.MIN_NORMAL); final float[] floats = { 3, 4, 5 }; assertEquals(12f, MathUtils.normalize(floats), Float.MIN_NORMAL); assertEquals(3f/12f, floats[0], Float.MIN_NORMAL); assertEquals(4f/12f, floats[1], Float.MIN_NORMAL); assertEquals(5f/12f, floats[2], Float.MIN_NORMAL); final double[] doubleZeroes = { 0, 0, 0 }; assertEquals(0.0, MathUtils.normalize(doubleZeroes), Double.MIN_NORMAL); assertEquals(1.0/3.0, doubleZeroes[0], Double.MIN_NORMAL); assertEquals(1.0/3.0, doubleZeroes[1], Double.MIN_NORMAL); assertEquals(1.0/3.0, doubleZeroes[2], Double.MIN_NORMAL); final float[] floatZeroes = { 0, 0, 0 }; assertEquals(0f, MathUtils.normalize(floatZeroes), Float.MIN_NORMAL); assertEquals(1f/3f, floatZeroes[0], Float.MIN_NORMAL); assertEquals(1f/3f, floatZeroes[1], Float.MIN_NORMAL); assertEquals(1f/3f, floatZeroes[2], Float.MIN_NORMAL); try { MathUtils.normalize(new double[] { 3, -4, 5 }); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { MathUtils.normalize(new float[] { 3, -4, 5 }); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
MathUtils { public static double restrict(double a, double min, double max) { return (a < min ? min : (a > max ? max : a)); } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testRestrict() { assertEquals(0.0, MathUtils.restrict(0.0, -10.0, +10.0), Double.MIN_NORMAL); assertEquals(-10.0, MathUtils.restrict(-20.0, -10.0, +10.0), Double.MIN_NORMAL); assertEquals(+10.0, MathUtils.restrict(+20.0, -10.0, +10.0), Double.MIN_NORMAL); assertEquals(0f, MathUtils.restrict(0f, -10f, +10f), Float.MIN_NORMAL); assertEquals(-10f, MathUtils.restrict(-20f, -10f, +10f), Float.MIN_NORMAL); assertEquals(+10f, MathUtils.restrict(+20f, -10f, +10f), Float.MIN_NORMAL); assertEquals((short) 0, MathUtils.restrict((short) 0, (short) -10, (short) +10)); assertEquals((short) -10, MathUtils.restrict((short) -20, (short) -10, (short) +10)); assertEquals((short) +10, MathUtils.restrict((short) +20, (short) -10, (short) +10)); assertEquals(0, MathUtils.restrict(0, -10, +10)); assertEquals(-10, MathUtils.restrict(-20, -10, +10)); assertEquals(+10, MathUtils.restrict(+20, -10, +10)); assertEquals(0L, MathUtils.restrict(0L, -10L, +10L)); assertEquals(-10L, MathUtils.restrict(-20L, -10L, +10L)); assertEquals(+10L, MathUtils.restrict(+20L, -10L, +10L)); }
MathUtils { public static int toIntExact(double value) { if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) throw new ArithmeticException("value <> Integer: " + value); return (int) value; } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testToIntExact() { try { MathUtils.toIntExact(2.0 * Integer.MAX_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } try { MathUtils.toIntExact(2.0 * Integer.MIN_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } try { MathUtils.toIntExact(2f * Integer.MAX_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } try { MathUtils.toIntExact(2f * Integer.MIN_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } }
MathUtils { public static long toLongExact(double value) { if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) throw new ArithmeticException("value <> Long: " + value); return (long) value; } private MathUtils(); static int compare(double a, double b, double epsilon); static int compare(float a, float b, float epsilon); static boolean equals(double a, double b, double epsilon); static boolean equals(float a, float b, float epsilon); static T getAny(T[] array); static T getAny(Collection<T> collection); static T getAny(List<T> list); static boolean isPrime(int candidate); static double normalize(double[] array); static float normalize(float[] array); static double restrict(double a, double min, double max); static float restrict(float a, float min, float max); static int restrict(int a, int min, int max); static long restrict(long a, long min, long max); static int toIntExact(double value); static int toIntExact(float value); static long toLongExact(double value); static long toLongExact(float value); }
@Test public void testToLongExact() { try { MathUtils.toLongExact(2.0 * Long.MAX_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } try { MathUtils.toLongExact(2.0 * Long.MIN_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } try { MathUtils.toLongExact(2f * Long.MAX_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } try { MathUtils.toLongExact(2f * Long.MIN_VALUE); fail("expected ArithmeticException"); } catch (ArithmeticException e) { } }
IEXTradingException extends RuntimeException { public int getStatus() { return status; } IEXTradingException(final String message); IEXTradingException(final String message, final int status); int getStatus(); static final String DEFAULT_PREFIX; }
@Test public void shouldSuccessfullyCreateExceptionWithStatus() { final String message = "test"; final int statusCode = 500; final IEXTradingException exception = new IEXTradingException(message, statusCode); assertThat(exception.getStatus()).isEqualTo(statusCode); assertThat(exception.getMessage()).containsSequence(DEFAULT_PREFIX, message); }
SectorRequestBuilder extends AbstractRequestFilterBuilder<List<Sector>, SectorRequestBuilder> implements IEXCloudV1RestRequest<List<Sector>> { @Override public RestRequest<List<Sector>> build() { return RestRequestBuilder.<List<Sector>>builder() .withPath("/ref-data/sectors").get() .withResponse(new GenericType<List<Sector>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<Sector>> build(); }
@Test public void shouldSuccessfullyCreateSectorRequest() { final RestRequest<List<Sector>> request = new SectorRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/sectors"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Sector>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
ExchangeRequestBuilder extends AbstractRequestFilterBuilder<List<Exchange>, ExchangeRequestBuilder> implements IEXCloudV1RestRequest<List<Exchange>> { @Override public RestRequest<List<Exchange>> build() { return RestRequestBuilder.<List<Exchange>>builder() .withPath("/ref-data/exchanges").get() .withResponse(new GenericType<List<Exchange>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<Exchange>> build(); }
@Test public void shouldSuccessfullyCreateExchangeRequest() { final RestRequest<List<Exchange>> request = new ExchangeRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/exchanges"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Exchange>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
MutualFundSymbolsRequestBuilder extends AbstractRequestFilterBuilder<List<ExchangeSymbol>, MutualFundSymbolsRequestBuilder> implements IEXCloudV1RestRequest<List<ExchangeSymbol>> { @Override public RestRequest<List<ExchangeSymbol>> build() { return RestRequestBuilder.<List<ExchangeSymbol>>builder() .withPath("/ref-data/mutual-funds/symbols").get() .withResponse(new GenericType<List<ExchangeSymbol>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<ExchangeSymbol>> build(); }
@Test public void shouldSuccessfullyCreateMutualFundsSymbolsRequest() { final RestRequest<List<ExchangeSymbol>> request = new MutualFundSymbolsRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/mutual-funds/symbols"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<ExchangeSymbol>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
UsExchangeRequestBuilder extends AbstractRequestFilterBuilder<List<UsExchange>, UsExchangeRequestBuilder> implements IEXCloudV1RestRequest<List<UsExchange>> { @Override public RestRequest<List<UsExchange>> build() { return RestRequestBuilder.<List<UsExchange>>builder() .withPath("/ref-data/market/us/exchanges").get() .withResponse(new GenericType<List<UsExchange>>() { }) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<UsExchange>> build(); }
@Test public void shouldSuccessfullyCreateUsExchangesRequest() { final RestRequest<List<UsExchange>> request = new UsExchangeRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/market/us/exchanges"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<UsExchange>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
TagRequestBuilder extends AbstractRequestFilterBuilder<List<Tag>, TagRequestBuilder> implements IEXCloudV1RestRequest<List<Tag>> { @Override public RestRequest<List<Tag>> build() { return RestRequestBuilder.<List<Tag>>builder() .withPath("/ref-data/tags").get() .withResponse(new GenericType<List<Tag>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<Tag>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final RestRequest<List<Tag>> request = new TagRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/tags"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Tag>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
FxSymbolRequestBuilder extends AbstractRequestFilterBuilder<FxSymbol, FxSymbolRequestBuilder> implements IEXCloudV1RestRequest<FxSymbol> { @Override public RestRequest<FxSymbol> build() { return RestRequestBuilder.<FxSymbol>builder() .withPath("/ref-data/fx/symbols").get() .withResponse(new GenericType<FxSymbol>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<FxSymbol> build(); }
@Test public void shouldSuccessfullyCreateFxSymbolsRequest() { final RestRequest<FxSymbol> request = new FxSymbolRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/fx/symbols"); assertThat(request.getResponseType()).isEqualTo(new GenericType<FxSymbol>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
SymbolsRequestBuilder extends AbstractRequestFilterBuilder<List<ExchangeSymbol>, SymbolsRequestBuilder> implements IEXCloudV1RestRequest<List<ExchangeSymbol>> { @Override public RestRequest<List<ExchangeSymbol>> build() { return RestRequestBuilder.<List<ExchangeSymbol>>builder() .withPath("/ref-data/symbols").get() .withResponse(new GenericType<List<ExchangeSymbol>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<ExchangeSymbol>> build(); }
@Test public void shouldSuccessfullyCreateSymbolsRequest() { final RestRequest<List<ExchangeSymbol>> request = new SymbolsRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/symbols"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<ExchangeSymbol>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
IEXSymbolsRequestBuilder extends AbstractRequestFilterBuilder<List<Symbol>, SymbolsRequestBuilder> implements IEXCloudV1RestRequest<List<Symbol>> { @Override public RestRequest<List<Symbol>> build() { return RestRequestBuilder.<List<Symbol>>builder() .withPath("/ref-data/iex/symbols").get() .withResponse(new GenericType<List<Symbol>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<Symbol>> build(); }
@Test public void shouldSuccessfullyCreateIEXSymbolsRequest() { final RestRequest<List<Symbol>> request = new IEXSymbolsRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/iex/symbols"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Symbol>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
OtcSymbolsRequestBuilder extends AbstractRequestFilterBuilder<List<ExchangeSymbol>, OtcSymbolsRequestBuilder> implements IEXCloudV1RestRequest<List<ExchangeSymbol>> { @Override public RestRequest<List<ExchangeSymbol>> build() { return RestRequestBuilder.<List<ExchangeSymbol>>builder() .withPath("/ref-data/otc/symbols").get() .withResponse(new GenericType<List<ExchangeSymbol>>() {}) .addQueryParam(getFilterParams()) .build(); } @Override RestRequest<List<ExchangeSymbol>> build(); }
@Test public void shouldSuccessfullyCreateOtcSymbolsRequest() { final RestRequest<List<ExchangeSymbol>> request = new OtcSymbolsRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/ref-data/otc/symbols"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<ExchangeSymbol>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
SocketManager { public <T> void subscribe(final SocketRequest<T> request, final Consumer<T> consumer) { final String url = createURL(request); try { if (socketStore.containsKey(request)) { return; } final Socket socket = socketWrapper.socket(url, true).connect(); socket.emit("subscribe", mapParam(request.getParam())) .on("message", args -> processResponse(args, request, consumer)); socketStore.put(request, socket); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } } SocketManager(final SocketWrapper socketWrapper, final String url); void subscribe(final SocketRequest<T> request, final Consumer<T> consumer); void unsubscribe(final SocketRequest<T> request); }
@Test public void shouldConnectAndSubscribeAndProcessResponse() { final String path = "/test"; final List<String> params = Arrays.asList("Test", "Test2"); final SocketRequest<String> request = new SocketRequest<>(new TypeReference<String>() {}, path, params); final Consumer<String> consumer = spy(Consumer.class); final String response = "response"; final ArgumentCaptor<Emitter.Listener> listenerCaptor = ArgumentCaptor.forClass(Emitter.Listener.class); when(socket.connect()).thenReturn(socket); when(socket.emit(any(), any())).thenReturn(socket); when(socket.on(any(), any())).thenReturn(socket); socketManager.subscribe(request, consumer); verify(socket).connect(); verify(socket).emit("subscribe", "[\"Test\",\"Test2\"]"); verify(socket).on(eq("message"), listenerCaptor.capture()); listenerCaptor.getValue().call("\""+response+"\""); verify(consumer).accept(eq(response)); } @Test public void shouldNotOverwriteSubscription() { final String path = "/test"; final List<String> params = Arrays.asList("Test", "Test2"); final SocketRequest<String> request = new SocketRequest<>(new TypeReference<String>() {}, path, params); final Consumer<String> consumer = spy(Consumer.class); final Consumer<String> anotherConsumer = spy(Consumer.class); final String response = "response"; final ArgumentCaptor<Emitter.Listener> listenerCaptor = ArgumentCaptor.forClass(Emitter.Listener.class); when(socket.connect()).thenReturn(socket); when(socket.emit(any(), any())).thenReturn(socket); when(socket.on(any(), any())).thenReturn(socket); socketManager.subscribe(request, consumer); socketManager.subscribe(request, anotherConsumer); verify(socket).on(eq("message"), listenerCaptor.capture()); listenerCaptor.getValue().call("\""+response+"\""); verify(consumer).accept(eq(response)); } @Test public void verifyCreatedSocketPath() throws URISyntaxException { final SocketRequest<String> request = new SocketRequest<>(new TypeReference<String>() {}, "/test", Arrays.asList("Test", "Test2")); final Consumer<String> consumer = spy(Consumer.class); when(socket.connect()).thenReturn(socket); when(socket.emit(any(), any())).thenReturn(socket); when(socket.on(any(), any())).thenReturn(socket); socketManager.subscribe(request, consumer); verify(socketWrapper).socket(eq("https: } @Test(expected = IllegalStateException.class) public void shouldThrowIllegalStateExceptionIfFailsOnConnection() throws URISyntaxException { final SocketRequest<String> request = new SocketRequest<>(new TypeReference<String>() {}, "/test", Arrays.asList("Test", "Test2")); final Consumer<String> consumer = mock(Consumer.class); when(socketWrapper.socket(any(), eq(true))).thenThrow(URISyntaxException.class); socketManager.subscribe(request, consumer); }
CurrencyConversion extends CurrencyRate { public BigDecimal getAmount() { return amount; } @JsonCreator CurrencyConversion( @JsonProperty("symbol") final String symbol, @JsonProperty("rate") final BigDecimal rate, @JsonProperty("timestamp") final Long timestamp, @JsonProperty("amount") final BigDecimal amount, @JsonProperty("isDerived") final Boolean isDerived); BigDecimal getAmount(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
@Test public void constructor() { final String symbol = fixture.create(String.class); final BigDecimal rate = fixture.create(BigDecimal.class); final Long timestamp = fixture.create(Long.class); final BigDecimal amount = fixture.create(BigDecimal.class); final Boolean isDerived = fixture.create(Boolean.class); final CurrencyConversion currencyConversion = new CurrencyConversion(symbol, rate, timestamp, amount, isDerived); assertThat(currencyConversion.getSymbol()).isEqualTo(symbol); assertThat(currencyConversion.getRate()).isEqualTo(rate); assertThat(currencyConversion.getTimestamp()).isEqualTo(timestamp); assertThat(currencyConversion.getAmount()).isEqualTo(amount); assertThat(currencyConversion.isDerived()).isEqualTo(isDerived); }
SocketManager { public <T> void unsubscribe(final SocketRequest<T> request) { final Socket socket = socketStore.remove(request); if (socket == null) { return; } socket.disconnect(); } SocketManager(final SocketWrapper socketWrapper, final String url); void subscribe(final SocketRequest<T> request, final Consumer<T> consumer); void unsubscribe(final SocketRequest<T> request); }
@Test public void shouldNotThrowExceptionWhenThereIsNoSubscription() { final SocketRequest<String> request = new SocketRequest<>(new TypeReference<String>() {}, "/test", Arrays.asList("Test", "Test2")); socketManager.unsubscribe(request); }
SocketWrapper { public Socket socket(final String uri, final boolean reconnect) throws URISyntaxException { return IO.socket(uri, createOptions(reconnect)); } Socket socket(final String uri, final boolean reconnect); }
@Test public void shouldSuccessfullyCreateSocket() throws URISyntaxException { final String uri = "uri"; when(IO.socket(eq(uri), any(IO.Options.class))).thenReturn(socketMock); final Socket socket = socketWrapper.socket(uri, false); assertThat(socket).isEqualTo(socketMock); }
GenericSocketEndpoint implements ISocketEndpoint { @Override public <R> void subscribe(final SocketRequest<R> socketRequest, final Consumer<R> consumer) { socketManager.subscribe(socketRequest, consumer); } GenericSocketEndpoint(final SocketManager socketManager); @Override void subscribe(final SocketRequest<R> socketRequest, final Consumer<R> consumer); @Override void unsubscribe(final SocketRequest<R> socketRequest); }
@Test public void shouldSuccessfullySubscribe() { final SocketRequest<TOPS> request = new TopsAsyncRequestBuilder().build(); final Consumer<TOPS> topsConsumer = mock(Consumer.class); genericSocketEndpoint.subscribe(request, topsConsumer); verify(socketManagerMock).subscribe(eq(request), eq(topsConsumer)); }
GenericSocketEndpoint implements ISocketEndpoint { @Override public <R> void unsubscribe(final SocketRequest<R> socketRequest) { socketManager.unsubscribe(socketRequest); } GenericSocketEndpoint(final SocketManager socketManager); @Override void subscribe(final SocketRequest<R> socketRequest, final Consumer<R> consumer); @Override void unsubscribe(final SocketRequest<R> socketRequest); }
@Test public void shouldSuccessfullyUnsubscribe() { final SocketRequest<TOPS> request = new TopsAsyncRequestBuilder().build(); genericSocketEndpoint.unsubscribe(request); verify(socketManagerMock).unsubscribe(eq(request)); }
AbstractSymbolAsyncRequestBuilder implements IAsyncRequestBuilder<R> { public B withSymbols(final String... symbols) { this.symbols.addAll(Arrays.asList(symbols)); return (B) this; } B withSymbol(final String symbol); B withSymbols(final String... symbols); }
@Test public void shouldSuccessfullyCreateAsyncRequestWithMultipleSymbols() { final String ibmSymbol = "ibm"; final String aaplSymbol = "aapl"; final SocketRequest<LastTrade> request = new LastAsyncRequestBuilder() .withSymbols(ibmSymbol, aaplSymbol) .build(); final String param = String.valueOf(request.getParam()); assertThat(param).containsSequence(ibmSymbol).containsSequence(aaplSymbol); }
BookAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<Book>, BookAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<Book>> build() { return SocketRequestBuilder.<DeepAsyncResponse<Book>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<Book>>() {}) .withParam(getDeepParam()) .build(); } BookAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<Book>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<Book>> request = new BookAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.BOOK); }
TradingStatusAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<TradingStatus>, TradingStatusAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<TradingStatus>> build() { return SocketRequestBuilder.<DeepAsyncResponse<TradingStatus>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<TradingStatus>>() {}) .withParam(getDeepParam()) .build(); } TradingStatusAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<TradingStatus>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<TradingStatus>> request = new TradingStatusAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.TRADING_STATUS); }
HistoricalCurrencyRate extends CurrencyRate { public LocalDate getDate() { return date; } @JsonCreator HistoricalCurrencyRate( @JsonProperty("symbol") final String symbol, @JsonProperty("rate") final BigDecimal rate, @JsonProperty("timestamp") final Long timestamp, @JsonProperty("date") final LocalDate date, @JsonProperty("isDerived") final Boolean isDerived); LocalDate getDate(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
@Test public void constructor() { final String symbol = fixture.create(String.class); final BigDecimal rate = fixture.create(BigDecimal.class); final Long timestamp = fixture.create(Long.class); final LocalDate date = fixture.create(LocalDate.class); final Boolean isDerived = fixture.create(Boolean.class); final HistoricalCurrencyRate historicalCurrencyRate = new HistoricalCurrencyRate(symbol, rate, timestamp, date, isDerived); assertThat(historicalCurrencyRate.getSymbol()).isEqualTo(symbol); assertThat(historicalCurrencyRate.getRate()).isEqualTo(rate); assertThat(historicalCurrencyRate.getTimestamp()).isEqualTo(timestamp); assertThat(historicalCurrencyRate.getDate()).isEqualTo(date); assertThat(historicalCurrencyRate.isDerived()).isEqualTo(isDerived); }
TopsAsyncRequestBuilder extends AbstractSymbolAsyncRequestBuilder<TOPS, TopsAsyncRequestBuilder> { @Override public SocketRequest<TOPS> build() { return SocketRequestBuilder.<TOPS>builder() .withPath("/tops") .withResponse(new TypeReference<TOPS>() {}) .withParam(getSymbol()) .build(); } @Override SocketRequest<TOPS> build(); }
@Test public void shouldSuccessfullyCreateAsyncRequest() { final String symbol = "IBM"; final SocketRequest<TOPS> request = new TopsAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/tops"); assertThat(String.valueOf(request.getParam())).contains(symbol); }
SsrStatusAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<SsrStatus>, SsrStatusAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<SsrStatus>> build() { return SocketRequestBuilder.<DeepAsyncResponse<SsrStatus>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<SsrStatus>>() {}) .withParam(getDeepParam()) .build(); } SsrStatusAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<SsrStatus>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<SsrStatus>> request = new SsrStatusAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.SSR_STATUS); }
LastAsyncRequestBuilder extends AbstractSymbolAsyncRequestBuilder<LastTrade, LastAsyncRequestBuilder> { @Override public SocketRequest<LastTrade> build() { return SocketRequestBuilder.<LastTrade>builder() .withPath("/last") .withResponse(new TypeReference<LastTrade>() {}) .withParam(getSymbol()) .build(); } @Override SocketRequest<LastTrade> build(); }
@Test public void shouldSuccessfullyCreateAsyncRequest() { final String symbol = "IBM"; final SocketRequest<LastTrade> request = new LastAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/last"); assertThat(String.valueOf(request.getParam())).contains(symbol); }
TradeBreakAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<Trade>, TradeBreakAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<Trade>> build() { return SocketRequestBuilder.<DeepAsyncResponse<Trade>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<Trade>>() {}) .withParam(getDeepParam()) .build(); } TradeBreakAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<Trade>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<Trade>> request = new TradeBreakAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.TRADE_BREAK); }
TradesAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<Trade>, TradesAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<Trade>> build() { return SocketRequestBuilder.<DeepAsyncResponse<Trade>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<Trade>>() {}) .withParam(getDeepParam()) .build(); } TradesAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<Trade>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<Trade>> request = new TradesAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.TRADES); }
DeepConsumerAdapter implements Consumer<DeepAsyncResponse<DeepResult>> { @Override public final void accept(final DeepAsyncResponse deepAsyncResponse) { final DeepMessageType messageType = deepAsyncResponse.getMessageType(); switch (messageType) { case TRADING_STATUS: acceptTradingStatus(deepAsyncResponse); break; case AUCTION: acceptAuction(deepAsyncResponse); break; case OP_HALT_STATUS: acceptOpHaltStatus(deepAsyncResponse); break; case SSR_STATUS: acceptSsrStatus(deepAsyncResponse); break; case SECURITY_EVENT: acceptSecurityEvent(deepAsyncResponse); break; case TRADE_BREAK: acceptTradeBreak(deepAsyncResponse); break; case TRADES: acceptTrades(deepAsyncResponse); break; case BOOK: acceptBook(deepAsyncResponse); break; case SYSTEM_EVENT: acceptSystemEvent(deepAsyncResponse); break; default: throw new IEXTradingException("Message type not supported: " + messageType); } } @Override final void accept(final DeepAsyncResponse deepAsyncResponse); void acceptTradingStatus(final DeepAsyncResponse<TradingStatus> tradingStatusResponse); void acceptAuction(final DeepAsyncResponse<Auction> auctionResponse); void acceptOpHaltStatus(final DeepAsyncResponse<OpHaltStatus> opHaltStatusResponse); void acceptSsrStatus(final DeepAsyncResponse<SsrStatus> ssrStatusResponse); void acceptSecurityEvent(final DeepAsyncResponse<SecurityEvent> securityEventResponse); void acceptTradeBreak(final DeepAsyncResponse<Trade> tradeBreakResponse); void acceptTrades(final DeepAsyncResponse<Trade> tradesResponse); void acceptBook(final DeepAsyncResponse<Book> bookResponse); void acceptSystemEvent(final DeepAsyncResponse<SystemEvent> systemEventResponse); }
@Test(expected = IEXTradingException.class) public void shouldThrowAnExceptionForUnknownMessageType() { final SystemEvent data = fixture.create(SystemEvent.class); final DeepAsyncResponse<SystemEvent> response = new DeepAsyncResponse<>(TEST_SYMBOL, DeepMessageType.UNKNOWN.getName(), data, SEQ); consumerAdapter.accept(response); }
AuctionAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<Auction>, AuctionAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<Auction>> build() { return SocketRequestBuilder.<DeepAsyncResponse<Auction>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<Auction>>() {}) .withParam(getDeepParam()) .build(); } AuctionAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<Auction>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<Auction>> request = new AuctionAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.AUCTION); }
SecurityEventAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<SecurityEvent>, SecurityEventAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<SecurityEvent>> build() { return SocketRequestBuilder.<DeepAsyncResponse<SecurityEvent>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<SecurityEvent>>() {}) .withParam(getDeepParam()) .build(); } SecurityEventAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<SecurityEvent>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<SecurityEvent>> request = new SecurityEventAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.SECURITY_EVENT); }
SystemEventAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<SystemEvent>, SystemEventAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<SystemEvent>> build() { return SocketRequestBuilder.<DeepAsyncResponse<SystemEvent>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<SystemEvent>>() {}) .withParam(getDeepParam()) .build(); } SystemEventAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<SystemEvent>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<SystemEvent>> request = new SystemEventAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.SYSTEM_EVENT); }
OpHaltStatusAsyncRequestBuilder extends AbstractDeepAsyncRequestBuilder<DeepAsyncResponse<OpHaltStatus>, OpHaltStatusAsyncRequestBuilder> { @Override public SocketRequest<DeepAsyncResponse<OpHaltStatus>> build() { return SocketRequestBuilder.<DeepAsyncResponse<OpHaltStatus>>builder() .withPath("/deep") .withResponse(new TypeReference<DeepAsyncResponse<OpHaltStatus>>() {}) .withParam(getDeepParam()) .build(); } OpHaltStatusAsyncRequestBuilder(); @Override SocketRequest<DeepAsyncResponse<OpHaltStatus>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SocketRequest<DeepAsyncResponse<OpHaltStatus>> request = new OpHaltStatusAsyncRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); final DeepAsyncRequest param = (DeepAsyncRequest) request.getParam(); assertThat(param.getSymbols()).containsExactly(symbol); assertThat(param.getChannels()).containsExactly(DeepChannel.OP_HALT_STATUS); }
Sector implements Serializable { public String getName() { return name; } @JsonCreator Sector( @JsonProperty("name") final String name); String getName(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
@Test public void constructor() { final String name = fixture.create(String.class); final Sector sector = new Sector(name); assertThat(sector.getName()).isEqualTo(name); }
MarketAsyncRequestBuilder implements IAsyncRequestBuilder<List<MarketVolume>> { @Override public SocketRequest<List<MarketVolume>> build() { return SocketRequestBuilder.<List<MarketVolume>>builder() .withPath("/market") .withResponse(new TypeReference<List<MarketVolume>>() {}) .build(); } @Override SocketRequest<List<MarketVolume>> build(); }
@Test public void shouldSuccessfullyCreateAsyncRequest() { final SocketRequest<List<MarketVolume>> request = new MarketAsyncRequestBuilder().build(); assertThat(request.getPath()).isEqualTo("/market"); assertThat(request.getParam()).isNull(); }
ChartRangeSerializer extends JsonSerializer<ChartRange> { @Override public void serialize(final ChartRange value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException { if (value == null) { gen.writeNull(); return; } gen.writeString(value.getCode()); } @Override void serialize(final ChartRange value, final JsonGenerator gen, final SerializerProvider serializers); }
@Test public void shouldWriteNullIfValueIsNull() throws IOException { final JsonGenerator jsonGeneratorMock = mock(JsonGenerator.class); final SerializerProvider serializerProviderMock = mock(SerializerProvider.class); final ChartRange input = null; serializer.serialize(input, jsonGeneratorMock, serializerProviderMock); verify(jsonGeneratorMock).writeNull(); } @Test public void shouldWriteStringFromValue() throws IOException { final JsonGenerator jsonGeneratorMock = mock(JsonGenerator.class); final SerializerProvider serializerProviderMock = mock(SerializerProvider.class); final ChartRange input = ChartRange.FIVE_YEARS; serializer.serialize(input, jsonGeneratorMock, serializerProviderMock); verify(jsonGeneratorMock).writeString(eq("5y")); }
HackyLocalDateDeserializer extends LocalDateDeserializer { @Override public LocalDate deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { final String val = parser.getValueAsString(); if (val == null || val.equals("0")) { return null; } return super.deserialize(parser, context); } HackyLocalDateDeserializer(); HackyLocalDateDeserializer(DateTimeFormatter dtf); @Override LocalDate deserialize(final JsonParser parser, final DeserializationContext context); }
@Test public void shouldReturnNullIfValueIsNA() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn("0"); final LocalDate result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldReturnNullIfValueIsNull() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn(null); final LocalDate result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldCreateLocalDateBasedOnValue() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); final String date = "2015-05-05"; when(parserMock.getText()).thenReturn(date); when(parserMock.getValueAsString()).thenReturn(date); when(parserMock.hasToken(JsonToken.VALUE_STRING)).thenReturn(true); final LocalDate result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isEqualTo(LocalDate.of(2015, 5, 5)); }
HackyBigDecimalDeserializer extends StdScalarDeserializer<BigDecimal> { @Override public BigDecimal deserialize(final JsonParser parser, final DeserializationContext ctx) throws IOException { final String val = parser.getValueAsString(); if (val == null || "N/A".equalsIgnoreCase(val) || "NaN".equalsIgnoreCase(val) || val.isEmpty()) { return null; } try { return parser.getDecimalValue(); } catch (IOException e) { return new BigDecimal(val); } } HackyBigDecimalDeserializer(); @Override BigDecimal deserialize(final JsonParser parser, final DeserializationContext ctx); }
@Test public void shouldReturnNullIfValueIsNA() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn("N/A"); final BigDecimal result = hackyBigDecimalDeserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldReturnNullIfValueIsNaN() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn("NaN"); final BigDecimal result = hackyBigDecimalDeserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldReturnNullIfValueIsNull() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn(null); final BigDecimal result = hackyBigDecimalDeserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldReturnNullIfValueIsEmpty() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn(""); final BigDecimal result = hackyBigDecimalDeserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldCreateBigDecimalBasedOnValue() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); final BigDecimal value = BigDecimal.valueOf(3); when(parserMock.getValueAsString()).thenReturn(value.toString()); when(parserMock.getDecimalValue()).thenReturn(value); final BigDecimal result = hackyBigDecimalDeserializer.deserialize(parserMock, contextMock); assertThat(result).isEqualTo(value); }
Tag implements Serializable { public String getName() { return name; } @JsonCreator Tag( @JsonProperty("name") final String name); String getName(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
@Test public void constructor() { final String name = fixture.create(String.class); final Tag tag = new Tag(name); assertThat(tag.getName()).isEqualTo(name); }
HackyLocalDateTimeDeserializer extends LocalDateTimeDeserializer { @Override public LocalDateTime deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { final String val = parser.getValueAsString(); if (val == null || val.equals("0")) { return null; } return super.deserialize(parser, context); } HackyLocalDateTimeDeserializer(); HackyLocalDateTimeDeserializer(DateTimeFormatter dtf); @Override LocalDateTime deserialize(final JsonParser parser, final DeserializationContext context); }
@Test public void shouldReturnNullIfValueIsNA() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn("0"); final LocalDateTime result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldReturnNullIfValueIsNull() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn(null); final LocalDateTime result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldCreateLocalDateTimeBasedOnValue() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); final String dateTime = "2015-05-05T19:19:19"; when(parserMock.getText()).thenReturn(dateTime); when(parserMock.getValueAsString()).thenReturn(dateTime); when(parserMock.hasTokenId(JsonTokenId.ID_STRING)).thenReturn(true); final LocalDateTime result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isEqualTo(LocalDateTime.of(2015, 5, 5, 19, 19, 19)); }
ChartRangeDeserializer extends JsonDeserializer<ChartRange> { @Override public ChartRange deserialize(final JsonParser parser, final DeserializationContext ctxt) throws IOException { final String value = parser.getValueAsString(); if (value == null) { return null; } return ChartRange.getValueFromCode(value); } @Override ChartRange deserialize(final JsonParser parser, final DeserializationContext ctxt); }
@Test public void shouldReturnUnknownTypeIfValueIsNull() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn(null); final ChartRange result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isNull(); } @Test public void shouldCreateEnumBasedOnValue() throws IOException { final JsonParser parserMock = mock(JsonParser.class); final DeserializationContext contextMock = mock(DeserializationContext.class); when(parserMock.getValueAsString()).thenReturn("1d"); final ChartRange result = deserializer.deserialize(parserMock, contextMock); assertThat(result).isEqualTo(ChartRange.ONE_DAY); }
SseClientMetadata { public String getUrl() { return url; } SseClientMetadata(final String url, final IEXCloudToken token); String getUrl(); IEXCloudToken getToken(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
@Test public void testUrl() { final String url = "https: final SseClientMetadata sseClientMetadata = new SseClientMetadata(url, new IEXCloudToken("token", "t")); assertThat(sseClientMetadata.getUrl()).isEqualTo(url); }
GenericSseEndpoint implements ISseEndpoint { @Override public <R> void subscribe(final SseRequest<R> sseRequest, final Consumer<R> consumer) { sseManager.subscribe(sseRequest, consumer); } GenericSseEndpoint(final SseManager sseManager); @Override void subscribe(final SseRequest<R> sseRequest, final Consumer<R> consumer); @Override void unsubscribe(final SseRequest<R> sseRequest); }
@Test public void shouldSuccessfullySubscribe() { final SseRequest<List<TOPS>> request = new TopsSseRequestBuilder().build(); final Consumer<List<TOPS>> topsConsumer = mock(Consumer.class); genericSseEndpoint.subscribe(request, topsConsumer); verify(sseManagerMock).subscribe(eq(request), eq(topsConsumer)); }
GenericSseEndpoint implements ISseEndpoint { @Override public <R> void unsubscribe(final SseRequest<R> sseRequest) { sseManager.unsubscribe(sseRequest); } GenericSseEndpoint(final SseManager sseManager); @Override void subscribe(final SseRequest<R> sseRequest, final Consumer<R> consumer); @Override void unsubscribe(final SseRequest<R> sseRequest); }
@Test public void shouldSuccessfullyUnsubscribe() { final SseRequest<List<TOPS>> request = new TopsSseRequestBuilder().build(); genericSseEndpoint.unsubscribe(request); verify(sseManagerMock).unsubscribe(eq(request)); }
NewsSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<News>, NewsSseRequestBuilder> { @Override public SseRequest<List<News>> build() { return SseRequestBuilder.<List<News>>builder() .withPath("/news-stream") .withResponse(new GenericType<List<News>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<News>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<News>> request = new NewsSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/news-stream"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<News>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
RestClientMetadata { public String getUrl() { return url; } RestClientMetadata(final String url, final IEXCloudToken token); String getUrl(); IEXCloudToken getToken(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
@Test public void testUrl() { final String url = "https: final RestClientMetadata restClientMetadata = new RestClientMetadata(url, new IEXCloudToken("token", "t")); assertThat(restClientMetadata.getUrl()).isEqualTo(url); }
CurrencyRatesSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<CurrencyRate>, CurrencyRatesSseRequestBuilder> { @Override public SseRequest<List<CurrencyRate>> build() { return SseRequestBuilder.<List<CurrencyRate>>builder() .withPath("/forex{interval}") .addPathParam("interval", quoteInterval.getName()) .withResponse(new GenericType<List<CurrencyRate>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } CurrencyRatesSseRequestBuilder withQuoteInterval(final QuoteInterval quoteInterval); @Override SseRequest<List<CurrencyRate>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "USDJPY"; final SseRequest<List<CurrencyRate>> request = new CurrencyRatesSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/forex{interval}"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<CurrencyRate>>() {}); assertThat(request.getPathParams()).contains(entry("interval", "1Minute")); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
SsrStatusSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<SsrStatus>>, SsrStatusSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<SsrStatus>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<SsrStatus>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<SsrStatus>>>() { }) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } SsrStatusSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<SsrStatus>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<SsrStatus>>> request = new SsrStatusSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<SsrStatus>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "ssr-status")); }
AuctionSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<Auction>>, AuctionSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<Auction>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<Auction>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<Auction>>>() {}) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } AuctionSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<Auction>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<Auction>>> request = new AuctionSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<Auction>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "auction")); }
SecurityEventSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<SecurityEvent>>, SecurityEventSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<SecurityEvent>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<SecurityEvent>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<SecurityEvent>>>() { }) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } SecurityEventSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<SecurityEvent>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<SecurityEvent>>> request = new SecurityEventSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<SecurityEvent>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "security-event")); }
OpHaltStatusSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<OpHaltStatus>>, OpHaltStatusSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<OpHaltStatus>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<OpHaltStatus>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<OpHaltStatus>>>() {}) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } OpHaltStatusSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<OpHaltStatus>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<OpHaltStatus>>> request = new OpHaltStatusSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<OpHaltStatus>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "op-halt-status")); }
SystemEventSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<SystemEvent>>, SystemEventSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<SystemEvent>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<SystemEvent>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<SystemEvent>>>() { }) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } SystemEventSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<SystemEvent>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<SystemEvent>>> request = new SystemEventSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<SystemEvent>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "system-event")); }
DeepSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<DeepResult>>, DeepSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<DeepResult>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<DeepResult>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<DeepResult>>>() {}) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } DeepSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<DeepResult>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<DeepResult>>> request = new DeepSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<DeepResult>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "deep")); }
TradingStatusSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<TradingStatus>>, TradingStatusSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<TradingStatus>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<TradingStatus>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<TradingStatus>>>() { }) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } TradingStatusSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<TradingStatus>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<TradingStatus>>> request = new TradingStatusSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<TradingStatus>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "trading-status")); }
TradeBreaksSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<Trade>>, TradeBreaksSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<Trade>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<Trade>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<Trade>>>() {}) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } TradeBreaksSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<Trade>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<Trade>>> request = new TradeBreaksSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<Trade>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "trade-breaks")); }
TopsSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<TOPS>, TopsSseRequestBuilder> { @Override public SseRequest<List<TOPS>> build() { return SseRequestBuilder.<List<TOPS>>builder() .withPath("/tops") .withResponse(new GenericType<List<TOPS>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<TOPS>> build(); }
@Test public void shouldSuccessfullyCreateSseRequest() { final String symbol = "IBM"; final SseRequest<List<TOPS>> request = new TopsSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/tops"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<TOPS>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
RestManager { public <R> RestResponse<R> executeRequest(final RestRequest<R> restRequest) { final String url = createURL(restRequest, restClient.getRestClientMetadata().getToken(), restClient.getRestClientMetadata().getUrl()); final Invocation.Builder target = restClient.getClient().target(url).request(MediaType.APPLICATION_JSON); Response response = null; try { switch (restRequest.getMethodType()) { case GET: response = target.get(); break; case POST: final PostEntity requestEntity = restRequest.getRequestEntity(); requestEntity.setToken(resolveToken(restRequest, restClient.getRestClientMetadata().getToken())); response = target.post(Entity.entity(requestEntity, MediaType.APPLICATION_JSON)); break; default: throw new IllegalStateException("Method Type not supported."); } if (!isSuccessful(response)) { final String errorMessage = response.readEntity(String.class); throw new IEXTradingException(errorMessage, response.getStatus()); } return new RestResponseBuilder<R>() .withMessage(response.getStatusInfo().getReasonPhrase()) .withResponse(response.readEntity(restRequest.getResponseType())) .build(); } finally { if (response != null) { response.close(); } } } RestManager(final RestClient restClient); RestResponse<R> executeRequest(final RestRequest<R> restRequest); }
@Test public void shouldSuccessfullyExecuteGetRequest() { final String reasonPhrase = "reason"; final Response.StatusType statusTypeMock = mock(Response.StatusType.class); when(statusTypeMock.getReasonPhrase()).thenReturn(reasonPhrase); final Response responseMock = mock(Response.class); when(responseMock.getStatusInfo()).thenReturn(statusTypeMock); when(responseMock.getStatus()).thenReturn(200); final Invocation.Builder builderMock = mock(Invocation.Builder.class); when(builderMock.get()).thenReturn(responseMock); final WebTarget webTargetMock = mock(WebTarget.class); when(webTargetMock.request(anyString())).thenReturn(builderMock); final Client clientMock = mock(Client.class); when(clientMock.target(anyString())).thenReturn(webTargetMock); final RestRequest restRequestMock = mock(RestRequest.class); when(restClientMock.getClient()).thenReturn(clientMock); final RestClientMetadata metadataMock = mock(RestClientMetadata.class); when(restClientMock.getRestClientMetadata()).thenReturn(metadataMock); when(restRequestMock.getMethodType()).thenReturn(MethodType.GET); when(restRequestMock.getPath()).thenReturn("/test/{test}"); when(restRequestMock.getPathParams()).thenReturn(ImmutableMap.builder() .put("test", "works") .build()); when(restRequestMock.getQueryParams()).thenReturn(ImmutableMap.builder() .put("query", "test") .build()); when(metadataMock.getUrl()).thenReturn("http: final RestResponse response = restManager.executeRequest(restRequestMock); assertThat(response.getMessage()).isEqualTo(reasonPhrase); verify(responseMock).close(); verify(clientMock).target(eq("http: } @Test(expected = IEXTradingException.class) public void shouldThrowAnExceptionForNotSuccessfulResponse() { final String reasonPhrase = "reason"; final Response.StatusType statusTypeMock = mock(Response.StatusType.class); when(statusTypeMock.getReasonPhrase()).thenReturn(reasonPhrase); final Response responseMock = mock(Response.class); when(responseMock.getStatusInfo()).thenReturn(statusTypeMock); when(responseMock.getStatus()).thenReturn(500); final Invocation.Builder builderMock = mock(Invocation.Builder.class); when(builderMock.get()).thenReturn(responseMock); final WebTarget webTargetMock = mock(WebTarget.class); when(webTargetMock.request(anyString())).thenReturn(builderMock); final Client clientMock = mock(Client.class); when(clientMock.target(anyString())).thenReturn(webTargetMock); final RestRequest restRequestMock = mock(RestRequest.class); when(restClientMock.getClient()).thenReturn(clientMock); final RestClientMetadata metadataMock = mock(RestClientMetadata.class); when(restClientMock.getRestClientMetadata()).thenReturn(metadataMock); when(restRequestMock.getMethodType()).thenReturn(MethodType.GET); when(restRequestMock.getPath()).thenReturn("/test/{test}"); when(restRequestMock.getPathParams()).thenReturn(ImmutableMap.builder() .put("test", "works") .build()); when(restRequestMock.getQueryParams()).thenReturn(ImmutableMap.builder() .put("query", "test") .build()); when(metadataMock.getUrl()).thenReturn("http: restManager.executeRequest(restRequestMock); } @Test(expected = IllegalStateException.class) public void shouldThrowAnExceptionIfMethodTypeIsNotSupported() { final RestClientMetadata metadataMock = mock(RestClientMetadata.class); final RestRequest restRequestMock = mock(RestRequest.class); final Client clientMock = mock(Client.class); final WebTarget webTargetMock = mock(WebTarget.class); final Invocation.Builder builderMock = mock(Invocation.Builder.class); when(webTargetMock.request(anyString())).thenReturn(builderMock); when(clientMock.target(anyString())).thenReturn(webTargetMock); when(restClientMock.getClient()).thenReturn(clientMock); when(restClientMock.getRestClientMetadata()).thenReturn(metadataMock); when(restRequestMock.getMethodType()).thenReturn(MethodType.PUT); when(restRequestMock.getPath()).thenReturn("/test"); when(metadataMock.getUrl()).thenReturn("http: restManager.executeRequest(restRequestMock); }
LastSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<LastTrade>, LastSseRequestBuilder> { @Override public SseRequest<List<LastTrade>> build() { return SseRequestBuilder.<List<LastTrade>>builder() .withPath("/last") .withResponse(new GenericType<List<LastTrade>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<LastTrade>> build(); }
@Test public void shouldSuccessfullyCreateSseRequest() { final String symbol = "IBM"; final SseRequest<List<LastTrade>> request = new LastSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/last"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<LastTrade>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
BookSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<Book>>, BookSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<Book>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<Book>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<Book>>>() { }) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } BookSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<Book>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<Book>>> request = new BookSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<Book>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "book")); }
TradesSseRequestBuilder extends AbstractDeepSseRequestBuilder<List<DeepAsyncResponse<Trade>>, TradesSseRequestBuilder> { @Override public SseRequest<List<DeepAsyncResponse<Trade>>> build() { return SseRequestBuilder.<List<DeepAsyncResponse<Trade>>>builder() .withPath("/deep") .withResponse(new GenericType<List<DeepAsyncResponse<Trade>>>() { }) .addQueryParam(CHANNEL_PARAM, getChannels()) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } TradesSseRequestBuilder(); @Override SseRequest<List<DeepAsyncResponse<Trade>>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<DeepAsyncResponse<Trade>>> request = new TradesSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/deep"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<DeepAsyncResponse<Trade>>>() { }); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol), entry("channels", "trades")); }
SentimentSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<SentimentEvent>, SentimentSseRequestBuilder> { @Override public SseRequest<List<SentimentEvent>> build() { return SseRequestBuilder.<List<SentimentEvent>>builder() .withPath("/sentiment") .withResponse(new GenericType<List<SentimentEvent>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<SentimentEvent>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<SentimentEvent>> request = new SentimentSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/sentiment"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<SentimentEvent>>() {}); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
CryptoBookSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<CryptoBookEvent>, CryptoBookSseRequestBuilder> { @Override public SseRequest<List<CryptoBookEvent>> build() { return SseRequestBuilder.<List<CryptoBookEvent>>builder() .withPath("/cryptoBook") .withResponse(new GenericType<List<CryptoBookEvent>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<CryptoBookEvent>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<CryptoBookEvent>> request = new CryptoBookSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/cryptoBook"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<CryptoBookEvent>>() {}); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
CryptoQuoteSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<Quote>, CryptoQuoteSseRequestBuilder> { @Override public SseRequest<List<Quote>> build() { return SseRequestBuilder.<List<Quote>>builder() .withPath("/cryptoQuotes") .withResponse(new GenericType<List<Quote>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<Quote>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<Quote>> request = new CryptoQuoteSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/cryptoQuotes"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Quote>>() {}); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
CryptoEventSseRequestBuilder extends AbstractSymbolSseRequestBuilder<List<CryptoEvent>, CryptoEventSseRequestBuilder> { @Override public SseRequest<List<CryptoEvent>> build() { return SseRequestBuilder.<List<CryptoEvent>>builder() .withPath("/cryptoEvents") .withResponse(new GenericType<List<CryptoEvent>>() {}) .addQueryParam(SYMBOL_PARAM, getSymbol()) .addQueryParam(NO_SNAPSHOT_PARAM, isNoSnapshot()) .build(); } @Override SseRequest<List<CryptoEvent>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final SseRequest<List<CryptoEvent>> request = new CryptoEventSseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getPath()).isEqualTo("/cryptoEvents"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<CryptoEvent>>() {}); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).contains(entry("nosnapshot", "false"), entry("symbols", symbol)); }
GenericRestEndpoint extends AbstractRestEndpoint { public <R> R executeRequest(final RestRequest<R> restRequest) { return execute(restRequest); } GenericRestEndpoint(final RestManager restManager); R executeRequest(final RestRequest<R> restRequest); }
@Test public void shouldSuccessfullyExecuteRequest() { final Object testObject = new Object(); final RestResponse<Object> response = mock(RestResponse.class); when(response.getResponse()).thenReturn(testObject); final RestRequest<Object> restRequest = mock(RestRequest.class); when(restManagerMock.executeRequest(eq(restRequest))).thenReturn(response); final Object result = genericRestEndpoint.executeRequest(restRequest); assertThat(result).isEqualTo(testObject); }
UsageRequestBuilder extends AbstractRequestFilterBuilder<Map<String, List<Usage>>, UsageRequestBuilder> implements IEXCloudV1RestRequest<Map<String, List<Usage>>> { @Override public RestRequest<Map<String, List<Usage>>> build() { return RestRequestBuilder.<Map<String, List<Usage>>>builder() .withPath("/account/usage").get() .withResponse(new GenericType<Map<String, List<Usage>>>() {}) .addQueryParam(getFilterParams()) .withSecretToken() .build(); } SingleUsageRequestBuilder withUsageType(final UsageType usageType); @Override RestRequest<Map<String, List<Usage>>> build(); }
@Test public void shouldSuccessfullyCreateUsageRequest() { final RestRequest<Map<String, List<Usage>>> request = new UsageRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/account/usage"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Map<String, List<Usage>>>() {}); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
MapUtil { public static <K, V> Map<K, V> immutableMap(final Map<K, V> map) { return map == null ? ImmutableMap.of() : ImmutableMap.copyOf(map); } private MapUtil(); static Map<K, V> immutableMap(final Map<K, V> map); }
@Test public void shouldCreateEmptyMapForNullInput() { final Map<String, String> result = MapUtil.immutableMap(null); assertThat(result).isEmpty(); } @Test public void shouldCreateImmutableMapFromMap() { final Map<String, String> mutableMap = new HashMap<>(); final Map<String, String> immutableMap = MapUtil.immutableMap(mutableMap); assertThat(immutableMap).isInstanceOf(ImmutableMap.class); }
MetadataRequestBuilder extends AbstractRequestFilterBuilder<Metadata, MetadataRequestBuilder> implements IEXCloudV1RestRequest<Metadata> { @Override public RestRequest<Metadata> build() { return RestRequestBuilder.<Metadata>builder() .withPath("/account/metadata").get() .withResponse(new GenericType<Metadata>() {}) .addQueryParam(getFilterParams()) .withSecretToken() .build(); } @Override RestRequest<Metadata> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final RestRequest<Metadata> request = new MetadataRequestBuilder().build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/account/metadata"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Metadata>() {}); assertThat(request.getPathParams()).isEmpty(); assertThat(request.getQueryParams()).isEmpty(); }
RequestFilter { public String getColumnList() { return columnList; } RequestFilter(final String columnList); String getColumnList(); static RequestFilterBuilder builder(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
@Test public void constructor() { final String columnList = fixture.create(String.class); final RequestFilter requestFilter = new RequestFilter(columnList); assertThat(requestFilter.getColumnList()).isEqualTo(columnList); }
RequestFilter { public static RequestFilterBuilder builder() { return new RequestFilterBuilder(); } RequestFilter(final String columnList); String getColumnList(); static RequestFilterBuilder builder(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
@Test public void builder() { final String columnList = fixture.create(String.class); final RequestFilter requestFilter = RequestFilter.builder() .withColumn(columnList) .build(); assertThat(requestFilter.getColumnList()).isEqualTo(columnList); }
OptionsRequestBuilder extends AbstractStocksRequestBuilder<List<String>, OptionsRequestBuilder> implements IEXCloudV1RestRequest<List<String>> { @Override public RestRequest<List<String>> build() { return RestRequestBuilder.<List<String>>builder() .withPath("/stock/{symbol}/options") .addPathParam("symbol", getSymbol()).get() .withResponse(new GenericType<List<String>>() { }) .build(); } SpecificOptionRequestBuilder withExpirationDate(final String expirationDate); @Override RestRequest<List<String>> build(); }
@Test public void shouldSuccessfullyCreateOptionsRequest() { final String symbol = "AAPL"; final RestRequest<List<String>> request = new OptionsRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/options"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<String>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
EffectiveSpreadRequestBuilder extends AbstractStocksRequestBuilder<List<EffectiveSpread>, EffectiveSpreadRequestBuilder> implements IEXApiRestRequest<List<EffectiveSpread>> { @Override public RestRequest<List<EffectiveSpread>> build() { return RestRequestBuilder.<List<EffectiveSpread>>builder() .withPath("/stock/{symbol}/effective-spread") .addPathParam("symbol", getSymbol()).get() .withResponse(new GenericType<List<EffectiveSpread>>() {}) .build(); } @Override RestRequest<List<EffectiveSpread>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<List<EffectiveSpread>> request = new EffectiveSpreadRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/effective-spread"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<EffectiveSpread>>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
UpcomingIposRequestBuilder implements IEXCloudV1RestRequest<Ipos> { @Override public RestRequest<Ipos> build() { return RestRequestBuilder.<Ipos>builder() .withPath("/stock/market/upcoming-ipos").get() .withResponse(Ipos.class) .build(); } @Override RestRequest<Ipos> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final RestRequest<Ipos> request = new UpcomingIposRequestBuilder() .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/market/upcoming-ipos"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Ipos>() {}); assertThat(request.getQueryParams()).isEmpty(); }
TimeSeriesRequestBuilder extends AbstractStocksRequestBuilder<List<TimeSeries>, TimeSeriesRequestBuilder> { @Override public RestRequest<List<TimeSeries>> build() { return RestRequestBuilder.<List<TimeSeries>>builder() .withPath("/stock/{symbol}/time-series") .addPathParam("symbol", getSymbol()).get() .withResponse(new GenericType<List<TimeSeries>>() {}) .build(); } @Override RestRequest<List<TimeSeries>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final RestRequest<List<TimeSeries>> request = new TimeSeriesRequestBuilder() .withSymbol("aapl") .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/time-series"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<TimeSeries>>() {}); assertThat(request.getPathParams()).contains(entry("symbol", "aapl")); assertThat(request.getQueryParams()).isEmpty(); }
ChartRequestBuilder extends AbstractChartRequestBuilder<List<Chart>, ChartRequestBuilder> implements IEXCloudV1RestRequest<List<Chart>> { @Override public RestRequest<List<Chart>> build() { if (chartRange != null) { return requestWithRange(); } else if (date != null) { return requestWithDate(); } else { return request(); } } LocalDate getDate(); ChartRequestBuilder withDate(final LocalDate date); ChartRange getChartRange(); ChartRequestBuilder withChartRange(final ChartRange chartRange); @Override RestRequest<List<Chart>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<List<Chart>> request = new ChartRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/chart"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Chart>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); } @Test public void shouldSuccessfullyCreateRequestWithChartReset() { final String symbol = "IBM"; final RestRequest<List<Chart>> request = new ChartRequestBuilder() .withSymbol(symbol) .withChartReset() .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/chart"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Chart>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).containsExactly(entry("chartReset", "true")); } @Test public void shouldSuccessfullyCreateRequestWithChartSimplify() { final String symbol = "IBM"; final RestRequest<List<Chart>> request = new ChartRequestBuilder() .withSymbol(symbol) .withChartSimplify() .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/chart"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Chart>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).containsExactly(entry("chartSimplify", "true")); } @Test public void shouldSuccessfullyCreateRequestWithChartInterval() { final String symbol = "IBM"; final Integer chartInterval = 5; final RestRequest<List<Chart>> request = new ChartRequestBuilder() .withSymbol(symbol) .withChartInterval(chartInterval) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/chart"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Chart>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).containsExactly(entry("chartInterval", String.valueOf(chartInterval))); } @Test public void shouldSuccessfullyCreateRequestWithChangeFromClose() { final String symbol = "IBM"; final RestRequest<List<Chart>> request = new ChartRequestBuilder() .withSymbol(symbol) .withChangeFromClose() .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/chart"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Chart>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).containsExactly(entry("changeFromClose", "true")); } @Test public void shouldSuccessfullyCreateRequestWithChartLast() { final String symbol = "IBM"; final Integer chartLast = 5; final RestRequest<List<Chart>> request = new ChartRequestBuilder() .withSymbol(symbol) .withChartLast(chartLast) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/chart"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<Chart>>() { }); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).containsExactly(entry("chartLast", String.valueOf(chartLast))); }
OpenCloseRequestBuilder extends AbstractStocksRequestBuilder<Ohlc, OpenCloseRequestBuilder> implements IEXCloudV1RestRequest<Ohlc> { @Override public RestRequest<Ohlc> build() { return RestRequestBuilder.<Ohlc>builder() .withPath("/stock/{symbol}/open-close") .addPathParam("symbol", getSymbol()).get() .withResponse(Ohlc.class) .build(); } @Override RestRequest<Ohlc> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<Ohlc> request = new OpenCloseRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/open-close"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Ohlc>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
LogoRequestBuilder extends AbstractStocksRequestBuilder<Logo, LogoRequestBuilder> implements IEXCloudV1RestRequest<Logo> { @Override public RestRequest<Logo> build() { return RestRequestBuilder.<Logo>builder() .withPath("/stock/{symbol}/logo") .addPathParam("symbol", getSymbol()).get() .withResponse(Logo.class) .build(); } @Override RestRequest<Logo> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<Logo> request = new LogoRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/logo"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Logo>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
DelayedQuoteRequestBuilder extends AbstractStocksRequestBuilder<DelayedQuote, DelayedQuoteRequestBuilder> implements IEXCloudV1RestRequest<DelayedQuote> { @Override public RestRequest<DelayedQuote> build() { return RestRequestBuilder.<DelayedQuote>builder() .withPath("/stock/{symbol}/delayed-quote") .addPathParam("symbol", getSymbol()).get() .withResponse(DelayedQuote.class) .build(); } @Override RestRequest<DelayedQuote> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<DelayedQuote> request = new DelayedQuoteRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/delayed-quote"); assertThat(request.getResponseType()).isEqualTo(new GenericType<DelayedQuote>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
VenueVolumeRequestBuilder extends AbstractStocksRequestBuilder<List<VenueVolume>, VenueVolumeRequestBuilder> implements IEXApiRestRequest<List<VenueVolume>>, IEXCloudV1RestRequest<List<VenueVolume>> { @Override public RestRequest<List<VenueVolume>> build() { return RestRequestBuilder.<List<VenueVolume>>builder() .withPath("/stock/{symbol}/volume-by-venue") .addPathParam("symbol", getSymbol()).get() .withResponse(new GenericType<List<VenueVolume>>() {}) .build(); } @Override RestRequest<List<VenueVolume>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<List<VenueVolume>> request = new VenueVolumeRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/volume-by-venue"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<VenueVolume>>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
LargestTradeRequestBuilder extends AbstractStocksRequestBuilder<List<LargestTrade>, LargestTradeRequestBuilder> implements IEXCloudV1RestRequest<List<LargestTrade>> { @Override public RestRequest<List<LargestTrade>> build() { return RestRequestBuilder.<List<LargestTrade>>builder() .withPath("/stock/{symbol}/largest-trades") .addPathParam("symbol", getSymbol()).get() .withResponse(new GenericType<List<LargestTrade>>() {}) .build(); } @Override RestRequest<List<LargestTrade>> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<List<LargestTrade>> request = new LargestTradeRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/largest-trades"); assertThat(request.getResponseType()).isEqualTo(new GenericType<List<LargestTrade>>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }
CompanyRequestBuilder extends AbstractStocksRequestBuilder<Company, CompanyRequestBuilder> implements IEXCloudV1RestRequest<Company> { @Override public RestRequest<Company> build() { return RestRequestBuilder.<Company>builder() .withPath("/stock/{symbol}/company") .addPathParam("symbol", getSymbol()).get() .withResponse(Company.class) .build(); } @Override RestRequest<Company> build(); }
@Test public void shouldSuccessfullyCreateRequest() { final String symbol = "IBM"; final RestRequest<Company> request = new CompanyRequestBuilder() .withSymbol(symbol) .build(); assertThat(request.getMethodType()).isEqualTo(MethodType.GET); assertThat(request.getPath()).isEqualTo("/stock/{symbol}/company"); assertThat(request.getResponseType()).isEqualTo(new GenericType<Company>() {}); assertThat(request.getPathParams()).containsExactly(entry("symbol", symbol)); assertThat(request.getQueryParams()).isEmpty(); }