Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 688163700
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 21, 2024
1 parent 031cefa commit 9911c83
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 52 deletions.
49 changes: 27 additions & 22 deletions android/guava-tests/test/com/google/common/io/BaseEncodingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,28 +450,6 @@ private static void assertFailsToDecode(
}

enum AssertFailsToDecodeStrategy {
@GwtIncompatible // decodingStream(Reader)
DECODING_STREAM {
@Override
void assertFailsToDecode(
BaseEncoding encoding, String cannotDecode, @Nullable String expectedMessage) {
// Regression test for case where DecodingException was swallowed by default implementation
// of
// InputStream.read(byte[], int, int)
// See https://github.com/google/guava/issues/3542
Reader reader = new StringReader(cannotDecode);
InputStream decodingStream = encoding.decodingStream(reader);
try {
ByteStreams.exhaust(decodingStream);
fail("Expected DecodingException");
} catch (DecodingException expected) {
// Don't assert on the expectedMessage; the messages for exceptions thrown from the
// decoding stream may differ from the messages for the decode methods.
} catch (IOException e) {
fail("Expected DecodingException but got: " + e);
}
}
},
CAN_DECODE {
@Override
void assertFailsToDecode(
Expand Down Expand Up @@ -506,6 +484,33 @@ void assertFailsToDecode(
}
}
}
},
/*
* This one comes last to work around b/367716565. (One *possible* alternative would be to not
* declare any methods in this enum, converting assertFailsToDecode into a static method that is
* implemented with a `switch`. I haven't tested that.)
*/
@GwtIncompatible // decodingStream(Reader)
DECODING_STREAM {
@Override
void assertFailsToDecode(
BaseEncoding encoding, String cannotDecode, @Nullable String expectedMessage) {
// Regression test for case where DecodingException was swallowed by default implementation
// of
// InputStream.read(byte[], int, int)
// See https://github.com/google/guava/issues/3542
Reader reader = new StringReader(cannotDecode);
InputStream decodingStream = encoding.decodingStream(reader);
try {
ByteStreams.exhaust(decodingStream);
fail("Expected DecodingException");
} catch (DecodingException expected) {
// Don't assert on the expectedMessage; the messages for exceptions thrown from the
// decoding stream may differ from the messages for the decode methods.
} catch (IOException e) {
fail("Expected DecodingException but got: " + e);
}
}
};

abstract void assertFailsToDecode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.google.common.base.Predicate;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ExecutionError;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.UnsupportedCharsetException;
Expand Down Expand Up @@ -134,7 +132,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
.put(
ConcurrentModificationException.class,
e -> e instanceof ConcurrentModificationException)
.put(ExecutionError.class, e -> e instanceof ExecutionError)
.put(ExecutionException.class, e -> e instanceof ExecutionException)
.put(IllegalArgumentException.class, e -> e instanceof IllegalArgumentException)
.put(IllegalStateException.class, e -> e instanceof IllegalStateException)
Expand All @@ -144,7 +141,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
.put(NumberFormatException.class, e -> e instanceof NumberFormatException)
.put(RuntimeException.class, e -> e instanceof RuntimeException)
.put(TimeoutException.class, e -> e instanceof TimeoutException)
.put(UncheckedExecutionException.class, e -> e instanceof UncheckedExecutionException)
.put(UnsupportedCharsetException.class, e -> e instanceof UnsupportedCharsetException)
.put(UnsupportedOperationException.class, e -> e instanceof UnsupportedOperationException)
.put(VerifyException.class, e -> e instanceof VerifyException)
Expand Down
49 changes: 27 additions & 22 deletions guava-tests/test/com/google/common/io/BaseEncodingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,28 +450,6 @@ private static void assertFailsToDecode(
}

enum AssertFailsToDecodeStrategy {
@GwtIncompatible // decodingStream(Reader)
DECODING_STREAM {
@Override
void assertFailsToDecode(
BaseEncoding encoding, String cannotDecode, @Nullable String expectedMessage) {
// Regression test for case where DecodingException was swallowed by default implementation
// of
// InputStream.read(byte[], int, int)
// See https://github.com/google/guava/issues/3542
Reader reader = new StringReader(cannotDecode);
InputStream decodingStream = encoding.decodingStream(reader);
try {
ByteStreams.exhaust(decodingStream);
fail("Expected DecodingException");
} catch (DecodingException expected) {
// Don't assert on the expectedMessage; the messages for exceptions thrown from the
// decoding stream may differ from the messages for the decode methods.
} catch (IOException e) {
fail("Expected DecodingException but got: " + e);
}
}
},
CAN_DECODE {
@Override
void assertFailsToDecode(
Expand Down Expand Up @@ -506,6 +484,33 @@ void assertFailsToDecode(
}
}
}
},
/*
* This one comes last to work around b/367716565. (One *possible* alternative would be to not
* declare any methods in this enum, converting assertFailsToDecode into a static method that is
* implemented with a `switch`. I haven't tested that.)
*/
@GwtIncompatible // decodingStream(Reader)
DECODING_STREAM {
@Override
void assertFailsToDecode(
BaseEncoding encoding, String cannotDecode, @Nullable String expectedMessage) {
// Regression test for case where DecodingException was swallowed by default implementation
// of
// InputStream.read(byte[], int, int)
// See https://github.com/google/guava/issues/3542
Reader reader = new StringReader(cannotDecode);
InputStream decodingStream = encoding.decodingStream(reader);
try {
ByteStreams.exhaust(decodingStream);
fail("Expected DecodingException");
} catch (DecodingException expected) {
// Don't assert on the expectedMessage; the messages for exceptions thrown from the
// decoding stream may differ from the messages for the decode methods.
} catch (IOException e) {
fail("Expected DecodingException but got: " + e);
}
}
};

abstract void assertFailsToDecode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.google.common.base.Predicate;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ExecutionError;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.UnsupportedCharsetException;
Expand Down Expand Up @@ -134,7 +132,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
.put(
ConcurrentModificationException.class,
e -> e instanceof ConcurrentModificationException)
.put(ExecutionError.class, e -> e instanceof ExecutionError)
.put(ExecutionException.class, e -> e instanceof ExecutionException)
.put(IllegalArgumentException.class, e -> e instanceof IllegalArgumentException)
.put(IllegalStateException.class, e -> e instanceof IllegalStateException)
Expand All @@ -144,7 +141,6 @@ ImmutableMap<Class<? extends Throwable>, Predicate<Throwable>> exceptions() {
.put(NumberFormatException.class, e -> e instanceof NumberFormatException)
.put(RuntimeException.class, e -> e instanceof RuntimeException)
.put(TimeoutException.class, e -> e instanceof TimeoutException)
.put(UncheckedExecutionException.class, e -> e instanceof UncheckedExecutionException)
.put(UnsupportedCharsetException.class, e -> e instanceof UnsupportedCharsetException)
.put(UnsupportedOperationException.class, e -> e instanceof UnsupportedOperationException)
.put(VerifyException.class, e -> e instanceof VerifyException)
Expand Down

0 comments on commit 9911c83

Please sign in to comment.