You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

URIParserTest.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.util;
  23. import org.junit.Test;
  24. public class URIParserTest {
  25. @Test(expected = InvalidURIException.class)
  26. public void testURINoScheme() throws InvalidURIException {
  27. final URIParser uriParser = new URIParser();
  28. uriParser.parseFromURI("irc.test.com");
  29. }
  30. @Test(expected = InvalidURIException.class)
  31. public void testURINoAuthority() throws InvalidURIException {
  32. final URIParser uriParser = new URIParser();
  33. uriParser.parseFromURI("irc://");
  34. }
  35. @Test(expected = InvalidURIException.class)
  36. public void testURIInvalidHostname() throws InvalidURIException {
  37. final URIParser uriParser = new URIParser();
  38. uriParser.parseFromURI("irc://irc_test.com");
  39. }
  40. @Test(expected = InvalidURIException.class)
  41. public void testURIInvalidUserInfo() throws InvalidURIException {
  42. final URIParser uriParser = new URIParser();
  43. uriParser.parseFromURI("ircs://:irc.test.com:6667");
  44. }
  45. @Test(expected = InvalidURIException.class)
  46. public void testURIEmptyPort() throws InvalidURIException {
  47. final URIParser uriParser = new URIParser();
  48. uriParser.parseFromURI("ircs://irc.test.com:");
  49. }
  50. @Test(expected = InvalidURIException.class)
  51. public void testURIInvalidPort() throws InvalidURIException {
  52. final URIParser uriParser = new URIParser();
  53. uriParser.parseFromURI("ircs://irc.test.com:-1");
  54. }
  55. @Test(expected = InvalidURIException.class)
  56. public void testURINotIntPort() throws InvalidURIException {
  57. final URIParser uriParser = new URIParser();
  58. uriParser.parseFromURI("ircs://irc.test.com:999999999999");
  59. }
  60. @Test(expected = InvalidURIException.class)
  61. public void testURIPortOutOfRange() throws InvalidURIException {
  62. final URIParser uriParser = new URIParser();
  63. uriParser.parseFromURI("ircs://irc.test.com:65536");
  64. }
  65. @Test(expected = InvalidURIException.class)
  66. public void testTextInvalidHostname() throws InvalidURIException {
  67. final URIParser uriParser = new URIParser();
  68. uriParser.parseFromText("irc_test.com");
  69. }
  70. @Test(expected = InvalidURIException.class)
  71. public void testTextEmptyPort() throws InvalidURIException {
  72. final URIParser uriParser = new URIParser();
  73. uriParser.parseFromText("irc.test.com:");
  74. }
  75. @Test(expected = InvalidURIException.class)
  76. public void testTextInvalidPort() throws InvalidURIException {
  77. final URIParser uriParser = new URIParser();
  78. uriParser.parseFromText("irc.test.com:-1");
  79. }
  80. @Test(expected = InvalidURIException.class)
  81. public void testTextNotIntPort() throws InvalidURIException {
  82. final URIParser uriParser = new URIParser();
  83. uriParser.parseFromText("irc.test.com:999999999999");
  84. }
  85. @Test(expected = InvalidURIException.class)
  86. public void testTextPortOutOfRange() throws InvalidURIException {
  87. final URIParser uriParser = new URIParser();
  88. uriParser.parseFromText("irc.test.com:65536");
  89. }
  90. }