Package com.base2art.jeqll

Source Code of com.base2art.jeqll.PredicatedIterableTest

package com.base2art.jeqll;

import com.base2art.jeqll.sampleData.TestObjectRepository;
import com.base2art.jeqll.sampleData.TestObject;
import com.base2art.jeqll.impl.IterableQueryIterable;
import com.base2art.jeqll.matchers.EqualityMatcher;
import java.util.Iterator;
import static org.fest.assertions.Assertions.*;
import org.junit.Test;

public class PredicatedIterableTest
{

  @Test
  public void shouldGetSingleItemWhereOneMatch()
  {
    Iterable<TestObject> list = TestObjectRepository.createList(2);
    final EqualityMatcher matcher = new EqualityMatcher<>("index", 1);

    IterableQueryIterable<TestObject> iter = new IterableQueryIterable<TestObject>(list, matcher);
    final Iterator<TestObject> iterator = iter.iterator();
    assertThat(iterator.hasNext()).isEqualTo(true);
    TestObject testObject = iterator.next();
    assertThat(testObject).isNotNull();
    assertThat(testObject.getIndex()).isEqualTo(1);

    assertThat(iterator.hasNext()).isEqualTo(false);
  }


  @Test(expected=java.util.NoSuchElementException.class)
  public void shouldGetSingleItemWhereZeroMatch()
  {
    Iterable<TestObject> list = TestObjectRepository.createList(2);
    final EqualityMatcher matcher = new EqualityMatcher<>("index", 2);

    IterableQueryIterable<TestObject> iter = new IterableQueryIterable<TestObject>(list, matcher);
    final Iterator<TestObject> iterator = iter.iterator();
    assertThat(iterator.hasNext()).isEqualTo(false);
    iterator.next();
  }
}
TOP

Related Classes of com.base2art.jeqll.PredicatedIterableTest

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.