View Javadoc
1   package nom.tam.util;
2   
3   /*-
4    * #%L
5    * nom.tam FITS library
6    * %%
7    * Copyright (C) 1996 - 2024 nom-tam-fits
8    * %%
9    * This is free and unencumbered software released into the public domain.
10   *
11   * Anyone is free to copy, modify, publish, use, compile, sell, or
12   * distribute this software, either in source code form or as a compiled
13   * binary, for any purpose, commercial or non-commercial, and by any
14   * means.
15   *
16   * In jurisdictions that recognize copyright laws, the author or authors
17   * of this software dedicate any and all copyright interest in the
18   * software to the public domain. We make this dedication for the benefit
19   * of the public at large and to the detriment of our heirs and
20   * successors. We intend this dedication to be an overt act of
21   * relinquishment in perpetuity of all present and future rights to this
22   * software under copyright law.
23   *
24   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30   * OTHER DEALINGS IN THE SOFTWARE.
31   * #L%
32   */
33  
34  import static org.junit.Assert.assertEquals;
35  
36  import java.io.EOFException;
37  import java.io.IOException;
38  
39  import org.junit.Test;
40  
41  public class DefaultMethodsTest {
42  
43      @Test
44      public void testMarkSupported() throws Exception {
45          assertEquals(true, new DefaultInput().markSupported());
46      }
47  
48      @Test(expected = EOFException.class)
49      public void testReadArrayFullyException() throws Exception {
50          int[] array = new int[2];
51          new DefaultInput().readArrayFully(array);
52          // throws EOFException since the test read() returns 0 always...
53      }
54  
55      @Test
56      public void testReadArrayFullySuccess() throws Exception {
57          int[] array = new int[2];
58          new DefaultInput() {
59              @Override
60              public long readLArray(Object o) throws IOException {
61                  return 4L * array.length;
62              }
63          }.readArrayFully(array);
64      }
65  
66      @Test
67      public void testReadBooleanArray() throws Exception {
68          Boolean[] b = new Boolean[1];
69          assertEquals(b.length, new DefaultInput().read(b));
70          assertEquals(false, b[0]);
71      }
72  
73      @Test
74      public void testWriteBooleanArray() throws Exception {
75          Boolean[] b = new Boolean[] {Boolean.TRUE, Boolean.FALSE};
76          new DefaultOutput().write(b);
77          // No exception thrown...
78      }
79  
80      @Test(expected = NullPointerException.class)
81      public void testWriteBooleanNull() throws Exception {
82          Boolean[] b = new Boolean[] {Boolean.TRUE, Boolean.FALSE, null};
83          new DefaultOutput().write(b);
84          // A NullPointerException is thrown, because the deffault implementation does not handle null...
85      }
86  
87      class DefaultInput implements ArrayDataInput {
88  
89          @Override
90          public int read() throws IOException {
91              // TODO Auto-generated method stub
92              return 0;
93          }
94  
95          @Override
96          public int read(byte[] b, int from, int length) throws IOException {
97              // TODO Auto-generated method stub
98              return 0;
99          }
100 
101         @Override
102         public boolean readBoolean() throws IOException {
103             // TODO Auto-generated method stub
104             return false;
105         }
106 
107         @Override
108         public byte readByte() throws IOException {
109             // TODO Auto-generated method stub
110             return 0;
111         }
112 
113         @Override
114         public char readChar() throws IOException {
115             // TODO Auto-generated method stub
116             return 0;
117         }
118 
119         @Override
120         public double readDouble() throws IOException {
121             // TODO Auto-generated method stub
122             return 0;
123         }
124 
125         @Override
126         public float readFloat() throws IOException {
127             // TODO Auto-generated method stub
128             return 0;
129         }
130 
131         @Override
132         public void readFully(byte[] b) throws IOException {
133             // TODO Auto-generated method stub
134 
135         }
136 
137         @Override
138         public int readInt() throws IOException {
139             // TODO Auto-generated method stub
140             return 0;
141         }
142 
143         @Override
144         public String readLine() throws IOException {
145             // TODO Auto-generated method stub
146             return null;
147         }
148 
149         @Override
150         public long readLong() throws IOException {
151             // TODO Auto-generated method stub
152             return 0;
153         }
154 
155         @Override
156         public short readShort() throws IOException {
157             // TODO Auto-generated method stub
158             return 0;
159         }
160 
161         @Override
162         public String readUTF() throws IOException {
163             // TODO Auto-generated method stub
164             return null;
165         }
166 
167         @Override
168         public int readUnsignedByte() throws IOException {
169             // TODO Auto-generated method stub
170             return 0;
171         }
172 
173         @Override
174         public int readUnsignedShort() throws IOException {
175             // TODO Auto-generated method stub
176             return 0;
177         }
178 
179         @Override
180         public int skipBytes(int n) throws IOException {
181             // TODO Auto-generated method stub
182             return 0;
183         }
184 
185         @Override
186         public void close() throws IOException {
187             // TODO Auto-generated method stub
188 
189         }
190 
191         @Override
192         public void mark(int readlimit) throws IOException {
193             // TODO Auto-generated method stub
194 
195         }
196 
197         @Override
198         public int read(byte[] buf) throws IOException {
199             // TODO Auto-generated method stub
200             return 0;
201         }
202 
203         @Override
204         public int read(boolean[] buf) throws IOException {
205             // TODO Auto-generated method stub
206             return 0;
207         }
208 
209         @Override
210         public int read(boolean[] buf, int offset, int size) throws IOException {
211             // TODO Auto-generated method stub
212             return 0;
213         }
214 
215         @Override
216         public int read(char[] buf) throws IOException {
217             // TODO Auto-generated method stub
218             return 0;
219         }
220 
221         @Override
222         public int read(char[] buf, int offset, int size) throws IOException {
223             // TODO Auto-generated method stub
224             return 0;
225         }
226 
227         @Override
228         public int read(double[] buf) throws IOException {
229             // TODO Auto-generated method stub
230             return 0;
231         }
232 
233         @Override
234         public int read(double[] buf, int offset, int size) throws IOException {
235             // TODO Auto-generated method stub
236             return 0;
237         }
238 
239         @Override
240         public int read(float[] buf) throws IOException {
241             // TODO Auto-generated method stub
242             return 0;
243         }
244 
245         @Override
246         public int read(float[] buf, int offset, int size) throws IOException {
247             // TODO Auto-generated method stub
248             return 0;
249         }
250 
251         @Override
252         public int read(int[] buf) throws IOException {
253             // TODO Auto-generated method stub
254             return 0;
255         }
256 
257         @Override
258         public int read(int[] buf, int offset, int size) throws IOException {
259             // TODO Auto-generated method stub
260             return 0;
261         }
262 
263         @Override
264         public int read(long[] buf) throws IOException {
265             // TODO Auto-generated method stub
266             return 0;
267         }
268 
269         @Override
270         public int read(long[] buf, int offset, int size) throws IOException {
271             // TODO Auto-generated method stub
272             return 0;
273         }
274 
275         @Override
276         public int read(short[] buf) throws IOException {
277             // TODO Auto-generated method stub
278             return 0;
279         }
280 
281         @Override
282         public int read(short[] buf, int offset, int size) throws IOException {
283             // TODO Auto-generated method stub
284             return 0;
285         }
286 
287         @Override
288         public int readArray(Object o) throws IOException, IllegalArgumentException {
289             // TODO Auto-generated method stub
290             return 0;
291         }
292 
293         @Override
294         public long readLArray(Object o) throws IOException, IllegalArgumentException {
295             // TODO Auto-generated method stub
296             return 0;
297         }
298 
299         @Override
300         public void reset() throws IOException {
301             // TODO Auto-generated method stub
302 
303         }
304 
305         @Override
306         public long skip(long distance) throws IOException {
307             // TODO Auto-generated method stub
308             return 0;
309         }
310 
311         @Override
312         public void skipAllBytes(long toSkip) throws IOException {
313             // TODO Auto-generated method stub
314 
315         }
316 
317         @Override
318         public void readFully(byte[] b, int off, int len) throws IOException {
319             // TODO Auto-generated method stub
320 
321         }
322     }
323 
324     public static class DefaultOutput implements ArrayDataOutput {
325 
326         @Override
327         public void write(int b) throws IOException {
328             // TODO Auto-generated method stub
329 
330         }
331 
332         @Override
333         public void write(byte[] b) throws IOException {
334             // TODO Auto-generated method stub
335 
336         }
337 
338         @Override
339         public void write(byte[] b, int off, int len) throws IOException {
340             // TODO Auto-generated method stub
341 
342         }
343 
344         @Override
345         public void writeBoolean(boolean v) throws IOException {
346             // TODO Auto-generated method stub
347 
348         }
349 
350         @Override
351         public void writeByte(int v) throws IOException {
352             // TODO Auto-generated method stub
353 
354         }
355 
356         @Override
357         public void writeBytes(String s) throws IOException {
358             // TODO Auto-generated method stub
359 
360         }
361 
362         @Override
363         public void writeChar(int v) throws IOException {
364             // TODO Auto-generated method stub
365 
366         }
367 
368         @Override
369         public void writeChars(String s) throws IOException {
370             // TODO Auto-generated method stub
371 
372         }
373 
374         @Override
375         public void writeDouble(double v) throws IOException {
376             // TODO Auto-generated method stub
377 
378         }
379 
380         @Override
381         public void writeFloat(float v) throws IOException {
382             // TODO Auto-generated method stub
383 
384         }
385 
386         @Override
387         public void writeInt(int v) throws IOException {
388             // TODO Auto-generated method stub
389 
390         }
391 
392         @Override
393         public void writeLong(long v) throws IOException {
394             // TODO Auto-generated method stub
395 
396         }
397 
398         @Override
399         public void writeShort(int v) throws IOException {
400             // TODO Auto-generated method stub
401 
402         }
403 
404         @Override
405         public void writeUTF(String s) throws IOException {
406             // TODO Auto-generated method stub
407 
408         }
409 
410         @Override
411         public void close() throws IOException {
412             // TODO Auto-generated method stub
413 
414         }
415 
416         @Override
417         public void flush() throws IOException {
418             // TODO Auto-generated method stub
419 
420         }
421 
422         @Override
423         public void write(boolean[] buf) throws IOException {
424             // TODO Auto-generated method stub
425 
426         }
427 
428         @Override
429         public void write(boolean[] buf, int offset, int size) throws IOException {
430             // TODO Auto-generated method stub
431 
432         }
433 
434         @Override
435         public void write(char[] buf) throws IOException {
436             // TODO Auto-generated method stub
437 
438         }
439 
440         @Override
441         public void write(char[] buf, int offset, int size) throws IOException {
442             // TODO Auto-generated method stub
443 
444         }
445 
446         @Override
447         public void write(double[] buf) throws IOException {
448             // TODO Auto-generated method stub
449 
450         }
451 
452         @Override
453         public void write(double[] buf, int offset, int size) throws IOException {
454             // TODO Auto-generated method stub
455 
456         }
457 
458         @Override
459         public void write(float[] buf) throws IOException {
460             // TODO Auto-generated method stub
461 
462         }
463 
464         @Override
465         public void write(float[] buf, int offset, int size) throws IOException {
466             // TODO Auto-generated method stub
467 
468         }
469 
470         @Override
471         public void write(int[] buf) throws IOException {
472             // TODO Auto-generated method stub
473 
474         }
475 
476         @Override
477         public void write(int[] buf, int offset, int size) throws IOException {
478             // TODO Auto-generated method stub
479 
480         }
481 
482         @Override
483         public void write(long[] buf) throws IOException {
484             // TODO Auto-generated method stub
485 
486         }
487 
488         @Override
489         public void write(long[] buf, int offset, int size) throws IOException {
490             // TODO Auto-generated method stub
491 
492         }
493 
494         @Override
495         public void write(short[] buf) throws IOException {
496             // TODO Auto-generated method stub
497 
498         }
499 
500         @Override
501         public void write(short[] buf, int offset, int size) throws IOException {
502             // TODO Auto-generated method stub
503 
504         }
505 
506         @Override
507         public void write(String[] buf) throws IOException {
508             // TODO Auto-generated method stub
509 
510         }
511 
512         @Override
513         public void write(String[] buf, int offset, int size) throws IOException {
514             // TODO Auto-generated method stub
515 
516         }
517 
518         @Override
519         public void writeArray(Object o) throws IOException, IllegalArgumentException {
520             // TODO Auto-generated method stub
521 
522         }
523     }
524 
525 }