title: How focused JUnit tests in BDD way should be
body: <p>I'm test-driving some code  for practice and spotted strange situation.</p>
  
  <p>There is a ChannelRegistry that contains all communication channels references, and PrimaryConsumer who needs to attach itself to one of those channels choosen in runtime when initialize() called.
  So I've done my first test as follows:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class PrimaryConsumerTest {
  
      private @Mock ChannelsRegistry communicationRegistry;
      private PrimaryConsumer consumer;
  
      @Before
      public void setup() {
          consumer = new PrimaryConsumer(communicationRegistry);
      }
  
      @Test
      public void shouldAttachToChannel() throws Exception {
          consumer.initialize();
          verify(communicationRegistry).attachToChannel("channel", consumer);
      }
  } 
  </code></pre>
  
  <p>I'm checking if attaching method is called. To get it green I put impl like that:</p>
  
  <pre><code>public void initialize() {
      communicationRegistry.attachToChannel("channel", this);
  }
  </code></pre>
  
  <p>Now next test: get channel id by name and attach to this specific channel. I want my test to describe class' behavior instead of its internals so I don't want my test to be "shouldGetSpecificChannel". Instead I check if it can attach to channel selected in runtime:</p>
  
  <pre><code>    @Test
      public void shouldAttachToSpecificChannel() throws Exception {
          String channelName = "channel";
          when(communicationRegistry.getChannel("channel_name")).thenReturn(channelName);
          consumer.initialize();
          verify(communicationRegistry).attachToChannel(channelName, consumer);
      }
  </code></pre>
  
  <p>This test passes immediately, but implementation is screwed ("channel" hardcoded).</p>
  
  <p>2 questions here:</p>
  
  <ul>
  <li><p>is it ok to have 2 tests for such behavior? Maybe I should stub getting channel immediately in first test? If so, how does it map to testing single thing in single test?</p></li>
  <li><p>how to cope with such situation: tests green, impl "hardcoded"? Should I write another test with different channel's name? If so, should I remove it after correcting impl (as it gets useless?)</p></li>
  </ul>
  
  <p><strong>UPDATE:</strong>
  Just some clarifications.
  I've hardcoded "channel" here</p>
  
  <pre><code>public void initialize() {
      communicationRegistry.attachToChannel("channel", this);
  }
  </code></pre>
  
  <p>just to make first test pass quickly. But then, when running second test it passes immediately. I don't verify if stubbed method was called as I think stubs should not be verified explicitly. 
  Is this what you Rodney mean saying test are redundant? If yes shoud I make stub at the very beginning in the first test?</p>