Package com.happyprog.tdgotchi.subscriber

Source Code of com.happyprog.tdgotchi.subscriber.JUnitTestSubscriber

package com.happyprog.tdgotchi.subscriber;

import org.eclipse.jdt.junit.JUnitCore;
import org.eclipse.jdt.junit.TestRunListener;
import org.eclipse.jdt.junit.model.ITestElement;
import org.eclipse.jdt.junit.model.ITestElement.Result;
import org.eclipse.jdt.junit.model.ITestRunSession;

import com.happyprog.tdgotchi.scoreboard.TestObserver;

public class JUnitTestSubscriber extends TestRunListener implements TestSubscriber {

  private TestObserver observer;

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

  void addAsTestListener() {
    JUnitCore.addTestRunListener(this);
  }

  @Override
  public void sessionFinished(ITestRunSession session) {
    Result testResult = session.getTestResult(true);
    if (testResult.equals(ITestElement.Result.OK)) {
      observer.onPassingTest();
    } else {
      observer.onFailingTest();
    }
  }

}
TOP

Related Classes of com.happyprog.tdgotchi.subscriber.JUnitTestSubscriber

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.