// Path: src/main/java/com/xemantic/ankh/shared/event/Sink.java
// public interface Sink<T> {
// 
//   void publish(T event);
// 
//   /**
//    * Exposes an {@link Observer} as a {@link Sink}.
//    *
//    * @param observer the observer.
//    * @param <T> the event type.
//    * @return the event sink.
//    */
//   static  <T> Sink<T> of(Observer<T> observer) {
//     Objects.requireNonNull(observer, "observer cannot be null");
//     return observer::onNext;
//   }
// 
// }
// 
// Path: src/main/java/com/xemantic/ankh/shared/event/Trigger.java
// public final class Trigger {
// 
//   public static final Trigger INSTANCE = new Trigger();
// 
//   private Trigger() { /* no instantiation */ }
// 
//   public static void fire(Observer<Trigger> observer) {
//     (Objects.requireNonNull(observer)).onNext(Trigger.INSTANCE);
//   }
// 
//   public static Observable<Trigger> noTriggers() {
//     return Observable.empty();
//   }
// 
//   /**
//    * Creates {@link Observable} emitting only one {@link Trigger} instance on
//    * creation. For subsequent subscribers it behaves like {@link Observable#empty()}.
//    *
//    * @return the one time firing Observable.
//    */
//   public static Observable<Trigger> oneTime() {
//     AtomicBoolean firstTime = new AtomicBoolean(true);
//     return Observable.create(e -> {
//       if (firstTime.get()) {
//         firstTime.set(false);
//         e.onNext(Trigger.INSTANCE);
//       }
//     });
//   }
// 
// }
// 
// Path: src/main/java/com/xemantic/githubusers/logic/event/UserSelectedEvent.java
// @Event
// public class UserSelectedEvent {
// 
//   private final User user;
// 
//   public UserSelectedEvent(User user) {
//     this.user = Objects.requireNonNull(user);
//   }
// 
//   public User getUser() {
//     return user;
//   }
// 
// }
// 
// Path: src/main/java/com/xemantic/githubusers/logic/model/User.java
// public interface User {
// 
//   String getLogin();
// 
//   String getAvatarUrl();
// 
//   String getHtmlUrl();
// 
// }
// 
// Path: src/main/java/com/xemantic/ankh/shared/event/Trigger.java
// public static void fire(Observer<Trigger> observer) {
//   (Objects.requireNonNull(observer)).onNext(Trigger.INSTANCE);
// }
// 
// Path: src/main/java/com/xemantic/ankh/shared/event/Trigger.java
// public static Observable<Trigger> noTriggers() {
//   return Observable.empty();
// }


import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import static com.xemantic.ankh.shared.event.Trigger.fire;
import static com.xemantic.ankh.shared.event.Trigger.noTriggers;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import com.xemantic.ankh.shared.event.Sink;
import com.xemantic.ankh.shared.event.Trigger;
import com.xemantic.githubusers.logic.event.UserSelectedEvent;
import com.xemantic.githubusers.logic.model.User;
import io.reactivex.observers.TestObserver;
import io.reactivex.subjects.PublishSubject;
import org.junit.Rule;
import org.junit.Test;
/*
 * github-users - lists GitHub users. Minimal app demonstrating
 * cross-platform app development (Web, Android, iOS) where core
 * logic is shared and transpiled from Java to JavaScript and
 * Objective-C. This project delivers core application logic.
 *
 * Copyright (C) 2017  Kazimierz Pogoda
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.xemantic.githubusers.logic.user;



/**
 * Test of the {@link UserPresenter}.
 *
 * @author morisil
 */
public class UserPresenterTest {

