@Test public void testProcessNonJavaFilesWithoutException() throws Exception { final TreeWalker treeWalker = new TreeWalker(); treeWalker.setTabWidth(1); treeWalker.configure(new DefaultConfiguration("default config")); final File file = new File(getPath("InputTreeWalkerNotJava.xml")); final FileText fileText = new FileText(file, StandardCharsets.ISO_8859_1.name()); treeWalker.processFiltered(file, fileText); final Collection<Checks> checks = Whitebox.getInternalState(treeWalker, "ordinaryChecks"); assertTrue("No checks -> No parsing", checks.isEmpty()); }
@Test public void testBehaviourWithZeroChecks() throws Exception { final TreeWalker treeWalker = new TreeWalker(); final PackageObjectFactory factory = new PackageObjectFactory( new HashSet<String>(), Thread.currentThread().getContextClassLoader()); treeWalker.setModuleFactory(factory); // create file that should throw exception final File file = temporaryFolder.newFile("file.java"); final FileText fileText = new FileText(file, new ArrayList<String>()); treeWalker.processFiltered(file, fileText); final Collection<Checks> checks = Whitebox.getInternalState(treeWalker, "ordinaryChecks"); assertTrue("No checks -> No parsing", checks.isEmpty()); }
/** * Accept fields annotated by the given annotations. * * @param annotations Annotation types to check. * @return The filter. */ public static Filter<InstanceField> annotatedBy(final Class<? extends Annotation>... annotations) { return new Filter<InstanceField>() { public boolean isOut(InstanceField instanceField) { Checks.checkNotNull(annotations, "Provide at least one annotation class"); for (Class<? extends Annotation> annotation : annotations) { if(instanceField.isAnnotatedBy(annotation)) { return false; } } return true; } }; }
@Test public void testBehaviourWithZeroChecks() throws Exception { final TreeWalker treeWalker = new TreeWalker(); final PackageObjectFactory factory = new PackageObjectFactory( new HashSet<>(), Thread.currentThread().getContextClassLoader()); treeWalker.setModuleFactory(factory); // create file that should throw exception final File file = temporaryFolder.newFile("file.java"); final FileText fileText = new FileText(file, new ArrayList<>()); treeWalker.processFiltered(file, fileText); final Collection<Checks> checks = Whitebox.getInternalState(treeWalker, "ordinaryChecks"); assertTrue("No checks -> No parsing", checks.isEmpty()); }
/** * Create an new instance of {@link GenericMetadataSupport} inferred from a {@link Type}. * * <p> * At the moment <code>type</code> can only be a {@link Class} or a {@link ParameterizedType}, otherwise * it'll throw a {@link MockitoException}. * </p> * * @param type The class from which the {@link GenericMetadataSupport} should be built. * @return The new {@link GenericMetadataSupport}. * @throws MockitoException Raised if type is not a {@link Class} or a {@link ParameterizedType}. */ public static GenericMetadataSupport inferFrom(Type type) { Checks.checkNotNull(type, "type"); if (type instanceof Class) { return new FromClassGenericMetadataSupport((Class<?>) type); } if (type instanceof ParameterizedType) { return new FromParameterizedTypeGenericMetadataSupport((ParameterizedType) type); } throw new MockitoException("Type meta-data for this Type (" + type.getClass().getCanonicalName() + ") is not supported : " + type); }
/** * Create a new InstanceField. * * @param field The field that should be accessed, note that no checks are performed to ensure * the field belong to this instance class. * @param instance The instance from which the field shall be accessed. */ public InstanceField(Field field, Object instance) { this.field = Checks.checkNotNull(field, "field"); this.instance = Checks.checkNotNull(instance, "instance"); }