aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-channel/src/test/java
diff options
context:
space:
mode:
authorFreddy Mallet <freddy.mallet@gmail.com>2011-05-24 16:15:25 +0200
committerFreddy Mallet <freddy.mallet@gmail.com>2011-05-24 16:15:25 +0200
commitb6d05fa45566092791e0b2bdc16ed0312d93c613 (patch)
tree1de82f1eb18b314097c7505d76b207eeb31104a7 /sonar-channel/src/test/java
parentd1db9357b84d57dfa61d3c40a48915d24c50ee12 (diff)
downloadsonarqube-b6d05fa45566092791e0b2bdc16ed0312d93c613.tar.gz
sonarqube-b6d05fa45566092791e0b2bdc16ed0312d93c613.zip
Provide a builder to the ChannelDispatcher class and depreciate all constructors
Diffstat (limited to 'sonar-channel/src/test/java')
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
new file mode 100644
index 00000000000..030d82feb70
--- /dev/null
+++ b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
@@ -0,0 +1,56 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.channel;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ChannelDispatcherTest {
+
+ @Test
+ public void shouldRemoveSpacesFromString() {
+ ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().addChannel(new SpaceDeletionChannel()).build();
+ StringBuilder output = new StringBuilder();
+ dispatcher.consume(new CodeReader("two words"), output);
+ assertThat(output.toString(), is("twowords"));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldThrowExceptionWhenNoChannelToConsumeNextCharacter() {
+ ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().failIfNoChannelToConsumeOneCharacter().build();
+ dispatcher.consume(new CodeReader("two words"), new StringBuilder());
+ }
+
+ private class SpaceDeletionChannel extends Channel<StringBuilder> {
+
+ @Override
+ public boolean consume(CodeReader code, StringBuilder output) {
+ if (code.peek() == ' ') {
+ code.pop();
+ } else {
+ output.append((char) code.pop());
+ }
+ return true;
+ }
+
+ }
+}