1 package nom.tam.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import java.io.EOFException;
35 import java.io.IOException;
36
37 import org.junit.jupiter.api.Assertions;
38 import org.junit.jupiter.api.Test;
39
40 @SuppressWarnings("javadoc")
41 public class DefaultMethodsTest {
42
43 @Test
44 public void testMarkSupported() throws Exception {
45 try (ArrayDataInput in = new DefaultInput()) {
46 Assertions.assertTrue(in.markSupported());
47 }
48 }
49
50 @Test
51 public void testReadArrayFullyException() throws Exception {
52 try (ArrayDataInput in = new DefaultInput()) {
53
54 Assertions.assertThrows(EOFException.class, () -> in.readArrayFully(new int[2]));
55 }
56 }
57
58 @Test
59 public void testReadArrayFullySuccess() throws Exception {
60 int[] array = new int[2];
61
62 try (ArrayDataInput in = new DefaultInput() {
63 @Override
64 public long readLArray(Object o) throws IOException {
65 return 4L * array.length;
66 }
67 }) {
68 in.readArrayFully(array);
69 }
70 }
71
72 @Test
73 public void testReadBooleanArray() throws Exception {
74 try (ArrayDataInput in = new DefaultInput()) {
75 Boolean[] b = new Boolean[1];
76
77 Assertions.assertEquals(b.length, in.read(b));
78 Assertions.assertFalse(b[0]);
79 }
80 }
81
82 @Test
83 public void testWriteBooleanArray() throws Exception {
84 try (ArrayDataOutput out = new DefaultOutput()) {
85 Boolean[] b = new Boolean[] {Boolean.TRUE, Boolean.FALSE};
86 out.write(b);
87
88 }
89 }
90
91 @Test
92 public void testWriteBooleanNull() throws Exception {
93 try (ArrayDataOutput out = new DefaultOutput()) {
94 Boolean[] b = new Boolean[] {Boolean.TRUE, Boolean.FALSE, null};
95 Assertions.assertThrows(NullPointerException.class, () -> out.write(b));
96
97 }
98 }
99
100 class DefaultInput implements ArrayDataInput {
101
102 @Override
103 public int read() throws IOException {
104 return 0;
105 }
106
107 @Override
108 public int read(byte[] b, int from, int length) throws IOException {
109 return 0;
110 }
111
112 @Override
113 public boolean readBoolean() throws IOException {
114 return false;
115 }
116
117 @Override
118 public byte readByte() throws IOException {
119 return 0;
120 }
121
122 @Override
123 public char readChar() throws IOException {
124 return 0;
125 }
126
127 @Override
128 public double readDouble() throws IOException {
129 return 0;
130 }
131
132 @Override
133 public float readFloat() throws IOException {
134 return 0;
135 }
136
137 @Override
138 public void readFully(byte[] b) throws IOException {
139 }
140
141 @Override
142 public int readInt() throws IOException {
143 return 0;
144 }
145
146 @Override
147 public String readLine() throws IOException {
148 return null;
149 }
150
151 @Override
152 public long readLong() throws IOException {
153 return 0;
154 }
155
156 @Override
157 public short readShort() throws IOException {
158 return 0;
159 }
160
161 @Override
162 public String readUTF() throws IOException {
163 return null;
164 }
165
166 @Override
167 public int readUnsignedByte() throws IOException {
168 return 0;
169 }
170
171 @Override
172 public int readUnsignedShort() throws IOException {
173 return 0;
174 }
175
176 @Override
177 public int skipBytes(int n) throws IOException {
178 return 0;
179 }
180
181 @Override
182 public void close() throws IOException {
183 }
184
185 @Override
186 public void mark(int readlimit) throws IOException {
187 }
188
189 @Override
190 public int read(byte[] buf) throws IOException {
191 return 0;
192 }
193
194 @Override
195 public int read(boolean[] buf) throws IOException {
196 return 0;
197 }
198
199 @Override
200 public int read(boolean[] buf, int offset, int size) throws IOException {
201 return 0;
202 }
203
204 @Override
205 public int read(char[] buf) throws IOException {
206 return 0;
207 }
208
209 @Override
210 public int read(char[] buf, int offset, int size) throws IOException {
211 return 0;
212 }
213
214 @Override
215 public int read(double[] buf) throws IOException {
216 return 0;
217 }
218
219 @Override
220 public int read(double[] buf, int offset, int size) throws IOException {
221 return 0;
222 }
223
224 @Override
225 public int read(float[] buf) throws IOException {
226 return 0;
227 }
228
229 @Override
230 public int read(float[] buf, int offset, int size) throws IOException {
231 return 0;
232 }
233
234 @Override
235 public int read(int[] buf) throws IOException {
236 return 0;
237 }
238
239 @Override
240 public int read(int[] buf, int offset, int size) throws IOException {
241 return 0;
242 }
243
244 @Override
245 public int read(long[] buf) throws IOException {
246 return 0;
247 }
248
249 @Override
250 public int read(long[] buf, int offset, int size) throws IOException {
251 return 0;
252 }
253
254 @Override
255 public int read(short[] buf) throws IOException {
256 return 0;
257 }
258
259 @Override
260 public int read(short[] buf, int offset, int size) throws IOException {
261 return 0;
262 }
263
264 @Override
265 public int readArray(Object o) throws IOException, IllegalArgumentException {
266 return 0;
267 }
268
269 @Override
270 public long readLArray(Object o) throws IOException, IllegalArgumentException {
271 return 0;
272 }
273
274 @Override
275 public void reset() throws IOException {
276 }
277
278 @Override
279 public long skip(long distance) throws IOException {
280 return 0;
281 }
282
283 @Override
284 public void skipAllBytes(long toSkip) throws IOException {
285 }
286
287 @Override
288 public void readFully(byte[] b, int off, int len) throws IOException {
289 }
290 }
291
292 public static class DefaultOutput implements ArrayDataOutput {
293
294 @Override
295 public void write(int b) throws IOException {
296 }
297
298 @Override
299 public void write(byte[] b) throws IOException {
300 }
301
302 @Override
303 public void write(byte[] b, int off, int len) throws IOException {
304 }
305
306 @Override
307 public void writeBoolean(boolean v) throws IOException {
308 }
309
310 @Override
311 public void writeByte(int v) throws IOException {
312 }
313
314 @Override
315 public void writeBytes(String s) throws IOException {
316 }
317
318 @Override
319 public void writeChar(int v) throws IOException {
320 }
321
322 @Override
323 public void writeChars(String s) throws IOException {
324 }
325
326 @Override
327 public void writeDouble(double v) throws IOException {
328 }
329
330 @Override
331 public void writeFloat(float v) throws IOException {
332 }
333
334 @Override
335 public void writeInt(int v) throws IOException {
336 }
337
338 @Override
339 public void writeLong(long v) throws IOException {
340 }
341
342 @Override
343 public void writeShort(int v) throws IOException {
344 }
345
346 @Override
347 public void writeUTF(String s) throws IOException {
348 }
349
350 @Override
351 public void close() throws IOException {
352 }
353
354 @Override
355 public void flush() throws IOException {
356 }
357
358 @Override
359 public void write(boolean[] buf) throws IOException {
360 }
361
362 @Override
363 public void write(boolean[] buf, int offset, int size) throws IOException {
364 }
365
366 @Override
367 public void write(char[] buf) throws IOException {
368 }
369
370 @Override
371 public void write(char[] buf, int offset, int size) throws IOException {
372 }
373
374 @Override
375 public void write(double[] buf) throws IOException {
376 }
377
378 @Override
379 public void write(double[] buf, int offset, int size) throws IOException {
380 }
381
382 @Override
383 public void write(float[] buf) throws IOException {
384 }
385
386 @Override
387 public void write(float[] buf, int offset, int size) throws IOException {
388 }
389
390 @Override
391 public void write(int[] buf) throws IOException {
392 }
393
394 @Override
395 public void write(int[] buf, int offset, int size) throws IOException {
396 }
397
398 @Override
399 public void write(long[] buf) throws IOException {
400 }
401
402 @Override
403 public void write(long[] buf, int offset, int size) throws IOException {
404 }
405
406 @Override
407 public void write(short[] buf) throws IOException {
408 }
409
410 @Override
411 public void write(short[] buf, int offset, int size) throws IOException {
412 }
413
414 @Override
415 public void write(String[] buf) throws IOException {
416 }
417
418 @Override
419 public void write(String[] buf, int offset, int size) throws IOException {
420 }
421
422 @Override
423 public void writeArray(Object o) throws IOException, IllegalArgumentException {
424 }
425 }
426
427 }