// 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/githubusers/logic/event/UserQueryEvent.java
// @Event
// public class UserQueryEvent {
// 
//   private final String query;
// 
//   public UserQueryEvent(String query) {
//     this.query = Objects.requireNonNull(query);
//   }
// 
//   public String getQuery() {
//     return query;
//   }
// 
// }


import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import com.xemantic.ankh.shared.event.Sink;
import com.xemantic.githubusers.logic.event.UserQueryEvent;
import io.reactivex.Observable;
import io.reactivex.observers.TestObserver;
import io.reactivex.subjects.PublishSubject;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
/*
 * 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 UserQueryPresenter}.
 *
 * @author morisil
 */
public class UserQueryPresenterTest {

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

  @Mock
  private UserQueryView view;

  @Test
  public void start_shouldOnlyBindToView() {
    // given
    TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
    given(view.queryInput$()).willReturn(Observable.empty());
    UserQueryPresenter presenter = new UserQueryPresenter(view, Sink.of(userQuery$));

    // when
    presenter.start();

    // then
    verify(view).queryInput$();
    verifyNoMoreInteractions(view);
    userQuery$.assertNoValues();
  }

  @Test
  public void onUserQuery_queryString_shouldPostEventWithQueryString() {
    // given
    TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
    PublishSubject<String> userQueryIntent = PublishSubject.create();
    given(view.queryInput$()).willReturn(userQueryIntent);
// 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/githubusers/logic/event/UserQueryEvent.java
// @Event
// public class UserQueryEvent {
// 
//   private final String query;
// 
//   public UserQueryEvent(String query) {
//     this.query = Objects.requireNonNull(query);
//   }
// 
//   public String getQuery() {
//     return query;
//   }
// 
// }


// Path: src/test/java/com/xemantic/githubusers/logic/user/UserQueryPresenterTest.java
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import com.xemantic.ankh.shared.event.Sink;
import com.xemantic.githubusers.logic.event.UserQueryEvent;
import io.reactivex.Observable;
import io.reactivex.observers.TestObserver;
import io.reactivex.subjects.PublishSubject;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;

/*
 * 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 UserQueryPresenter}.
 *
 * @author morisil
 */
public class UserQueryPresenterTest {

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

  @Mock
  private UserQueryView view;

  @Test
  public void start_shouldOnlyBindToView() {
    // given
    TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
    given(view.queryInput$()).willReturn(Observable.empty());
    UserQueryPresenter presenter = new UserQueryPresenter(view, Sink.of(userQuery$));

    // when
    presenter.start();

    // then
    verify(view).queryInput$();
    verifyNoMoreInteractions(view);
    userQuery$.assertNoValues();
  }

  @Test
  public void onUserQuery_queryString_shouldPostEventWithQueryString() {
    // given
    TestObserver<UserQueryEvent> userQuery$ = TestObserver.create();
    PublishSubject<String> userQueryIntent = PublishSubject.create();
    given(view.queryInput$()).willReturn(userQueryIntent);
    UserQueryPresenter presenter = new UserQueryPresenter(view, Sink.of(userQuery$));