-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
90 changes: 90 additions & 0 deletions
90
...ava/org/fedoraproject/javapackages/validator/validators/BytecodeVersionValidatorTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.fedoraproject.javapackages.validator.validators; | ||
|
||
import static org.fedoraproject.javapackages.validator.TestCommon.assertError; | ||
import static org.fedoraproject.javapackages.validator.TestCommon.assertFailOne; | ||
import static org.fedoraproject.javapackages.validator.TestCommon.assertInfo; | ||
import static org.fedoraproject.javapackages.validator.TestCommon.assertPass; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.nio.file.Path; | ||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import org.fedoraproject.javapackages.validator.TestCommon; | ||
import org.fedoraproject.javapackages.validator.spi.Decorated; | ||
import org.fedoraproject.javapackages.validator.spi.LogEntry; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.kojan.javadeptools.rpm.RpmPackage; | ||
|
||
public class BytecodeVersionValidatorTest { | ||
static final Iterable<RpmPackage> RPMS = TestCommon.fromPaths( | ||
TestCommon.RPM_PATH_PREFIX.resolve(Path.of("noarch/jpms-automatic-1-1.noarch.rpm")), | ||
TestCommon.RPM_PATH_PREFIX.resolve(Path.of("noarch/jpms-invalid-1-1.noarch.rpm"))); | ||
|
||
List<String> msgs; | ||
BytecodeVersionValidator validator; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
msgs = new ArrayList<>(); | ||
validator = new BytecodeVersionValidator() { | ||
public void addLog(LogEntry ent) { | ||
String msg = MessageFormat.format(ent.pattern(), | ||
Stream.of(ent.objects()).map(Decorated::getObject).toArray()); | ||
msgs.add(msg); | ||
System.out.println("[" + ent.kind().getDecorated().getObject() + "] " + msg); | ||
super.addLog(ent); | ||
} | ||
}; | ||
} | ||
|
||
void assertMsg(String exp) { | ||
for (String msg : msgs) { | ||
if (msg.contains(exp)) { | ||
return; | ||
} | ||
} | ||
fail("Expected message: " + exp); | ||
} | ||
|
||
@Test | ||
void testInfo() throws Exception { | ||
validator.validate(RPMS, null); | ||
assertInfo(validator.build()); | ||
assertMsg("module-info.class: bytecode version: 65.0"); | ||
} | ||
|
||
@Test | ||
void testPass() throws Exception { | ||
validator.validate(RPMS, List.of("12:345")); | ||
assertPass(validator.build()); | ||
assertMsg("Limits: 12:345"); | ||
assertMsg("found bytecode versions: [65.0]"); | ||
} | ||
|
||
@Test | ||
void testFail() throws Exception { | ||
validator.validate(RPMS, List.of("42")); | ||
assertFailOne(validator.build()); | ||
assertMsg("Limits: 42:42"); | ||
assertMsg("bytecode version: 65.0 is larger than 42"); | ||
} | ||
|
||
@Test | ||
void testEmptyArgs() throws Exception { | ||
validator.validate(RPMS, List.of()); | ||
assertError(validator.build()); | ||
assertMsg("Wrong number of arguments, expected 1"); | ||
} | ||
|
||
@Test | ||
void testTooManyArgs() throws Exception { | ||
validator.validate(RPMS, List.of("12", "34")); | ||
assertError(validator.build()); | ||
assertMsg("Wrong number of arguments, expected 1"); | ||
} | ||
} |