Skip to content

Storage Copybara: Fixing ErrorProne Warnings #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,19 @@ private static void verifyTaskStateChanges(@Nullable InputStream inputStream, St
}

StringBuilder baselineContents = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
// skip to first <new>
String line;
while ((line = br.readLine()) != null) {
baselineContents.append(line).append("\n");
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}

try {
BufferedReader current = new BufferedReader(new StringReader(contents));
BufferedReader baseline = new BufferedReader(new StringReader(baselineContents.toString()));
try (BufferedReader current = new BufferedReader(new StringReader(contents));
BufferedReader baseline =
new BufferedReader(new StringReader(baselineContents.toString()))) {
String originalLine;
String newLine;
// skip to first <new>
Expand All @@ -121,16 +119,8 @@ private static void verifyTaskStateChanges(@Nullable InputStream inputStream, St
}
line++;
}
current.close();
baseline.close();
} catch (IOException e) {
e.printStackTrace();
}

try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

public class MockConnectionFactory implements HttpURLConnectionFactory {
private static final String LOG_TAG = MockConnectionFactory.class.getName();

private final boolean binaryBody;
HttpURLConnection oldMock;
List<String> verifications = new ArrayList<>();
Expand All @@ -69,7 +65,7 @@ public MockConnectionFactory(String testName, boolean binaryBody) {
}
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -166,16 +162,13 @@ public synchronized HttpURLConnection createInstance(@NonNull URL url) throws IO
currentRecord++;
if (currentRecord == pauseRecord) {
Mockito.doAnswer(
new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
try {
pauseSemaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
invocation -> {
try {
pauseSemaphore.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return null;
})
.when(mock)
.disconnect();
Expand Down Expand Up @@ -205,7 +198,7 @@ public synchronized void verifyOldMock() {
try {
verify(oldMock).setRequestMethod(value);
} catch (ProtocolException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} else if (key.equalsIgnoreCase("setRequestProperty")) {
int comma = value.indexOf(',');
Expand Down