1 package de.japrost.jabudget.serialization;
2
3 import static org.assertj.core.api.Assertions.assertThat;
4
5 import java.io.File;
6
7 import org.junit.After;
8 import org.junit.Before;
9 import org.junit.Test;
10
11
12
13
14
15 public class LazyFileOutputStreamTest {
16
17 private LazyFileOutputStream cut;
18 private LazyFileInputStream helper;
19
20
21
22
23 @Before
24 public void initCut() {
25 final File file = new File("target/LazyFile.txt");
26 cut = new LazyFileOutputStream(file);
27 helper = new LazyFileInputStream(file);
28 }
29
30
31
32
33
34
35 @After
36 public void closeCut() throws Exception {
37 cut.close();
38 helper.close();
39 }
40
41
42
43
44
45
46 @Test
47 public void testWrite() throws Exception {
48
49 assertThat(cut.isOpen()).isFalse();
50
51 cut.write(97);
52
53 assertThat(cut.isOpen()).isTrue();
54 assertThat(helper.read()).isEqualTo(97);
55 assertThat(helper.read()).isEqualTo(-1);
56 }
57
58
59
60
61
62
63 @Test
64 public void testWrite_twice() throws Exception {
65
66 assertThat(cut.isOpen()).isFalse();
67
68 cut.write(97);
69 cut.write(32);
70
71 assertThat(cut.isOpen()).isTrue();
72 assertThat(helper.read()).isEqualTo(97);
73 assertThat(helper.read()).isEqualTo(32);
74 assertThat(helper.read()).isEqualTo(-1);
75 }
76
77 }