diff options
Diffstat (limited to 'vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java')
-rw-r--r-- | vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java b/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java index 0b828c91f91..c448e5d55f5 100644 --- a/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java +++ b/vespaclient-java/src/test/java/com/yahoo/vespaget/CommandLineOptionsTest.java @@ -5,9 +5,7 @@ import com.yahoo.document.fieldset.AllFields; import com.yahoo.document.fieldset.DocumentOnly; import com.yahoo.document.fieldset.DocIdOnly; import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -17,9 +15,7 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.util.Iterator; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; /** * Test class for {@link CommandLineOptions} @@ -37,10 +33,6 @@ public class CommandLineOptionsTest { } }; - @SuppressWarnings("deprecation") - @Rule - public final ExpectedException exception = ExpectedException.none(); - private ClientParameters getParsedOptions(InputStream in, String... args) { CommandLineOptions options = new CommandLineOptions(in); return options.parseCommandLineArguments(args); @@ -51,7 +43,7 @@ public class CommandLineOptionsTest { } @Test - public void testDefaultOptions() { + void testDefaultOptions() { ClientParameters params = getParsedOptions(); assertFalse(params.help); assertFalse(params.documentIds.hasNext()); @@ -68,7 +60,7 @@ public class CommandLineOptionsTest { } @Test - public void testValidOptions() { + void testValidOptions() { ClientParameters params = getParsedOptions( "--fieldset", "[fieldset]", "--route", "dummyroute", @@ -97,73 +89,78 @@ public class CommandLineOptionsTest { } @Test - public void testInvalidCombination3() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Field set option can not be used in combination with print ids option."); - getParsedOptions("--printids", "--fieldset", AllFields.NAME); + void testInvalidCombination3() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + getParsedOptions("--printids", "--fieldset", AllFields.NAME); + }); + assertTrue(exception.getMessage().contains("Field set option can not be used in combination with print ids option.")); } @Test - public void testInvalidCombination4() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Cluster and route options are mutually exclusive."); - getParsedOptions("--route", "dummyroute", "--cluster", "dummycluster"); + void testInvalidCombination4() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + getParsedOptions("--route", "dummyroute", "--cluster", "dummycluster"); + }); + assertTrue(exception.getMessage().contains("Cluster and route options are mutually exclusive.")); } @Test - public void testInvalidPriority() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Invalid priority: 16"); - getParsedOptions("--priority", "16"); + void testInvalidPriority() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + getParsedOptions("--priority", "16"); + }); + assertTrue(exception.getMessage().contains("Invalid priority: 16")); } @Test - public void TestHighestPriority() { + void TestHighestPriority() { ClientParameters params = getParsedOptions("--priority", "HIGHEST"); assertEquals(DocumentProtocol.Priority.HIGHEST, params.priority); } @Test - public void TestHigh1PriorityAsNumber() { + void TestHigh1PriorityAsNumber() { ClientParameters params = getParsedOptions("--priority", "2"); assertEquals(DocumentProtocol.Priority.HIGH_1, params.priority); } @Test - public void testInvalidTraceLevel1() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Invalid tracelevel: -1"); - getParsedOptions("--trace", "-1"); + void testInvalidTraceLevel1() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + getParsedOptions("--trace", "-1"); + }); + assertTrue(exception.getMessage().contains("Invalid tracelevel: -1")); } @Test - public void testInvalidTraceLevel2() { - exception.expect(IllegalArgumentException.class); - exception.expectMessage("Invalid tracelevel: 10"); - getParsedOptions("--trace", "10"); + void testInvalidTraceLevel2() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + getParsedOptions("--trace", "10"); + }); + assertTrue(exception.getMessage().contains("Invalid tracelevel: 10")); } @Test - public void testPrintids() { + void testPrintids() { ClientParameters params = getParsedOptions("--printids"); assertEquals(DocIdOnly.NAME, params.fieldSet); } @Test - public void testCluster() { + void testCluster() { ClientParameters params = getParsedOptions("--cluster", "dummycluster"); assertEquals("dummycluster", params.cluster); assertTrue(params.route.isEmpty()); } @Test - public void testHelp() { + void testHelp() { ClientParameters params = getParsedOptions("--help"); assertTrue(params.help); } @Test - public void testDocumentIdsFromInputStream() throws UnsupportedEncodingException { + void testDocumentIdsFromInputStream() throws UnsupportedEncodingException { InputStream in = new ByteArrayInputStream("id:1 id:2 id:3".getBytes("UTF-8")); ClientParameters params = getParsedOptions(in, ""); @@ -175,7 +172,7 @@ public class CommandLineOptionsTest { } @Test - public void testPrintHelp() { + void testPrintHelp() { ByteArrayOutputStream outContent = new ByteArrayOutputStream(); PrintStream oldOut = System.out; System.setOut(new PrintStream(outContent)); |