Skip to content

Commit

Permalink
on passing and failing tests, update observer from junit subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hermida committed Apr 2, 2011
1 parent 10faf0c commit 2a21a08
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/com/happyprog/tdgotchi/controller/JUnitTestSubscriber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.happyprog.tdgotchi.controller;

public class JUnitTestSubscriber implements TestSubscriber {

private TestObserver observer;

@Override
public void subscribe(TestObserver observer) {
this.observer = observer;
}

public void onPassingTest() {
observer.onPassingTest();
}

public void onFailingTest() {
observer.onFailingTest();
}

}
2 changes: 1 addition & 1 deletion src/com/happyprog/tdgotchi/controller/TestSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface TestSubscriber {

void subscribe(TestObserver controller);
void subscribe(TestObserver observer);

}
2 changes: 1 addition & 1 deletion test/com/happyprog/tdgotchi/controller/ControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void before() {
}

@Test
public void subscribesToJUnitEvents() throws Exception {
public void subscribesToTestEvents() throws Exception {
verify(subscriber).subscribe(controller);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.happyprog.tdgotchi.controller;

import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;

public class JUnitTestSubscriberTest {

private TestObserver observer;
private JUnitTestSubscriber subscriber;

@Before
public void before() {
observer = mock(TestObserver.class);
subscriber = new JUnitTestSubscriber();

subscriber.subscribe(observer);
}

@Test
public void onPassingTest_updateObserver() throws Exception {
subscriber.onPassingTest();

verify(observer).onPassingTest();
}

@Test
public void onFailingTest_updateObserver() throws Exception {
subscriber.onFailingTest();

verify(observer).onFailingTest();
}
}

0 comments on commit 2a21a08

Please sign in to comment.