package com.github.davidmoten.rx;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import rx.Observable;

public class SerializedTest {

    @Test
    public void testSerializeAndDeserializeOfNonEmptyStream() {
        File file = new File("target/temp1");
        file.delete();
        Observable<Integer> source = Observable.just(1, 2, 3);
        Serialized.write(source, file, false).subscribe();
        assertTrue(file.exists());
        assertTrue(file.length()>0);
        List<Integer> list = Serialized.<Integer> read(file).toList().toBlocking().single();
        assertEquals(Arrays.asList(1,2,3),list);
    }
    
    @Test
    public void testSerializeAndDeserializeOfEmptyStream() {
        File file = new File("target/temp2");
        file.delete();
        Observable<Integer> source = Observable.empty();
        Serialized.write(source, file, false).subscribe();
        assertTrue(file.exists());
        List<Integer> list = Serialized.<Integer> read(file).toList().toBlocking().single();
        assertTrue(list.isEmpty());
    }

}

@@ -597,17 +597,19 @@
 length()
-%3E
+ %3E 
 0);%0A    
@@ -738,13 +738,528 @@
 t(1,
+ 
 2,
+ 
 3),
+ list);%0A    %7D%0A%0A    @Test%0A    public void testSerializeAndDeserializeOfNonEmptyStreamWithSmallBuffer() %7B%0A        File file = new File(%22target/temp1%22);%0A        file.delete();%0A        Observable%3CInteger%3E source = Observable.just(1, 2, 3);%0A        Serialized.write(source, file, false, 1).subscribe();%0A        assertTrue(file.exists());%0A        assertTrue(file.length() %3E 0);%0A        List%3CInteger%3E list = Serialized.%3CInteger%3E read(file, 1).toList().toBlocking().single();%0A        assertEquals(Arrays.asList(1, 2, 3), 
 list
@@ -1267,20 +1267,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Te

add Serialized unit test