1+ /*
2+ * The MIT License (MIT)
3+ *
4+ * Copyright (c) 2015 Daniel Gómez-Sánchez
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in all
14+ * copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+ package htsjdk .samtools .util ;
26+
27+ import org .testng .Assert ;
28+ import org .testng .annotations .Test ;
29+
30+ import java .io .IOException ;
31+ import java .io .OutputStream ;
32+
33+ /**
34+ * @author Daniel Gomez-Sanchez (magicDGS)
35+ */
36+ public class PositionalOutputStreamTest {
37+
38+ @ Test
39+ public void basicPositionTest () throws Exception {
40+ // wrapped null output stream to check
41+ final PositionalOutputStream wrapped = new PositionalOutputStream (new OutputStream () {
42+ @ Override
43+ public void write (int b ) throws IOException {}
44+ });
45+ int position = 0 ;
46+ // check that we start at position 0
47+ Assert .assertEquals (wrapped .getPosition (), position );
48+ // check that write one int just add one
49+ wrapped .write (100 );
50+ Assert .assertEquals (wrapped .getPosition (), ++position );
51+ // check that write a byte array adds its length
52+ final byte [] bytes = new byte []{1 , 3 , 5 , 7 };
53+ wrapped .write (bytes );
54+ position += bytes .length ;
55+ Assert .assertEquals (wrapped .getPosition (), position );
56+ // check that write just some bytes from an array adds its length
57+ wrapped .write (bytes , 2 , 2 );
58+ position += 2 ;
59+ Assert .assertEquals (wrapped .getPosition (), position );
60+ }
61+
62+ }
0 commit comments