|
| 1 | +(ns backtype.storm.fields-test |
| 2 | + (:use [clojure test]) |
| 3 | + (:import [backtype.storm.tuple Fields]) |
| 4 | + (:import [java.util List]) |
| 5 | + (:import [java.util Iterator])) |
| 6 | + |
| 7 | +(deftest test-fields-constructor |
| 8 | + (testing "constructor" |
| 9 | + (testing "with (String... fields)" |
| 10 | + (is (instance? Fields (Fields. (into-array String '("foo" "bar"))))) |
| 11 | + (is (thrown? IllegalArgumentException (Fields. (into-array String '("foo" "bar" "foo")))))) |
| 12 | + (testing "with (List<String> fields)" |
| 13 | + (is (instance? Fields (Fields. '("foo" "bar")))) |
| 14 | + (is (thrown? IllegalArgumentException (Fields. '("foo" "bar" "foo"))))))) |
| 15 | + |
| 16 | +(deftest test-fields-methods |
| 17 | + (let [fields (Fields. '("foo" "bar"))] |
| 18 | + (testing "method" |
| 19 | + (testing ".size" |
| 20 | + (is (= (.size fields) 2))) |
| 21 | + (testing ".get" |
| 22 | + (is (= (.get fields 0) "foo")) |
| 23 | + (is (= (.get fields 1) "bar")) |
| 24 | + (is (thrown? IndexOutOfBoundsException (.get fields 2)))) |
| 25 | + (testing ".fieldIndex" |
| 26 | + (is (= (.fieldIndex fields "foo") 0)) |
| 27 | + (is (= (.fieldIndex fields "bar") 1)) |
| 28 | + (is (thrown? IllegalArgumentException (.fieldIndex fields "baz")))) |
| 29 | + (testing ".toList" |
| 30 | + (is (instance? List (.toList fields))) |
| 31 | + (is (= (count (.toList fields)) 2)) |
| 32 | + (is (not-any? false? (map = (.toList fields) '("foo" "bar"))))) |
| 33 | + (testing ".iterator" |
| 34 | + (is (instance? Iterator (.iterator fields))) |
| 35 | + (is (= (count (iterator-seq (.iterator fields))) 2)) |
| 36 | + (is (not-any? false? (map = (iterator-seq (.iterator fields)) '("foo" "bar"))))) |
| 37 | + (testing ".select" |
| 38 | + (is (instance? List (.select fields (Fields. '("bar")) '("a" "b" "c")))) |
| 39 | + (is (= (.select fields (Fields. '("bar")) '("a" "b" "c")) '("b"))))))) |
| 40 | + |
0 commit comments