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.

IRCParserTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.parser;
  23. import com.dmdirc.parser.callbacks.CallbackNotFoundException;
  24. import com.dmdirc.parser.callbacks.interfaces.IAwayState;
  25. import org.junit.Test;
  26. import static org.junit.Assert.*;
  27. public class IRCParserTest {
  28. @Test
  29. public void testIssue042() {
  30. boolean res = false;
  31. try {
  32. final IRCParser myParser = new IRCParser();
  33. myParser.getCallbackManager().addCallback("non-existant",new IAwayState() {
  34. public void onAwayState(IRCParser tParser, boolean currentState, String reason) {
  35. throw new UnsupportedOperationException("Not supported yet.");
  36. }
  37. });
  38. } catch (CallbackNotFoundException ex) {
  39. res = true;
  40. }
  41. assertTrue("addCallback() should throw exception for non-existant callbacks", res);
  42. }
  43. @Test
  44. public void testTokeniser() {
  45. final IRCParser myParser = new IRCParser();
  46. final String line1 = "a b c d e";
  47. final String line2 = "a b c :d e";
  48. final String line3 = ":a b:c :d e";
  49. final String[] res1 = myParser.tokeniseLine(line1);
  50. final String[] res2 = myParser.tokeniseLine(line2);
  51. final String[] res3 = myParser.tokeniseLine(line3);
  52. arrayEquals(res1, new String[]{"a", "b", "c", "d", "e"});
  53. arrayEquals(res2, new String[]{"a", "b", "c", "d e"});
  54. arrayEquals(res3, new String[]{":a", "b:c", "d e"});
  55. }
  56. private void arrayEquals(final String[] a1, final String[] a2) {
  57. assertEquals(a1.length, a2.length);
  58. for (int i = 0; i < a1.length; i++) {
  59. assertEquals(a1[i], a2[i]);
  60. }
  61. }
  62. }