diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java index 7ff2eb9fd6c..84166df5882 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import org.junit.Assert; import org.junit.Test; public class Utf8StringBuilderTest @@ -35,14 +36,38 @@ public class Utf8StringBuilderTest Utf8StringBuilder buffer = new Utf8StringBuilder(); buffer.append(bytes,0,bytes.length); - assertEquals(i,"not expected",buffer.toString()); + Assert.fail("Should have thrown a NotUtf8Exception"); } catch (Utf8Appendable.NotUtf8Exception e) { - assertTrue(i,true); + // expected path } } } + + @Test + public void testFastFail() throws Exception + { + byte[] part1 = TypeUtil.fromHexString("cebae1bdb9cf83cebcceb5"); + byte[] part2 = TypeUtil.fromHexString("f4908080"); // INVALID + byte[] part3 = TypeUtil.fromHexString("656469746564"); + + Utf8StringBuilder buffer = new Utf8StringBuilder(); + // Part 1 is valid + buffer.append(part1,0,part1.length); + try + { + // Part 2 is invalid + buffer.append(part2,0,part2.length); + Assert.fail("Should have thrown a NotUtf8Exception"); + } + catch (Utf8Appendable.NotUtf8Exception e) + { + // expected path + } + // Part 3 is valid + buffer.append(part3,0,part3.length); + } @Test public void testUtfStringBuilder() throws Exception @@ -78,13 +103,14 @@ public class Utf8StringBuilderTest Utf8StringBuilder buffer = new Utf8StringBuilder(); try { - for (byte aByte : bytes) + for (byte aByte : bytes) { buffer.append(aByte); - assertTrue(false); + } + Assert.fail("Should have resulted in an Utf8Appendable.NotUtf8Exception"); } - catch (IllegalArgumentException e) + catch (Utf8Appendable.NotUtf8Exception e) { - assertTrue(true); + // expected path } assertEquals("abc\ufffd",buffer.toString()); }