Skip to content

Commit d12b0d7

Browse files
Storage Copybara: Fixing ErrorProne Warnings (#509)
1 parent 24fda58 commit d12b0d7

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

firebase-storage/src/test/java/com/google/firebase/storage/TestUtil.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,19 @@ private static void verifyTaskStateChanges(@Nullable InputStream inputStream, St
8080
}
8181

8282
StringBuilder baselineContents = new StringBuilder();
83-
try {
84-
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
83+
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
8584
// skip to first <new>
8685
String line;
8786
while ((line = br.readLine()) != null) {
8887
baselineContents.append(line).append("\n");
8988
}
90-
inputStream.close();
9189
} catch (IOException e) {
92-
e.printStackTrace();
90+
throw new RuntimeException(e);
9391
}
9492

95-
try {
96-
BufferedReader current = new BufferedReader(new StringReader(contents));
97-
BufferedReader baseline = new BufferedReader(new StringReader(baselineContents.toString()));
93+
try (BufferedReader current = new BufferedReader(new StringReader(contents));
94+
BufferedReader baseline =
95+
new BufferedReader(new StringReader(baselineContents.toString()))) {
9896
String originalLine;
9997
String newLine;
10098
// skip to first <new>
@@ -121,16 +119,8 @@ private static void verifyTaskStateChanges(@Nullable InputStream inputStream, St
121119
}
122120
line++;
123121
}
124-
current.close();
125-
baseline.close();
126122
} catch (IOException e) {
127-
e.printStackTrace();
128-
}
129-
130-
try {
131-
inputStream.close();
132-
} catch (IOException e) {
133-
e.printStackTrace();
123+
throw new RuntimeException(e);
134124
}
135125
}
136126

firebase-storage/src/test/java/com/google/firebase/storage/network/MockConnectionFactory.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@
4141
import org.mockito.ArgumentCaptor;
4242
import org.mockito.Mockito;
4343
import org.mockito.exceptions.base.MockitoAssertionError;
44-
import org.mockito.invocation.InvocationOnMock;
45-
import org.mockito.stubbing.Answer;
4644

4745
public class MockConnectionFactory implements HttpURLConnectionFactory {
48-
private static final String LOG_TAG = MockConnectionFactory.class.getName();
49-
5046
private final boolean binaryBody;
5147
HttpURLConnection oldMock;
5248
List<String> verifications = new ArrayList<>();
@@ -69,7 +65,7 @@ public MockConnectionFactory(String testName, boolean binaryBody) {
6965
}
7066
}
7167
} catch (IOException e) {
72-
e.printStackTrace();
68+
throw new RuntimeException(e);
7369
}
7470
}
7571

@@ -166,16 +162,13 @@ public synchronized HttpURLConnection createInstance(@NonNull URL url) throws IO
166162
currentRecord++;
167163
if (currentRecord == pauseRecord) {
168164
Mockito.doAnswer(
169-
new Answer<Void>() {
170-
@Override
171-
public Void answer(InvocationOnMock invocation) {
172-
try {
173-
pauseSemaphore.acquire();
174-
} catch (InterruptedException e) {
175-
e.printStackTrace();
176-
}
177-
return null;
165+
invocation -> {
166+
try {
167+
pauseSemaphore.acquire();
168+
} catch (InterruptedException e) {
169+
Thread.currentThread().interrupt();
178170
}
171+
return null;
179172
})
180173
.when(mock)
181174
.disconnect();
@@ -205,7 +198,7 @@ public synchronized void verifyOldMock() {
205198
try {
206199
verify(oldMock).setRequestMethod(value);
207200
} catch (ProtocolException e) {
208-
e.printStackTrace();
201+
throw new RuntimeException(e);
209202
}
210203
} else if (key.equalsIgnoreCase("setRequestProperty")) {
211204
int comma = value.indexOf(',');

0 commit comments

Comments
 (0)