Created
December 4, 2022 15:42
-
-
Save dehidehidehi/2d6f50c924ecd074c5ff7e186085c6db to your computer and use it in GitHub Desktop.
Boilerplate for asserting the contents of a module-info.java class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.lang.module.ModuleDescriptor; | |
import java.lang.module.ModuleDescriptor.Exports; | |
import java.lang.module.ModuleDescriptor.Requires; | |
import java.nio.file.Path; | |
import static org.assertj.core.api.Assertions.assertThat; | |
class ModuleInfoTest { | |
private ModuleDescriptor md; | |
private File file; | |
@BeforeEach | |
void setUp() throws IOException { | |
file = Path.of("target/classes/module-info.class").toFile(); | |
md = ModuleDescriptor.read(new FileInputStream(file)); | |
} | |
@Test | |
void shouldExport() { | |
assertThat(md.exports().stream().map(Exports::source).toList()).containsExactly("EXPECTED_PATH"); | |
} | |
@Test | |
void shouldRequire() { | |
assertThat(md.requires().stream().map(Requires::name).toList()).containsExactly("java.base", "EXPECTED_PATH"); | |
} | |
@Test | |
void shouldBeEmpty() { | |
assertThat(md.opens()).isEmpty(); | |
assertThat(md.uses()).isEmpty(); | |
assertThat(md.provides()).isEmpty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment