package com.insightfullogic.java8.answers.chapter4;
import com.insightfullogic.java8.examples.chapter1.Artist;
import com.insightfullogic.java8.examples.chapter1.SampleData;
import com.insightfullogic.java8.answers.chapter4.PerformanceFixed;
import org.junit.Test;
import java.util.List;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.junit.Assert.assertThat;
public class PerformanceTest {
@Test
public void findsAllTheBeatles() {
com.insightfullogic.java8.answers.chapter4.PerformanceFixed stub = new PerformanceFixed() {
@Override
public String getName() {
throw new UnsupportedOperationException();
}
@Override
public Stream<Artist> getMusicians() {
return Stream.of(SampleData.theBeatles);
}
};
List<Artist> allMusicians = stub.getAllMusicians().collect(toList());
assertThat(allMusicians, hasItem(SampleData.theBeatles));
// There really must be a better way than this
assertThat(allMusicians, hasItems(SampleData.membersOfTheBeatles.toArray(new Artist[0])));
}
}