From 289eaa829511b7aa536c86793f86f46a31d4a28e Mon Sep 17 00:00:00 2001 From: Olli Virtanen Date: Mon, 28 May 2018 12:36:35 +0200 Subject: Stricter verification of exception in builder_cannot_be_reused using @Rule; visibility cleanups --- .../com/yahoo/application/ApplicationBuilderTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'application/src') diff --git a/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java b/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java index 410ecdf886e..42f3a7267d8 100644 --- a/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java +++ b/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java @@ -2,14 +2,14 @@ package com.yahoo.application; import com.yahoo.io.IOUtils; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.nio.file.Files; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** * @author Tony Vaagenes @@ -48,9 +48,15 @@ public class ApplicationBuilderTest { }); } - @Test(expected = RuntimeException.class) + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test @SuppressWarnings("try") // application unreferenced inside try public void builder_cannot_be_reused() throws Exception { + expectedException.expect(RuntimeException.class); + expectedException.expectMessage(containsString("build method")); + ApplicationBuilder builder = new ApplicationBuilder(); builder.servicesXml(""); try (Application application = builder.build()) { @@ -61,10 +67,10 @@ public class ApplicationBuilderTest { } private interface TestCase { - public void accept(ApplicationBuilder ab) throws Exception; + void accept(ApplicationBuilder ab) throws Exception; } - public void withApplicationBuilder(TestCase f) throws Exception { + private static void withApplicationBuilder(TestCase f) throws Exception { ApplicationBuilder builder = new ApplicationBuilder(); try { f.accept(builder); -- cgit v1.2.3