Skip to content

andriantomanga/Bwi4J

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bwi4j

Blacklisted Words Inspector For Java

Version Build Status MIT License

Bwi4j is a Java library that allows you to define and enforce rules on the names of classes, methods, and fields within specified packages. This can be useful for enforcing naming conventions or avoiding the use of certain prohibited terms in your codebase.

Similar to ArchUnit, it is ideally used in a test file. It is useful, for example, to prevent contamination of the domain package in a Hexagonal architecture.

Usage example

In the following example, we forbid certain terms in our domain package. Thus, if a collaborator adds a class named ProductRestClient in our domain, the test will fail.

package org.bwi4j.demos;

import org.bwi4j.BwiRule;
import org.bwi4j.exception.BwiException;
import org.junit.jupiter.api.Test;

public class Bwi4jExamplesTest {
    @Test
    void elements_in_defined_packages_should_not_contain_the_given_terms() throws BwiException {
        // Given:
        BwiRule rule = BwiRule.elements()
                .inThesePackages("org.myproject.domain")
                .mustNotContainTheseTerms("Rest", "Hexa", "Dao", "Repository", "Controller", "Service", "Util", "Helper");

        // When + Then:
        rule.check();
    }
}

The exception that proves the rule

If you want a particular element (a class, a method or a field) to be ignored by the Bwi4J scanner, simply annotate it with the @BwiIgnore annotation.

    @BwiIgnore
    public static class BadClassButIgnored {
        private String validField;
        private int forbiddenField;
        public void validMethod() {}
    }

Examples

For more examples, please refer to the Examples repo.

About

_Blacklisted 🚫 _Words_ Inspector πŸ•΅οΈ _For _Java β˜• projects πŸ“‚

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages