1616
1717package com .google .gcloud .storage ;
1818
19+ import static org .easymock .EasyMock .anyObject ;
20+ import static org .easymock .EasyMock .createMock ;
21+ import static org .easymock .EasyMock .expect ;
22+ import static org .easymock .EasyMock .expectLastCall ;
23+ import static org .easymock .EasyMock .replay ;
1924import static org .easymock .EasyMock .verify ;
2025import static org .junit .Assert .assertArrayEquals ;
2126import static org .junit .Assert .assertEquals ;
2732import com .google .gcloud .spi .StorageRpc ;
2833import com .google .gcloud .spi .StorageRpcFactory ;
2934
30- import org .easymock .EasyMock ;
3135import org .junit .After ;
3236import org .junit .Before ;
3337import org .junit .Test ;
@@ -49,16 +53,16 @@ public class BlobReadChannelImplTest {
4953 private static final Random RANDOM = new Random ();
5054
5155 private StorageOptions options ;
56+ private StorageRpcFactory rpcFactoryMock ;
5257 private StorageRpc storageRpcMock ;
5358 private BlobReadChannelImpl reader ;
5459
5560 @ Before
5661 public void setUp () throws IOException , InterruptedException {
57- StorageRpcFactory rpcFactoryMock = EasyMock .createNiceMock (StorageRpcFactory .class );
58- storageRpcMock = EasyMock .createMock (StorageRpc .class );
59- EasyMock .expect (rpcFactoryMock .create (EasyMock .anyObject (StorageOptions .class )))
60- .andReturn (storageRpcMock );
61- EasyMock .replay (rpcFactoryMock );
62+ rpcFactoryMock = createMock (StorageRpcFactory .class );
63+ storageRpcMock = createMock (StorageRpc .class );
64+ expect (rpcFactoryMock .create (anyObject (StorageOptions .class ))).andReturn (storageRpcMock );
65+ replay (rpcFactoryMock );
6266 options = StorageOptions .builder ()
6367 .projectId ("projectId" )
6468 .serviceRpcFactory (rpcFactoryMock )
@@ -67,12 +71,12 @@ public void setUp() throws IOException, InterruptedException {
6771
6872 @ After
6973 public void tearDown () throws Exception {
70- verify (storageRpcMock );
74+ verify (rpcFactoryMock , storageRpcMock );
7175 }
7276
7377 @ Test
7478 public void testCreate () {
75- EasyMock . replay (storageRpcMock );
79+ replay (storageRpcMock );
7680 reader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
7781 assertTrue (reader .isOpen ());
7882 }
@@ -83,10 +87,9 @@ public void testReadBuffered() throws IOException {
8387 byte [] result = randomByteArray (DEFAULT_CHUNK_SIZE );
8488 ByteBuffer firstReadBuffer = ByteBuffer .allocate (42 );
8589 ByteBuffer secondReadBuffer = ByteBuffer .allocate (42 );
86- EasyMock
87- .expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
90+ expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
8891 .andReturn (result );
89- EasyMock . replay (storageRpcMock );
92+ replay (storageRpcMock );
9093 reader .read (firstReadBuffer );
9194 reader .read (secondReadBuffer );
9295 assertArrayEquals (Arrays .copyOf (result , firstReadBuffer .capacity ()), firstReadBuffer .array ());
@@ -104,15 +107,11 @@ public void testReadBig() throws IOException {
104107 byte [] secondResult = randomByteArray (DEFAULT_CHUNK_SIZE );
105108 ByteBuffer firstReadBuffer = ByteBuffer .allocate (DEFAULT_CHUNK_SIZE );
106109 ByteBuffer secondReadBuffer = ByteBuffer .allocate (42 );
107- EasyMock
108- .expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
109- .andReturn (firstResult );
110- EasyMock
111- .expect (
112- storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , DEFAULT_CHUNK_SIZE ,
113- CUSTOM_CHUNK_SIZE ))
114- .andReturn (secondResult );
115- EasyMock .replay (storageRpcMock );
110+ storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE );
111+ expectLastCall ().andReturn (firstResult );
112+ storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , DEFAULT_CHUNK_SIZE , CUSTOM_CHUNK_SIZE );
113+ expectLastCall ().andReturn (secondResult );
114+ replay (storageRpcMock );
116115 reader .read (firstReadBuffer );
117116 reader .read (secondReadBuffer );
118117 assertArrayEquals (firstResult , firstReadBuffer .array ());
@@ -125,10 +124,9 @@ public void testReadFinish() throws IOException {
125124 reader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
126125 byte [] result = {};
127126 ByteBuffer readBuffer = ByteBuffer .allocate (DEFAULT_CHUNK_SIZE );
128- EasyMock
129- .expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
127+ expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
130128 .andReturn (result );
131- EasyMock . replay (storageRpcMock );
129+ replay (storageRpcMock );
132130 assertEquals (-1 , reader .read (readBuffer ));
133131 }
134132
@@ -138,17 +136,16 @@ public void testSeek() throws IOException {
138136 reader .seek (42 );
139137 byte [] result = randomByteArray (DEFAULT_CHUNK_SIZE );
140138 ByteBuffer readBuffer = ByteBuffer .allocate (DEFAULT_CHUNK_SIZE );
141- EasyMock
142- .expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 42 , DEFAULT_CHUNK_SIZE ))
139+ expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 42 , DEFAULT_CHUNK_SIZE ))
143140 .andReturn (result );
144- EasyMock . replay (storageRpcMock );
141+ replay (storageRpcMock );
145142 reader .read (readBuffer );
146143 assertArrayEquals (result , readBuffer .array ());
147144 }
148145
149146 @ Test
150147 public void testClose () throws IOException {
151- EasyMock . replay (storageRpcMock );
148+ replay (storageRpcMock );
152149 reader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
153150 assertTrue (reader .isOpen ());
154151 reader .close ();
@@ -157,7 +154,7 @@ public void testClose() throws IOException {
157154
158155 @ Test
159156 public void testReadClosed () {
160- EasyMock . replay (storageRpcMock );
157+ replay (storageRpcMock );
161158 reader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
162159 reader .close ();
163160 try {
@@ -175,13 +172,11 @@ public void testSaveAndRestore() throws IOException, ClassNotFoundException {
175172 byte [] secondResult = randomByteArray (DEFAULT_CHUNK_SIZE );
176173 ByteBuffer firstReadBuffer = ByteBuffer .allocate (42 );
177174 ByteBuffer secondReadBuffer = ByteBuffer .allocate (DEFAULT_CHUNK_SIZE );
178- EasyMock
179- .expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
175+ expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 0 , DEFAULT_CHUNK_SIZE ))
180176 .andReturn (firstResult );
181- EasyMock
182- .expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 42 , DEFAULT_CHUNK_SIZE ))
177+ expect (storageRpcMock .read (BLOB_ID .toPb (), EMPTY_RPC_OPTIONS , 42 , DEFAULT_CHUNK_SIZE ))
183178 .andReturn (secondResult );
184- EasyMock . replay (storageRpcMock );
179+ replay (storageRpcMock );
185180 reader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
186181 reader .read (firstReadBuffer );
187182 RestorableState <BlobReadChannel > readerState = reader .capture ();
@@ -194,7 +189,7 @@ public void testSaveAndRestore() throws IOException, ClassNotFoundException {
194189
195190 @ Test
196191 public void testStateEquals () {
197- EasyMock . replay (storageRpcMock );
192+ replay (storageRpcMock );
198193 reader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
199194 BlobReadChannel secondReader = new BlobReadChannelImpl (options , BLOB_ID , EMPTY_RPC_OPTIONS );
200195 RestorableState <BlobReadChannel > state = reader .capture ();
0 commit comments