Search in sources :

Example 1 with BufferedSource

use of okio.BufferedSource in project Store by NYTimes.

the class FilePersisterTest method writeThenRead.

@Test
public void writeThenRead() throws IOException {
    when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource);
    when(fileSystem.exists(resolvedPath)).thenReturn(true);
    fileSystemPersister.write(simple, bufferedSource).toBlocking().single();
    BufferedSource source = fileSystemPersister.read(simple).toBlocking().first();
    InOrder inOrder = inOrder(fileSystem);
    inOrder.verify(fileSystem).write(resolvedPath, bufferedSource);
    inOrder.verify(fileSystem).exists(resolvedPath);
    inOrder.verify(fileSystem).read(resolvedPath);
    assertThat(source).isEqualTo(bufferedSource);
}
Also used : InOrder(org.mockito.InOrder) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 2 with BufferedSource

use of okio.BufferedSource in project Store by NYTimes.

the class FileSystemRecordPersisterTest method readExists.

@Test
public void readExists() throws FileNotFoundException {
    when(fileSystem.exists(resolvedPath)).thenReturn(true);
    when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource);
    BufferedSource returnedValue = fileSystemPersister.read(simple).toBlocking().single();
    assertThat(returnedValue).isEqualTo(bufferedSource);
}
Also used : BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 3 with BufferedSource

use of okio.BufferedSource in project Store by NYTimes.

the class FileSystemRecordPersisterTest method writeThenRead.

@Test
public void writeThenRead() throws IOException {
    when(fileSystem.read(resolvedPath)).thenReturn(bufferedSource);
    when(fileSystem.exists(resolvedPath)).thenReturn(true);
    fileSystemPersister.write(simple, bufferedSource).toBlocking().single();
    BufferedSource source = fileSystemPersister.read(simple).toBlocking().first();
    InOrder inOrder = inOrder(fileSystem);
    inOrder.verify(fileSystem).write(resolvedPath, bufferedSource);
    inOrder.verify(fileSystem).exists(resolvedPath);
    inOrder.verify(fileSystem).read(resolvedPath);
    assertThat(source).isEqualTo(bufferedSource);
}
Also used : InOrder(org.mockito.InOrder) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 4 with BufferedSource

use of okio.BufferedSource in project Store by NYTimes.

the class JacksonSourceParserStoreTest method testDefaultJacksonSourceParser.

@Test
public void testDefaultJacksonSourceParser() {
    Parser<BufferedSource, Foo> parser = JacksonParserFactory.createSourceParser(Foo.class);
    Store<Foo, BarCode> store = StoreBuilder.<BarCode, BufferedSource, Foo>parsedWithKey().persister(persister).fetcher(fetcher).parser(parser).open();
    Foo result = store.get(barCode).toBlocking().first();
    validateFoo(result);
    verify(fetcher, times(1)).fetch(barCode);
}
Also used : Foo(com.nytimes.android.external.store.middleware.jackson.data.Foo) BarCode(com.nytimes.android.external.store.base.impl.BarCode) BufferedSource(okio.BufferedSource) Test(org.junit.Test)

Example 5 with BufferedSource

use of okio.BufferedSource in project Store by NYTimes.

the class JacksonSourceParserStoreTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    BufferedSource bufferedSource = source(sourceString);
    assertNotNull(bufferedSource);
    when(fetcher.fetch(barCode)).thenReturn(Observable.just(bufferedSource));
    when(persister.read(barCode)).thenReturn(Observable.<BufferedSource>empty()).thenReturn(Observable.just(bufferedSource));
    when(persister.write(barCode, bufferedSource)).thenReturn(Observable.just(true));
}
Also used : BufferedSource(okio.BufferedSource) Before(org.junit.Before)

Aggregations

BufferedSource (okio.BufferedSource)72 Test (org.junit.Test)33 Buffer (okio.Buffer)21 IOException (java.io.IOException)19 Request (okhttp3.Request)8 Response (okhttp3.Response)8 BarCode (com.nytimes.android.external.store.base.impl.BarCode)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 EOFException (java.io.EOFException)6 InputStream (java.io.InputStream)6 ResponseBody (okhttp3.ResponseBody)6 Gson (com.google.gson.Gson)4 File (java.io.File)4 Charset (java.nio.charset.Charset)4 Headers (okhttp3.Headers)4 MediaType (okhttp3.MediaType)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 BufferedSink (okio.BufferedSink)4 Sink (okio.Sink)4 RequestBody (okhttp3.RequestBody)3