GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hosuaby/inject-resources: Simple and convenient way to read content of resource in Java.

BranchesTags
Open more actions menu

Latest commit

 

History

155 Commits
155 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs @ 7d388ca
docs @ 7d388ca
 
 
gradle/wrapper
gradle/wrapper
 
 
inject-resources-commons
inject-resources-commons
 
 
inject-resources-core
inject-resources-core
 
 
inject-resources-junit-jupiter
inject-resources-junit-jupiter
 
 
inject-resources-junit-vintage
inject-resources-junit-vintage
 
 
inject-resources-spring
inject-resources-spring
 
 
test-commons
test-commons
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
index.adoc
index.adoc
 
 
run-tests.zsh
run-tests.zsh
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

@InjectResources

CI Coverage Status Maven Central User guide Core Javadoc Spring Javadoc JUnit Jupiter Javadoc JUnit 4 Javadoc

Reading content of resource files in Java is harder that it should be. Great libraries like Guava or Spring made it much easier, but it's time to make another step forward. Use @InjectResources is the easiest and most convenient way to load and parse content of resources without boilerplate code that opens/closes streams and handles I/O exceptions. This library made of inject-resources-core, fluid Java DSL, and of extensions for Spring, JUnit5 and JUnit4 that allow to do that with simple annotations.

Examples

Core

var text = resource()
        .onClassLoaderOf(this.getClass())
        .withPath("/io/hosuaby/junit/jupiter", "resource.txt")
        .text();

Check Core user guide for more information and examples.

With Spring

@Component
public class MyBean {

    // Field 'text' is injected with content of '/io/hosuaby/junit/jupiter/resource.txt'
    @TextResource("/io/hosuaby/junit/jupiter/resource.txt")
    private String text;
}

Check Spring extension user guide for more information and examples.

With JUnit

JUnit5

@TestWithResources
class InjectTextResourcesTests {

    @GivenTextResource("/io/hosuaby/junit/jupiter/resource.txt")
    String instanceField;

    @Test
    public void testInjectTextIntoStringInstanceField() {
        assertThat(instanceField)
                .isEqualTo("The quick brown fox jumps over the lazy dog.");
    }
}

Check JUnit5 extension user guide for more information and examples.

JUnit4

class MyTestClass {

    @Rule
    public ResourceRule<String> textResource = givenResource()
            .text("/io/hosuaby/junit/jupiter/resource.txt")
            .withCharset(StandardCharsets.UTF_8);

    @Test
    public void testWithTextResource() {
        assertThat(textResource.get())
                .isEqualTo("The quick brown fox jumps over the lazy dog.");
    }
}

Check JUnit4 extension user guide for more information and examples.

Supported formats

  • Binary
  • Text
  • Java properties
  • JSON & JSON Lines
  • YAML & YAML Documents

News

  • 2024-08-16: Release v1.0.0. Ensure compatibility. Java: up to 22, Spring Boot: up to 3.3, JUnit Jupiter: up to 5.11, Jackson: up to 2.17, Gson: up to 2.11, Snakeyaml: up to 2.2. ⚠️ Major change in package names: com.adelean -> io.hosuaby.
  • 2023-05-28: Release v0.3.3. Removed dependency on deprecated InstantiationAwareBeanPostProcessorAdapter.
  • 2022-04-07: Release v0.3.2. Upgrade org.reflections to 0.10.2.
  • 2022-03-23: Release v0.3.1. Limit classpath search for TestsAdvices.
  • 2021-09-04: Release v0.3.0. Fix source compatibility (Gradle). JUnit (5/4) modules now depends on core. Implementation no longer relies on classpath scan to find annotations of the project.
  • 2021-05-10: Release v0.2.2. Use reflexions.org instead of JUnit ReflectionSupport
  • 2021-04-23: Release v0.2.1. Fix reflexion on annotations on JDK 1.8
  • 2021-03-07: Release v0.2.0. Publish to Maven Central.
  • 2020-08-13: Release v0.1.0. This release includes Spring extension.
  • 2020-07-29: Release v0.1.0-beta. This release contains support of YAML files (Snakeyaml) and JUnit 4 extension.
  • 2020-06-20: Release v0.1.0-alpha. The first ever release. Contains only module core and JUnit 5 extension. Support files in formats: binary, text, java properties and JSON.

Documentation

User guides

  • Core,
  • Spring extension,
  • JUnit5 extension,
  • JUnit4 extension

Javadoc

  • Core,
  • Spring extension,
  • JUnit5 extension,
  • JUnit4 extension

About

Simple and convenient way to read content of resource in Java.

inject-resources.hosuaby.io

Topics

gsonjacksonjavajsonjsonljunitjupiterloadloadingparseparse-resourcesparsingresourceresourcessnakeyamlspringteststextyaml

Resources

Readme
Apache-2.0 license
Activity

Stars

62 stars

Watchers

4 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.