  @Rule
  public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);

  @Mock
  private UserView view;

  @Test
  public void start_user_shouldDisplayUser() {
    // given
    TestObserver<UserSelectedEvent> userSelected$ = TestObserver.create();
    User user = mock(User.class);
    given(view.userSelection$()).willReturn(noTriggers());
    UserPresenter presenter = new UserPresenter(view, Sink.of(userSelected$), user);

    // when
    presenter.start();

    // then
    then(view).should().displayUser(user);
    then(view).should().userSelection$();
// Path: src/main/java/com/xemantic/ankh/shared/event/Sink.java
// public interface Sink<T> {
// 
//   void publish(T event);
// 
//   /**
//    * Exposes an {@link Observer} as a {@link Sink}.
//    *
//    * @param observer the observer.
//    * @param <T> the event type.
//    * @return the event sink.
//    */
//   static  <T> Sink<T> of(Observer<T> observer) {
//     Objects.requireNonNull(observer, "observer cannot be null");
//     return observer::onNext;
//   }
// 
// }
// 
// Path: src/main/java/com/xemantic/ankh/shared/event/Trigger.java
// public final class Trigger {
// 
//   public static final Trigger INSTANCE = new Trigger();
// 
//   private Trigger() { /* no instantiation */ }
// 
//   public static void fire(Observer<Trigger> observer) {
//     (Objects.requireNonNull(observer)).onNext(Trigger.INSTANCE);
//   }
// 
//   public static Observable<Trigger> noTriggers() {
//     return Observable.empty();
//   }
// 
//   /**
//    * Creates {@link Observable} emitting only one {@link Trigger} instance on
//    * creation. For subsequent subscribers it behaves like {@link Observable#empty()}.
//    *
//    * @return the one time firing Observable.
//    */
//   public static Observable<Trigger> oneTime() {
//     AtomicBoolean firstTime = new AtomicBoolean(true);
//     return Observable.create(e -> {
//       if (firstTime.get()) {
//         firstTime.set(false);
//         e.onNext(Trigger.INSTANCE);
//       }
//     });
//   }
// 
// }
// 
// Path: src/main/java/com/xemantic/githubusers/logic/event/UserSelectedEvent.java
// @Event
// public class UserSelectedEvent {
// 
//   private final User user;
// 
//   public UserSelectedEvent(User user) {
//     this.user = Objects.requireNonNull(user);
//   }
// 
//   public User getUser() {
//     return user;
//   }
// 
// }
// 
// Path: src/main/java/com/xemantic/githubusers/logic/model/User.java
// public interface User {
// 
//   String getLogin();
// 
//   String getAvatarUrl();
// 
//   String getHtmlUrl();
// 
// }
// 
// Path: src/main/java/com/xemantic/ankh/shared/event/Trigger.java
// public static void fire(Observer<Trigger> observer) {
//   (Objects.requireNonNull(observer)).onNext(Trigger.INSTANCE);
// }
// 
// Path: src/main/java/com/xemantic/ankh/shared/event/Trigger.java
// public static Observable<Trigger> noTriggers() {
//   return Observable.empty();
// }


// Path: src/test/java/com/xemantic/githubusers/logic/user/UserPresenterTest.java
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import static com.xemantic.ankh.shared.event.Trigger.fire;
import static com.xemantic.ankh.shared.event.Trigger.noTriggers;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import com.xemantic.ankh.shared.event.Sink;
import com.xemantic.ankh.shared.event.Trigger;
import com.xemantic.githubusers.logic.event.UserSelectedEvent;
import com.xemantic.githubusers.logic.model.User;
import io.reactivex.observers.TestObserver;
import io.reactivex.subjects.PublishSubject;
import org.junit.Rule;
import org.junit.Test;

/*
 * github-users - lists GitHub users. Minimal app demonstrating
 * cross-platform app development (Web, Android, iOS) where core
 * logic is shared and transpiled from Java to JavaScript and
 * Objective-C. This project delivers core application logic.
 *
 * Copyright (C) 2017  Kazimierz Pogoda
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.xemantic.githubusers.logic.user;



/**
 * Test of the {@link UserPresenter}.
 *
 * @author morisil
 */
public class UserPresenterTest {

  @Rule
  public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);

  @Mock
  private UserView view;

  @Test
  public void start_user_shouldDisplayUser() {
    // given
    TestObserver<UserSelectedEvent> userSelected$ = TestObserver.create();
    User user = mock(User.class);
    given(view.userSelection$()).willReturn(noTriggers());
    UserPresenter presenter = new UserPresenter(view, Sink.of(userSelected$), user);

    // when
    presenter.start();

    // then
    then(view).should().displayUser(user);
    then(view).should().userSelection$();
    then(view).shouldHaveNoMoreInteractions();