aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-channel/src/test/java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-06-28 08:42:53 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-06-28 08:43:11 +0200
commit4e1655566e26035164f644b0a933e7c0e7891436 (patch)
tree7229e1f543abd0a76be2f2b34e313f6adfea760d /sonar-channel/src/test/java
parent595485bb2bf8b327cb50e24597894d97d28c178d (diff)
downloadsonarqube-4e1655566e26035164f644b0a933e7c0e7891436.tar.gz
sonarqube-4e1655566e26035164f644b0a933e7c0e7891436.zip
Add method ChannelDispatcher.Builder#addChannels(Channel...) + minor fixes
Diffstat (limited to 'sonar-channel/src/test/java')
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java18
-rw-r--r--sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java6
2 files changed, 19 insertions, 5 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
index 030d82feb70..f24761e8045 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/ChannelDispatcherTest.java
@@ -34,14 +34,21 @@ public class ChannelDispatcherTest {
assertThat(output.toString(), is("twowords"));
}
+ @Test
+ public void shouldAddChannels() {
+ ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().addChannels(new SpaceDeletionChannel(), new FakeChannel()).build();
+ assertThat(dispatcher.getChannels().length, is(2));
+ assertThat(dispatcher.getChannels()[0], is(SpaceDeletionChannel.class));
+ assertThat(dispatcher.getChannels()[1], is(FakeChannel.class));
+ }
+
@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> {
-
+ private static class SpaceDeletionChannel extends Channel<StringBuilder> {
@Override
public boolean consume(CodeReader code, StringBuilder output) {
if (code.peek() == ' ') {
@@ -51,6 +58,13 @@ public class ChannelDispatcherTest {
}
return true;
}
+ }
+ private static class FakeChannel extends Channel<StringBuilder> {
+ @Override
+ public boolean consume(CodeReader code, StringBuilder output) {
+ return true;
+ }
}
+
}
diff --git a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
index 7fb5c3a11ab..35d9c936b78 100644
--- a/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
+++ b/sonar-channel/src/test/java/org/sonar/channel/RegexChannelTest.java
@@ -28,13 +28,13 @@ public class RegexChannelTest {
@Test
public void shouldMatch() {
- ChannelDispatcher<StringBuilder> dispatcher = new ChannelDispatcher<StringBuilder>(new MyWordChannel(), new BlackholeChannel());
+ ChannelDispatcher<StringBuilder> dispatcher = ChannelDispatcher.builder().addChannel(new MyWordChannel()).addChannel(new BlackholeChannel()).build();
StringBuilder output = new StringBuilder();
dispatcher.consume(new CodeReader("my word"), output);
assertThat(output.toString(), is("<w>my</w> <w>word</w>"));
}
- private class MyWordChannel extends RegexChannel<StringBuilder> {
+ private static class MyWordChannel extends RegexChannel<StringBuilder> {
public MyWordChannel() {
super("\\w++");
@@ -46,7 +46,7 @@ public class RegexChannelTest {
}
}
- class BlackholeChannel extends Channel<StringBuilder> {
+ private static class BlackholeChannel extends Channel<StringBuilder> {
@Override
public boolean consume(CodeReader code, StringBuilder output) {