Skip to content

Commit adabfcc

Browse files
committed
Fix reflection warnings in tests
1 parent c63e491 commit adabfcc

File tree

15 files changed

+110
-91
lines changed

15 files changed

+110
-91
lines changed

ring-core/test/ring/middleware/multipart_params/test/byte_array.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
:stream (string-input-stream "foo")})]
1212
(is (= (:filename result) "foo.txt"))
1313
(is (= (:content-type result) "text/plain"))
14-
(is (= (String. (:bytes result)) "foo"))))
14+
(is (= (String. ^bytes (:bytes result)) "foo"))))
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns ring.middleware.multipart-params.test.request-context
22
(:require [clojure.test :refer :all]
3-
[ring.middleware.multipart-params :as mp]))
3+
[ring.middleware.multipart-params :as mp])
4+
(:import [org.apache.commons.fileupload2.core RequestContext]))
45

56
(deftest test-default-content-length
67
(is (= -1
7-
(.getContentLength (#'mp/request-context {} nil)))))
8+
(.getContentLength ^RequestContext (#'mp/request-context {} nil)))))

ring-core/test/ring/middleware/multipart_params/test/temp_file.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns ring.middleware.multipart-params.test.temp-file
22
(:require [clojure.test :refer :all]
33
[ring.middleware.multipart-params.temp-file :refer :all]
4-
[ring.util.io :refer [string-input-stream]]))
4+
[ring.util.io :refer [string-input-stream]])
5+
(:import [java.io File]))
56

67
(deftest test-temp-file-store
78
(let [store (temp-file-store)
@@ -12,11 +13,11 @@
1213
(is (= (:filename result) "foo.txt"))
1314
(is (= (:content-type result) "text/plain"))
1415
(is (= (:size result) 3))
15-
(is (instance? java.io.File (:tempfile result)))
16-
(is (.exists (:tempfile result)))
16+
(is (instance? File (:tempfile result)))
17+
(is (.exists ^File (:tempfile result)))
1718
(is (= (slurp (:tempfile result)) "foo"))))
1819

19-
(defn eventually [check n d]
20+
(defn eventually [check n ^long d]
2021
(loop [i n]
2122
(if (check)
2223
true
@@ -30,9 +31,9 @@
3031
{:filename "foo.txt"
3132
:content-type "text/plain"
3233
:stream (string-input-stream "foo")})]
33-
(is (.exists (:tempfile result)))
34+
(is (.exists ^File (:tempfile result)))
3435
(Thread/sleep 2000)
35-
(let [deleted? (eventually #(not (.exists (:tempfile result))) 120 250)]
36+
(let [deleted? (eventually #(not (.exists ^File (:tempfile result))) 120 250)]
3637
(is deleted?))))
3738

3839
(defn all-threads []

ring-core/test/ring/middleware/session/test/cookie.clj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
[ring.middleware.session.store :refer :all]
44
[ring.middleware.session.cookie :as cookie :refer [cookie-store]]
55
[ring.util.codec :as codec]
6-
[crypto.random :as random]))
6+
[crypto.random :as random])
7+
(:import [java.io Writer]
8+
[java.time Instant]))
79

810
(deftest cookie-session-read-not-exist
911
(let [store (cookie-store)]
@@ -58,14 +60,14 @@
5860
(cookie-store {:key (.getBytes "012345678901234567890")}))))
5961

6062
; setup for serializing/deserializing Instant.
61-
(defmethod print-method java.time.Instant [dt out]
63+
(defmethod print-method Instant [^Instant dt ^Writer out]
6264
(.write out (str "#foo/instant \"" (.toString dt) "\"")))
6365

64-
(defn parse-instant [x] (java.time.Instant/parse x))
66+
(defn parse-instant [x] (Instant/parse x))
6567

6668
(deftest cookie-session-custom-type
6769
(let [store (cookie-store {:readers {'foo/instant #'parse-instant}})
68-
now (java.time.Instant/now)
70+
now (Instant/now)
6971
sess-key (write-session store nil {:foo now})]
7072
(is (not (nil? sess-key)))
7173
(is (= (read-session store sess-key)

ring-core/test/ring/middleware/test/file.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
(is (thrown-with-msg? Exception #".*Directory does not exist.*"
1111
(wrap-file (constantly test-response) "not_here"))))
1212

13-
(def public-dir "test/ring/assets")
14-
(def index-html (File. ^String public-dir "index.html"))
15-
(def foo-html (File. ^String public-dir "foo.html"))
13+
(def ^String public-dir "test/ring/assets")
14+
(def index-html (File. public-dir "index.html"))
15+
(def foo-html (File. public-dir "foo.html"))
1616

1717
(def app (wrap-file (constantly test-response) public-dir))
1818

ring-core/test/ring/middleware/test/file_info.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
"Lets us use a known file modification time for tests, without permanently changing
1616
the file's modification time."
1717
[[file new-time] form]
18-
`(let [old-time# (.lastModified ~file)]
19-
(.setLastModified ~file ~(* new-time 1000))
20-
(try ~form
21-
(finally (.setLastModified ~file old-time#)))))
18+
(let [file (vary-meta file assoc :tag `File)]
19+
`(let [old-time# (.lastModified ~file)]
20+
(.setLastModified ~file ~(* new-time 1000))
21+
(try ~form
22+
(finally (.setLastModified ~file old-time#))))))
2223

2324
(def custom-type-app
2425
(wrap-file-info

ring-core/test/ring/middleware/test/multipart_params.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
:body (string-input-stream form-body)}
162162
response (handler request)]
163163
(let [upload (get-in response [:multipart-params "upload"])]
164-
(is (java.util.Arrays/equals (:bytes upload) (.getBytes "foo"))))))
164+
(is (java.util.Arrays/equals ^bytes (:bytes upload) (.getBytes "foo"))))))
165165

166166
(deftest forced-encoding-option-works
167167
(let [form-body (str "--XXXX\r\n"

ring-core/test/ring/middleware/test/resource.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(deftest resource-loader-test
2525
(let [root-loader (->> (Thread/currentThread)
2626
.getContextClassLoader
27-
(iterate (memfn getParent))
27+
(iterate (memfn ^ClassLoader getParent))
2828
(take-while identity)
2929
last)
3030
jarfile (io/file "test/resource.jar")

ring-core/test/ring/middleware/test/session.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
(defn get-cookies [response]
2525
(get-in response [:headers "Set-Cookie"]))
2626

27-
(defn is-session-cookie? [c]
27+
(defn is-session-cookie? [^String c]
2828
(.contains c "ring-session="))
2929

30-
(defn get-session-cookie [response]
30+
(defn get-session-cookie ^String [response]
3131
(first (filter is-session-cookie? (get-cookies response))))
3232

3333
(deftest session-is-read

ring-devel/test/ring/middleware/test/stacktrace.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
(binding [*err* (java.io.StringWriter.)]
1414
(doseq [app [exception-app assert-app]]
1515
(testing "requests with Accept: text/html"
16-
(let [{:keys [status headers body]} (app html-req)]
16+
(let [{:keys [status headers ^String body]} (app html-req)]
1717
(is (= 500 status))
1818
(is (= {"Content-Type" "text/html"} headers))
1919
(is (.startsWith body "<!DOCTYPE html>"))))
2020
(testing "requests with Accept: application/javascript"
21-
(let [{:keys [status headers body]} (app js-req)]
21+
(let [{:keys [status headers ^String body]} (app js-req)]
2222
(is (= 500 status))
2323
(is (= {"Content-Type" "text/plain"} headers))
2424
(is (or (.startsWith body "java.lang.Exception")
2525
(.startsWith body "java.lang.AssertionError")))))
2626
(testing "requests without Accept header"
27-
(let [{:keys [status headers body]} (app plain-req)]
27+
(let [{:keys [status headers ^String body]} (app plain-req)]
2828
(is (= 500 status))
2929
(is (= {"Content-Type" "text/plain"} headers))
3030
(is (or (.startsWith body "java.lang.Exception")

0 commit comments

Comments
 (0)