Package ch.powerunit.exception

Examples of ch.powerunit.exception.InternalError


      try {
        method.invoke(target);
      } catch (InvocationTargetException e) {
        throw e.getCause();
      } catch (IllegalAccessException | IllegalArgumentException e) {
        throw new InternalError("Unexpected error " + e.getMessage(), e);
      }
    };
  }
View Full Code Here


import ch.powerunit.exception.InternalError;

public interface RuleValidator {
  default void checkRuleAnnotationForField(Field f) {
    if (Modifier.isStatic(f.getModifiers())) {
      throw new InternalError("@Rule field is static " + f.toString());
    }
    if (!Modifier.isPublic(f.getModifiers())) {
      throw new InternalError("@Rule field is not public " + f.toString());
    }
    if (!Modifier.isFinal(f.getModifiers())) {
      throw new InternalError("@Rule field is not final " + f.toString());
    }
    if (!TestRule.class.isAssignableFrom(f.getType())) {
      throw new InternalError("@Rule field is not TestRule "
          + f.toString());
    }
  }
View Full Code Here

import ch.powerunit.exception.InternalError;

public interface ParametersValidator {
  default void checkParametersAnnotationForMethod(Method m) {
    if (!Modifier.isStatic(m.getModifiers())) {
      throw new InternalError("@Parameters method is not static "
          + m.toString());
    }
    if (!Modifier.isPublic(m.getModifiers())) {
      throw new InternalError("@Parameters method is not public "
          + m.toString());
    }
    if (!Stream.class.isAssignableFrom(m.getReturnType())) {
      throw new InternalError("@Parameters method is not Stream<...> "
          + m.toString());
    }
    if (m.getParameterCount() != 0) {
      throw new InternalError("@Parameters method is not 0-parameter "
          + m.toString());
    }
  }
View Full Code Here

        : Arrays.toString(groups.toArray());

    try {
      targetObject = testClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
      throw new InternalError("Unexpected error " + e.getMessage(), e);
    }

    if (testClass.isAnnotationPresent(Ignore.class)) {
      executableTests.put(setName, p -> {
        TestContextImpl<Object> ctx = new TestContextImpl<>(
View Full Code Here

    testIndex = 0;
    try (Stream<?> params = (Stream<?>) parameters.invoke(targetObject)) {
      params.forEach(this::runOneParameter);
    } catch (IllegalAccessException | IllegalArgumentException
        | InvocationTargetException e) {
      throw new InternalError("Unexpected error " + e.getMessage(), e);
    }
  }
View Full Code Here

    String name = MessageFormat.format(formatter, o);
    try {
      notifyStartParameter(setName, name);
      int pidx = 0;
      if (o.length != parameterFields.size()) {
        throw new InternalError(
            "Parameter fields count doesn't match with array size returned by parameters");
      }
      for (Object p : o) {
        try {
          Field f = parameterFields.get(pidx);
          if (f == null) {
            throw new InternalError("Field " + pidx
                + " is not found");
          }
          f.set(targetObject, p);
        } catch (IllegalArgumentException | IllegalAccessException e) {
          throw new InternalError("Unexpected error "
              + e.getMessage(), e);
        }
        pidx++;
      }
      runOne(name);
View Full Code Here

                new TestContextImpl<Object>(targetObject,
                    setName, singleTest.getKey(), name,
                    parentGroups));
          } catch (Throwable e) {// NOSONAR
            // As we really want all error
            throw new InternalError("Unexpected error "
                + e.getMessage(), e);
          }
        });
  }
View Full Code Here

    parameters = Arrays
        .stream(testClass.getDeclaredMethods())
        .filter(m -> m.isAnnotationPresent(Parameters.class))
        .peek(m -> checkParametersAnnotationForMethod(m))
        .reduce((o, n) -> {
          throw new InternalError(
              "@Parameters method can't only be once");
        }).orElse(null);
    parameterFields = Arrays
        .stream(testClass.getDeclaredFields())
        .filter(f -> f.isAnnotationPresent(Parameter.class))
        .peek(f -> {
          if (parameters == null) {
            throw new InternalError(
                "@Parameter can't be used without @Parameters method");
          }
        })
        .peek(f -> checkParameterAnnotationForField(f))
        .collect(
            Collectors
                .<Field, Integer, Field> toMap(
                    (Field f) -> f.getAnnotation(
                        Parameter.class).value(),
                    (Field f) -> f,
                    (f1, f2) -> {
                      throw new InternalError(
                          "@Parameter can't be used twice with the same value number");
                    }));
    if (parameters != null) {
      // assuming field numbering 0 to
      int size = parameterFields.size();
      if (size == 0) {
        throw new InternalError("No @Parameter field found");
      }
      int expected = (size * (size - 1)) / 2;
      int sum = parameterFields.keySet().stream().mapToInt(i -> i).sum();
      if (sum != expected) {
        throw new InternalError(
            "@Parameter field number aren't continuus");
      }
    }
  }
View Full Code Here

            .map(f -> {
              checkRuleAnnotationForField(f);
              try {
                TestRule tr1 = (TestRule) f.get(targetObject);
                if (tr1 == null) {
                  throw new InternalError(
                      "@Rule annotation is used on a null field. This is not allowed");
                }
                return tr1;
              } catch (IllegalAccessException
                  | IllegalArgumentException e) {
                throw new InternalError("Unexpected error "
                    + e.getMessage(), e);
              }
            })
            .reduce((o, n) -> {
              throw new InternalError(
                  "@Rule annotation can only be used once on field");
            }).orElse(null)).filter(i -> i != null)
        .reduce((o, n) -> o.around(n)).orElse(null);

  }
View Full Code Here

import ch.powerunit.exception.InternalError;

public interface TestValidator {
  default void checkTestAnnotationForMethod(Method m) {
    if (Modifier.isStatic(m.getModifiers())) {
      throw new InternalError("@Test method is static " + m.toString());
    }
    if (!Modifier.isPublic(m.getModifiers())) {
      throw new InternalError("@Test method is not public "
          + m.toString());
    }
    if (!Void.TYPE.equals(m.getReturnType())) {
      throw new InternalError("@Test method is not void " + m.toString());
    }
    if (m.getParameterCount() != 0) {
      throw new InternalError("@Test method is not 0-parameter "
          + m.toString());
    }
  }
View Full Code Here

TOP

Related Classes of ch.powerunit.exception.InternalError

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.