1+ /*
2+ * Copyright 2017 Patrick Favre-Bulle
3+ *
4+ * Licensed to the Apache Software Foundation (ASF) under one
5+ * or more contributor license agreements. See the NOTICE file
6+ * distributed with this work for additional information
7+ * regarding copyright ownership. The ASF licenses this file
8+ * to you under the Apache License, Version 2.0 (the
9+ * "License"); you may not use this file except in compliance
10+ * with the License. You may obtain a copy of the License at
11+ *
12+ * http://www.apache.org/licenses/LICENSE-2.0
13+ *
14+ * Unless required by applicable law or agreed to in writing,
15+ * software distributed under the License is distributed on an
16+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+ * KIND, either express or implied. See the License for the
18+ * specific language governing permissions and limitations
19+ * under the License.
20+ */
21+
22+ package at .favre .lib .bytes ;
23+
24+ import org .junit .Test ;
25+
26+ import java .nio .ByteBuffer ;
27+
28+ import static org .junit .Assert .*;
29+
30+ public class BytesSharedDataConverterTest extends ABytesTest {
31+
32+ @ Test
33+ public void array () throws Exception {
34+ assertArrayEquals (new byte [0 ], Bytes .from (new byte [0 ]).array ());
35+ assertArrayEquals (example_bytes_one , Bytes .from (example_bytes_one ).array ());
36+ assertArrayEquals (example_bytes_two , Bytes .from (example_bytes_two ).array ());
37+ assertArrayEquals (example_bytes_four , Bytes .from (example_bytes_four ).array ());
38+ assertArrayEquals (example_bytes_seven , Bytes .from (example_bytes_seven ).array ());
39+ assertArrayEquals (example_bytes_eight , Bytes .from (example_bytes_eight ).array ());
40+ assertArrayEquals (example_bytes_sixteen , Bytes .from (example_bytes_sixteen ).array ());
41+ }
42+
43+ @ Test
44+ public void bigInteger () throws Exception {
45+ assertArrayEquals (example_bytes_one , Bytes .from (example_bytes_one ).bigInteger ().toByteArray ());
46+ assertArrayEquals (example_bytes_two , Bytes .from (example_bytes_two ).bigInteger ().toByteArray ());
47+ assertArrayEquals (example_bytes_four , Bytes .from (example_bytes_four ).bigInteger ().toByteArray ());
48+ assertArrayEquals (example_bytes_seven , Bytes .from (example_bytes_seven ).bigInteger ().toByteArray ());
49+ assertArrayEquals (example_bytes_eight , Bytes .from (example_bytes_eight ).bigInteger ().toByteArray ());
50+ assertArrayEquals (example_bytes_sixteen , Bytes .from (example_bytes_sixteen ).bigInteger ().toByteArray ());
51+ }
52+
53+ @ Test
54+ public void buffer () throws Exception {
55+ assertEquals (ByteBuffer .wrap (new byte [0 ]), Bytes .from (new byte [0 ]).buffer ());
56+ assertEquals (ByteBuffer .wrap (example_bytes_one ), Bytes .from (example_bytes_one ).buffer ());
57+ assertEquals (ByteBuffer .wrap (example_bytes_two ), Bytes .from (example_bytes_two ).buffer ());
58+ assertEquals (ByteBuffer .wrap (example_bytes_four ), Bytes .from (example_bytes_four ).buffer ());
59+ assertEquals (ByteBuffer .wrap (example_bytes_seven ), Bytes .from (example_bytes_seven ).buffer ());
60+ assertEquals (ByteBuffer .wrap (example_bytes_eight ), Bytes .from (example_bytes_eight ).buffer ());
61+ assertEquals (ByteBuffer .wrap (example_bytes_sixteen ), Bytes .from (example_bytes_sixteen ).buffer ());
62+ }
63+
64+ @ Test
65+ public void duplicate () throws Exception {
66+ Bytes b = Bytes .from (example_bytes_sixteen );
67+ Bytes b2 = b .duplicate ();
68+ assertNotSame (b , b2 );
69+ assertSame (b .array (), b2 .array ());
70+ }
71+
72+ @ Test
73+ public void inputStream () throws Exception {
74+ assertArrayEquals (example_bytes_one , Util .readFromStream (Bytes .from (example_bytes_one ).inputStream ()));
75+ assertArrayEquals (example_bytes_two , Util .readFromStream (Bytes .from (example_bytes_two ).inputStream ()));
76+ assertArrayEquals (example_bytes_four , Util .readFromStream (Bytes .from (example_bytes_four ).inputStream ()));
77+ assertArrayEquals (example_bytes_sixteen , Util .readFromStream (Bytes .from (example_bytes_sixteen ).inputStream ()));
78+ }
79+ }
0 commit comments