/*
 * Copyright 2012-2016 JetBrains s.r.o
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jetbrains.jetpad.model.event;

import com.google.common.base.Function;
import jetbrains.jetpad.test.BaseTestCase;
import org.junit.Assert;
import org.junit.Test;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class EventSourceTest extends BaseTestCase {
  private final EventSource<String> letters = EventSources.of("a", "b", "c", "d", "e");


  @Test
  public void map() {
    assertEvents(Arrays.asList("A", "B", "C", "D", "E"),
      EventSources.map(letters, new Function<String, String>() {
        @Override
        public String apply(String input) {
          return input.toUpperCase();
        }
      }));
  }

  private void assertEvents(List<String> events, EventSource<String> es) {
    LoggingEventHandler<String> handler = new LoggingEventHandler<>();
    es.addHandler(handler);

    assertEquals(events, handler.getEvents());
  }

}

@@ -674,16 +674,57 @@
 nction;%0A
+import com.google.common.base.Predicate;%0A
 import j
@@ -779,73 +779,14 @@
 nit.
-Assert;%0Aimport org.junit.Test;%0A%0Aimport javax.annotation.Nullable;
+Test;%0A
 %0Aimp
@@ -1297,16 +1297,286 @@
 );%0A  %7D%0A%0A
+  @Test%0A  public void filter() %7B%0A    assertEvents(Arrays.asList(%22a%22, %22e%22),%0A      EventSources.filter(letters, new Predicate%3CString%3E() %7B%0A        @Override%0A        public boolean apply(String s) %7B%0A          return %22a%22.equals(s) %7C%7C %22e%22.equals(s);%0A        %7D%0A      %7D));%0A  %7D%0A%0A
   privat

work on event sources