All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.core.testing.IsTestable Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015 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.core.testing;

import java.util.List;
import java.util.Optional;

import br.com.objectos.code.InterfaceInfo;
import br.com.objectos.code.ModifierInfo;
import br.com.objectos.code.SimpleTypeInfo;
import br.com.objectos.code.TypeParameterInfo;
import br.com.objectos.pojo.plugin.Naming;
import br.com.objectos.pojo.plugin.PojoInfo;
import br.com.objectos.pojo.plugin.Property;

import com.squareup.javapoet.MethodSpec;

/**
 * @author [email protected] (Marcio Endo)
 */
interface IsTestable {

  static IsTestable of(PojoInfo pojoInfo) {
    Naming naming = pojoInfo.naming();
    IsTestableBox box = new IsTestableBox();
    Optional maybeTestable = pojoInfo.getInterface(Testable.class);
    return maybeTestable
        .flatMap(testable -> {
          return pojoInfo.methodInfoStream()
              .filter(m -> m.hasName("isEqual"))
              .filter(m -> !m.hasModifierInfo(ModifierInfo.ABSTRACT))
              .findFirst()
              .map(method -> Optional. empty())
              .orElse(testable.typeParameterInfoStream()
                  .map(TypeParameterInfo::simpleTypeInfo)
                  .findFirst());

        })
        .map(box::set)
        . map(testableOf -> {
          return box.sameType(pojoInfo)
              ? new SimpleTestable(naming, testableOf)
              : new InheritedTestable(naming, testableOf);
        })
        .orElse(NotTestable.INSTANCE);
  }

  Optional get(List propertyList);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy