From 4e1655566e26035164f644b0a933e7c0e7891436 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 28 Jun 2011 08:42:53 +0200 Subject: Add method ChannelDispatcher.Builder#addChannels(Channel...) + minor fixes --- .../java/org/sonar/channel/ChannelDispatcherTest.java | 18 ++++++++++++++++-- .../test/java/org/sonar/channel/RegexChannelTest.java | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'sonar-channel/src/test') 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 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 dispatcher = ChannelDispatcher.builder().failIfNoChannelToConsumeOneCharacter().build(); dispatcher.consume(new CodeReader("two words"), new StringBuilder()); } - private class SpaceDeletionChannel extends Channel { - + private static class SpaceDeletionChannel extends Channel { @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 { + @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 dispatcher = new ChannelDispatcher(new MyWordChannel(), new BlackholeChannel()); + ChannelDispatcher 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("my word")); } - private class MyWordChannel extends RegexChannel { + private static class MyWordChannel extends RegexChannel { public MyWordChannel() { super("\\w++"); @@ -46,7 +46,7 @@ public class RegexChannelTest { } } - class BlackholeChannel extends Channel { + private static class BlackholeChannel extends Channel { @Override public boolean consume(CodeReader code, StringBuilder output) { -- cgit v1.2.3