Package br.com.objectos.way.relational

Source Code of br.com.objectos.way.relational.TesteDeIteradorDeEntidade$FakeQueryExec

/*
* Copyright 2011 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.way.relational;

import static com.google.common.collect.Lists.newArrayList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

import java.util.Iterator;
import java.util.List;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import br.com.objectos.way.relational.EntityIteratorGen;
import br.com.objectos.way.relational.EntityIteratorGenGuice;
import br.com.objectos.way.relational.DeprecatedQueryExec;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
@Test
public class TesteDeIteradorDeEntidade {

  private EntityIteratorGen gen;

  private Asserts asserts;
  private List<String> itens;

  @BeforeClass
  public void setUp() {
    DeprecatedQueryExec exec = new FakeQueryExec();
    gen = new EntityIteratorGenGuice(exec);
  }

  @BeforeMethod
  public void reset() {
    asserts = new Asserts();
    itens = newArrayList();
  }

  public void genShouldDelegateToExecWithCorrectParameters() {
    Class<String> entityClass = String.class;
    Iterator<String> it = gen.iteratorFor(entityClass);

    assertThat(it, is(notNullValue()));
    assertThat(it.hasNext(), is(false));
    assertThat(asserts.entityClass, equalTo(entityClass));
    assertThat(asserts.page.getFirstIndex(), equalTo(0));
    assertThat(asserts.page.getLength(), equalTo(50));
  }

  private class Asserts {
    Class<String> entityClass;
    Page page;
  }

  private class FakeQueryExec extends EmptyQueryExec {
    @SuppressWarnings("unchecked")
    @Override
    public <E> List<E> listPage(Class<?> entityClass, Page page) {
      asserts.entityClass = (Class<String>) entityClass;
      asserts.page = page;
      return (List<E>) itens;
    }
  }

}
TOP

Related Classes of br.com.objectos.way.relational.TesteDeIteradorDeEntidade$FakeQueryExec

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.