Package org.jtester.exception

Examples of org.jtester.exception.JTesterException


        Object bean = beanFactory.getBean(beanName);
        FieldHelper.setFieldValue(testedObject, field, bean);
      } catch (Throwable e) {
        String error = String.format("inject @SpringBeanByName field[%s] in class[%s] error.", field.getName(),
            testedClazz.getName());
        throw new JTesterException(error, e);
      }
    }
  }
View Full Code Here


        Object bean = getSpringBeanByType(beanFactory, field.getType());
        FieldHelper.setFieldValue(testedObject, field, bean);
      } catch (Throwable e) {
        String error = String.format("inject @SpringBeanByType field[%s] in class[%s] error.", field.getName(),
            testedClazz.getName());
        throw new JTesterException(error, e);
      }
    }
  }
View Full Code Here

   * @return The bean, not null
   */
  private Object getSpringBeanByType(JTesterBeanFactory beanFactory, Class type) {
    Map<String, ?> beans = beanFactory.getBeansOfType(type);
    if (beans == null || beans.size() == 0) {
      throw new JTesterException("Unable to get Spring bean by type. No Spring bean found for type "
          + type.getSimpleName());
    }
    if (beans.size() > 1) {
      throw new JTesterException(
          "Unable to get Spring bean by type. More than one possible Spring bean for type "
              + type.getSimpleName() + ". Possible beans; " + beans);
    }
    return beans.values().iterator().next();
  }
View Full Code Here

   */
  public static <T> Class<T> getClazz(String className) {
    try {
      return (Class<T>) Class.forName(className);
    } catch (Throwable t) {
      throw new JTesterException("Could not load class with name " + className, t);
    }
  }
View Full Code Here

  public static <T> T createInstanceOfType(String className) {
    try {
      Class type = Class.forName(className);
      return (T) newInstance(type);
    } catch (ClassCastException e) {
      throw new JTesterException("Class " + className + " is not of expected type.", e);
    } catch (NoClassDefFoundError e) {
      throw new JTesterException("Unable to load class " + className, e);
    } catch (ClassNotFoundException e) {
      throw new JTesterException("Class " + className + " not found", e);
    } catch (JTesterException e) {
      throw e;
    } catch (Throwable e) {
      throw new JTesterException("Error while instantiating class " + className, e);
    }
  }
View Full Code Here

      if (enumValueName.equalsIgnoreCase(enumValue.name())) {

        return enumValue;
      }
    }
    throw new JTesterException("Unable to find a enum value in enum: " + enumClass + ", with value name: "
        + enumValueName);
  }
View Full Code Here

    if (type instanceof ParameterizedType) {
      Type[] argumentTypes = ((ParameterizedType) type).getActualTypeArguments();
      if (argumentTypes.length == 1) {
        return argumentTypes[0];
      }
      throw new JTesterException("Unable to determine unique generic type for field: " + field
          + ". The field type declares more than one generic type: " + type);
    }
    throw new JTesterException("Unable to determine unique generic type for field: " + field
        + ". Field type is not a generic type: " + type);
  }
View Full Code Here

      return (Class<T>) type;
    }
    if (type instanceof ParameterizedType) {
      return (Class<T>) ((ParameterizedType) type).getRawType();
    }
    throw new JTesterException("Unable to convert Type instance " + type + " to a Class instance.");
  }
View Full Code Here

   * @return
   */
  public static <T> T newInstance(Class<T> claz) {

    if (claz.isMemberClass() && !isStatic(claz.getModifiers())) {
      throw new JTesterException(
          "Creation of an instance of a non-static innerclass is not possible using reflection. The type "
              + claz.getSimpleName()
              + " is only known in the context of an instance of the enclosing class "
              + claz.getEnclosingClass().getSimpleName()
              + ". Declare the innerclass as static to make construction possible.");
View Full Code Here

    try {
      ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename));
      out.writeObject(o);
      out.close();
    } catch (Throwable e) {
      throw new JTesterException(e);
    }
  }
View Full Code Here

TOP

Related Classes of org.jtester.exception.JTesterException

Copyright © 2018 www.massapicom. 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.