Java named module, Gradle 6.4.1, JUnit 5 tests

This commit is contained in:
Jörg Prante 2020-05-19 23:40:25 +02:00
parent 970f62f44f
commit c7d2aa3c87
63 changed files with 788 additions and 1320 deletions

View file

@ -1,22 +1,32 @@
plugins { plugins {
id "org.sonarqube" version "2.6.1" id "de.marcphilipp.nexus-publish" version "0.4.0"
id "io.codearte.nexus-staging" version "0.21.1" id "io.codearte.nexus-staging" version "0.21.1"
id "com.github.spotbugs" version "2.0.1"
id "org.xbib.gradle.plugin.asciidoctor" version "1.6.0.1" id "org.xbib.gradle.plugin.asciidoctor" version "1.6.0.1"
} }
wrapper {
gradleVersion = "${rootProject.property('gradle.wrapper.version')}"
distributionType = Wrapper.DistributionType.ALL
}
ext {
user = 'xbib'
name = 'marc'
description = 'MARC bibliographic data processing library for Java'
inceptionYear = '2016'
url = 'https://github.com/' + user + '/' + name
scmUrl = 'https://github.com/' + user + '/' + name
scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git'
scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git'
issueManagementSystem = 'Github'
issueManagementUrl = ext.scmUrl + '/issues'
licenseName = 'The Apache License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
apply plugin: 'java-library' apply plugin: 'java-library'
apply plugin: 'maven'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
apply plugin: "com.github.spotbugs"
apply plugin: "io.codearte.nexus-staging"
apply plugin: 'org.xbib.gradle.plugin.asciidoctor'
dependencies { dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.property('junit.version')}"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${project.property('junit.version')}"
testImplementation "junit:junit:${project.property('junit4.version')}"
testImplementation "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}" testImplementation "org.xbib:bibliographic-character-sets:${project.property('xbib-bibliographic-character-sets.version')}"
testImplementation "org.xbib:content-core:${project.property('xbib-content.version')}" testImplementation "org.xbib:content-core:${project.property('xbib-content.version')}"
testImplementation "xalan:xalan:${project.property('xalan.version')}" testImplementation "xalan:xalan:${project.property('xalan.version')}"
@ -30,182 +40,7 @@ dependencies {
testImplementation "org.marc4j:marc4j:${project.property('marc4j.version')}" testImplementation "org.marc4j:marc4j:${project.property('marc4j.version')}"
} }
compileJava { apply from: rootProject.file('gradle/ide/idea.gradle')
sourceCompatibility = JavaVersion.VERSION_11 apply from: rootProject.file('gradle/compile/java.gradle')
targetCompatibility = JavaVersion.VERSION_11 apply from: rootProject.file('gradle/test/junit5.gradle')
} apply from: rootProject.file('gradle/publishing/publication.gradle')
compileTestJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all"
if (!options.compilerArgs.contains("-processor")) {
options.compilerArgs << '-proc:none'
}
}
clean {
delete 'out'
}
test {
useJUnitPlatform()
systemProperty 'java.util.logging.config.file',
project.file('src/test/resources/logging.properties').toString()
failFast = false
testLogging {
showStandardStreams = true
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
}
afterSuite { desc, result ->
if (!desc.parent) {
println "\nTest result: ${result.resultType}"
println "Test summary: ${result.testCount} tests, " +
"${result.successfulTestCount} succeeded, " +
"${result.failedTestCount} failed, " +
"${result.skippedTestCount} skipped"
}
}
// massive heap for for xmlunit DOM comparer
jvmArgs '-Xmx2048m'
}
asciidoctor {
attributes toc: 'left',
doctype: 'book',
icons: 'font',
encoding: 'utf-8',
sectlink: true,
sectanchors: true,
linkattrs: true,
imagesdir: 'img',
'source-highlighter': 'coderay'
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier 'javadoc'
}
artifacts {
archives sourcesJar, javadocJar
}
ext {
user = 'xbib'
projectName = 'marc'
projectDescription = 'MARC bibliographic data processing library for Java'
scmUrl = 'https://github.com/xbib/marc'
scmConnection = 'scm:git:git://github.com/xbib/marc.git'
scmDeveloperConnection = 'scm:git:git://github.com/xbib/marc.git'
}
spotbugs {
effort = "max"
reportLevel = "low"
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
ignoreFailures = true
reports {
xml.enabled = false
html.enabled = true
}
}
tasks.withType(Pmd) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
tasks.withType(Checkstyle) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
pmd {
toolVersion = '6.11.0'
ruleSets = ['category/java/bestpractices.xml']
}
checkstyle {
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
ignoreFailures = true
showViolations = true
}
sonarqube {
properties {
property "sonar.projectName", "${project.group} ${project.name}"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.tests", "src/test/java"
property "sonar.scm.provider", "git"
property "sonar.junit.reportsPath", "build/test-results/test/"
}
}
task sonatypeUpload(type: Upload) {
group = 'publish'
configuration = configurations.archives
uploadDescriptor = true
repositories {
if (project.hasProperty('ossrhUsername')) {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: uri(ossrhReleaseUrl)) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: uri(ossrhSnapshotUrl)) {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name projectName
description projectDescription
packaging 'jar'
inceptionYear '2016'
url scmUrl
organization {
name 'xbib'
url 'http://xbib.org'
}
developers {
developer {
id user
name 'Jörg Prante'
email 'joergprante@gmail.com'
url 'https://github.com/jprante'
}
}
scm {
url scmUrl
connection scmConnection
developerConnection scmDeveloperConnection
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
}
}
nexusStaging {
packageGroup = "org.xbib"
}

View file

@ -1,16 +1,10 @@
group = org.xbib group = org.xbib
name = marc name = marc
version = 2.2.1 version = 2.3.0
# main gradle.wrapper.version = 6.4.1
xbib-content.version = 2.0.5 xbib-content.version = 2.2.0
# runtime
xbib-bibliographic-character-sets.version = 1.0.0 xbib-bibliographic-character-sets.version = 1.0.0
# test
junit.version = 5.5.2
junit4.version = 4.12
xalan.version = 2.7.2 xalan.version = 2.7.2
xmlunit-matchers.version = 2.6.3 xmlunit-matchers.version = 2.6.3
system-rules.version = 1.19.0 system-rules.version = 1.19.0

View file

@ -0,0 +1,39 @@
spotbugs {
effort = "max"
reportLevel = "low"
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
ignoreFailures = true
reports {
xml.enabled = false
html.enabled = true
}
}
tasks.withType(Pmd) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
tasks.withType(Checkstyle) {
ignoreFailures = true
reports {
xml.enabled = true
html.enabled = true
}
}
pmd {
toolVersion = '6.11.0'
ruleSets = ['category/java/bestpractices.xml']
}
checkstyle {
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
ignoreFailures = true
showViolations = true
}

View file

@ -0,0 +1,35 @@
apply plugin: 'java-library'
java {
modularity.inferModulePath.set(true)
}
compileJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
compileTestJava {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
jar {
manifest {
attributes('Implementation-Version': project.version)
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier 'javadoc'
}
artifacts {
archives sourcesJar, javadocJar
}

View file

@ -0,0 +1,34 @@
apply plugin: 'org.xbib.gradle.plugin.asciidoctor'
configurations {
asciidoclet
}
dependencies {
asciidoclet "org.asciidoctor:asciidoclet:${project.property('asciidoclet.version')}"
}
/*
javadoc {
options.docletpath = configurations.asciidoclet.files.asType(List)
options.doclet = 'org.asciidoctor.Asciidoclet'
//options.overview = "src/docs/asciidoclet/overview.adoc"
options.addStringOption "-base-dir", "${projectDir}"
options.addStringOption "-attribute",
"name=${project.name},version=${project.version},title-link=https://github.com/xbib/${project.name}"
configure(options) {
noTimestamp = true
}
}*/
asciidoctor {
attributes 'source-highlighter': 'coderay',
toc: 'left',
doctype: 'book',
icons: 'font',
encoding: 'utf-8',
sectlink: true,
sectanchors: true,
linkattrs: true,
imagesdir: 'img'
}

13
gradle/ide/idea.gradle Normal file
View file

@ -0,0 +1,13 @@
apply plugin: 'idea'
idea {
module {
outputDir file('build/classes/java/main')
testOutputDir file('build/classes/java/test')
}
}
if (project.convention.findPlugin(JavaPluginConvention)) {
//sourceSets.main.output.classesDirs = file("build/classes/java/main")
//sourceSets.test.output.classesDirs = file("build/classes/java/test")
}

View file

@ -0,0 +1,64 @@
apply plugin: "de.marcphilipp.nexus-publish"
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = project.name
description = rootProject.ext.description
url = rootProject.ext.url
inceptionYear = rootProject.ext.inceptionYear
packaging = 'jar'
organization {
name = 'xbib'
url = 'https://xbib.org'
}
developers {
developer {
id = 'jprante'
name = 'Jörg Prante'
email = 'joergprante@gmail.com'
url = 'https://github.com/jprante'
}
}
scm {
url = rootProject.ext.scmUrl
connection = rootProject.ext.scmConnection
developerConnection = rootProject.ext.scmDeveloperConnection
}
issueManagement {
system = rootProject.ext.issueManagementSystem
url = rootProject.ext.issueManagementUrl
}
licenses {
license {
name = rootProject.ext.licenseName
url = rootProject.ext.licenseUrl
distribution = 'repo'
}
}
}
}
}
}
if (project.hasProperty("signing.keyId")) {
apply plugin: 'signing'
signing {
sign publishing.publications.mavenJava
}
}
nexusPublishing {
repositories {
sonatype {
username = project.property('ossrhUsername')
password = project.property('ossrhPassword')
packageGroup = "org.xbib"
}
}
}

View file

@ -0,0 +1,11 @@
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
apply plugin: 'io.codearte.nexus-staging'
nexusStaging {
username = project.property('ossrhUsername')
password = project.property('ossrhPassword')
packageGroup = "org.xbib"
}
}

29
gradle/test/junit5.gradle Normal file
View file

@ -0,0 +1,29 @@
def junitVersion = project.hasProperty('junit.version')?project.property('junit.version'):'5.6.2'
def hamcrestVersion = project.hasProperty('hamcrest.version')?project.property('hamcrest.version'):'2.2'
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
failFast = true
testLogging {
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
}
afterSuite { desc, result ->
if (!desc.parent) {
println "\nTest result: ${result.resultType}"
println "Test summary: ${result.testCount} tests, " +
"${result.successfulTestCount} succeeded, " +
"${result.failedTestCount} failed, " +
"${result.skippedTestCount} skipped"
}
}
// massive heap for for xmlunit DOM comparer
jvmArgs '-Xmx2048m'
}

Binary file not shown.

View file

@ -1,6 +1,5 @@
#Fri Sep 13 21:19:04 CEST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

31
gradlew vendored
View file

@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath
@ -154,19 +156,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else else
eval `echo args$i`="\"$arg\"" eval `echo args$i`="\"$arg\""
fi fi
i=$((i+1)) i=`expr $i + 1`
done done
case $i in case $i in
(0) set -- ;; 0) set -- ;;
(1) set -- "$args0" ;; 1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;; 2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;; 3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;; 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
@ -175,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " " echo " "
} }
APP_ARGS=$(save "$@") APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules # Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@" exec "$JAVACMD" "$@"

4
gradlew.bat vendored
View file

@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@ -81,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

View file

@ -0,0 +1,20 @@
module org.xbib.marc {
exports org.xbib.marc;
exports org.xbib.marc.dialects.aleph;
exports org.xbib.marc.dialects.bibliomondo;
exports org.xbib.marc.dialects.mab;
exports org.xbib.marc.dialects.mab.xml;
exports org.xbib.marc.dialects.mab.diskette;
exports org.xbib.marc.dialects.pica;
exports org.xbib.marc.dialects.sisis;
exports org.xbib.marc.io;
exports org.xbib.marc.json;
exports org.xbib.marc.label;
exports org.xbib.marc.tools;
exports org.xbib.marc.transformer;
exports org.xbib.marc.transformer.field;
exports org.xbib.marc.transformer.value;
exports org.xbib.marc.xml;
requires java.logging;
requires java.xml;
}

View file

@ -1,25 +1,8 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.json.MarcJsonWriter; import org.xbib.marc.json.MarcJsonWriter;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;

View file

@ -1,30 +1,16 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import java.util.TreeSet; import java.util.TreeSet;
/** /**
* *
*/ */
public class MarcFieldTest extends Assert { public class MarcFieldTest {
@Test @Test
public void testFieldData() { public void testFieldData() {
@ -221,5 +207,4 @@ public class MarcFieldTest extends Assert {
assertNull(marcField.getFirstSubfield().getValue()); assertNull(marcField.getFirstSubfield().getValue());
assertNull(marcField.getLastSubfield().getValue()); assertNull(marcField.getLastSubfield().getValue());
} }
} }

View file

@ -1,23 +1,11 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.xbib.marc.label.RecordLabel; import org.xbib.marc.label.RecordLabel;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
@ -35,7 +23,7 @@ import java.util.regex.Pattern;
/** /**
* *
*/ */
public class MarcRecordTest extends Assert { public class MarcRecordTest {
@Test @Test
public void testMarcRecordLabel() { public void testMarcRecordLabel() {
@ -223,5 +211,4 @@ public class MarcRecordTest extends Assert {
assertThat(file, CompareMatcher.isIdenticalTo(getClass().getResource(s + ".xml").openStream())); assertThat(file, CompareMatcher.isIdenticalTo(getClass().getResource(s + ".xml").openStream()));
} }
} }
} }

View file

@ -1,11 +1,9 @@
package org.xbib.marc; package org.xbib.marc;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -65,7 +63,6 @@ public class MarcRoundTripTest {
.writeCollection(); .writeCollection();
} }
// compare both to expected file structure // compare both to expected file structure
assertThat(file, CompareMatcher.isIdenticalTo(getClass().getResource(s + ".xml").openStream())); assertThat(file, CompareMatcher.isIdenticalTo(getClass().getResource(s + ".xml").openStream()));
assertThat(file2, CompareMatcher.isIdenticalTo(getClass().getResource(s + ".xml").openStream())); assertThat(file2, CompareMatcher.isIdenticalTo(getClass().getResource(s + ".xml").openStream()));
} }

View file

@ -1,33 +1,15 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import static org.junit.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.io.ReplaceStringInputStream; import org.xbib.marc.io.ReplaceStringInputStream;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.transformer.value.Xml10MarcValueCleaner; import org.xbib.marc.transformer.value.Xml10MarcValueCleaner;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;

View file

@ -1,38 +1,17 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.xbib.marc.MarcXchangeConstants.MARC21_FORMAT; import static org.xbib.marc.MarcXchangeConstants.MARC21_FORMAT;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xbib.marc.xml.Sax2Dom; import org.xbib.marc.xml.Sax2Dom;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import javax.xml.transform.ErrorListener; import javax.xml.transform.ErrorListener;
import javax.xml.transform.OutputKeys; import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result; import javax.xml.transform.Result;

View file

@ -1,27 +1,11 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -32,7 +16,7 @@ import java.nio.charset.StandardCharsets;
/** /**
* *
*/ */
public class MarcWriterTest extends Assert { public class MarcWriterTest {
@Test @Test
public void testUtf8MarcWriter() throws Exception { public void testUtf8MarcWriter() throws Exception {

View file

@ -1,27 +1,11 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertFalse;
import org.junit.jupiter.api.Test;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.InputStream; import java.io.InputStream;
@ -32,7 +16,7 @@ import java.util.zip.GZIPInputStream;
/** /**
* *
*/ */
public class MarcXchangeWriterTest extends Assert { public class MarcXchangeWriterTest {
@Test @Test
public void splitMarcXchange() throws Exception { public void splitMarcXchange() throws Exception {

View file

@ -1,17 +1,13 @@
package org.xbib.marc; package org.xbib.marc;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
*
*/
public class SWBTest { public class SWBTest {
@Test @Test
@ -48,7 +44,7 @@ public class SWBTest {
try (InputStream in = getClass().getResource(file).openStream()) { try (InputStream in = getClass().getResource(file).openStream()) {
Marc.Builder builder = Marc.builder() Marc.Builder builder = Marc.builder()
.setInputStream(in) .setInputStream(in)
.setCharset(Charset.forName("UTF-8")); .setCharset(StandardCharsets.UTF_8);
for (MarcRecord marcRecord : builder.iterable()) { for (MarcRecord marcRecord : builder.iterable()) {
count++; count++;
} }

View file

@ -16,8 +16,7 @@
*/ */
package org.xbib.marc; package org.xbib.marc;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -29,7 +28,7 @@ import java.nio.charset.StandardCharsets;
/** /**
* *
*/ */
public class StreamMatcher extends Assert { public class StreamMatcher {
public static void assertStream(String name, InputStream expected, String actual) throws IOException { public static void assertStream(String name, InputStream expected, String actual) throws IOException {
assertStream(name, expected, new ByteArrayInputStream(actual.getBytes(StandardCharsets.UTF_8))); assertStream(name, expected, new ByteArrayInputStream(actual.getBytes(StandardCharsets.UTF_8)));

View file

@ -1,33 +1,15 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc; package org.xbib.marc;
import static org.junit.Assert.assertEquals; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.xbib.marc.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.json.MarcJsonWriter; import org.xbib.marc.json.MarcJsonWriter;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -38,9 +20,6 @@ import java.nio.charset.StandardCharsets;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.EnumSet; import java.util.EnumSet;
/**
*
*/
public class ZDBTest { public class ZDBTest {
private final StringBuilder sb = new StringBuilder(); private final StringBuilder sb = new StringBuilder();

View file

@ -1,24 +1,7 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.aleph; package org.xbib.marc.dialects.aleph;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcXchangeConstants; import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
@ -29,9 +12,6 @@ import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/**
*
*/
public class AlephSequentialTest { public class AlephSequentialTest {
@Test @Test

View file

@ -1,28 +1,9 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.bibliomondo; package org.xbib.marc.dialects.bibliomondo;
import org.junit.Assert; import org.junit.jupiter.api.Disabled;
import org.junit.Ignore; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher;
import java.io.InputStream; import java.io.InputStream;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -30,13 +11,10 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
/** public class BiblioMondoInputStreamTest {
*
*/
public class BiblioMondoInputStreamTest extends Assert {
@Test @Test
@Ignore("skip this because data license is unclear") @Disabled("skip this because data license is unclear")
public void biblioMondoRecords() throws Exception { public void biblioMondoRecords() throws Exception {
Path path = Paths.get("/data/fix/DE-380/Stbib_Fernleihe_20150427.MARC"); Path path = Paths.get("/data/fix/DE-380/Stbib_Fernleihe_20150427.MARC");
Path out = Paths.get("/var/tmp/Stbib_Fernleihe_20150427.marcxchange"); Path out = Paths.get("/var/tmp/Stbib_Fernleihe_20150427.marcxchange");

View file

@ -1,20 +1,15 @@
package org.xbib.marc.dialects.mab; package org.xbib.marc.dialects.mab;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcRecord; import org.xbib.marc.MarcRecord;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
*
*/
public class HBZTest { public class HBZTest {
@Test @Test

View file

@ -1,28 +1,11 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.mab; package org.xbib.marc.dialects.mab;
import static org.junit.Assert.assertNull; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.xbib.marc.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.HEAD; import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.HEAD;
import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.TAIL; import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.TAIL;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcField; import org.xbib.marc.MarcField;
import org.xbib.marc.MarcListener; import org.xbib.marc.MarcListener;
@ -36,7 +19,6 @@ import org.xbib.marc.xml.MarcContentHandler;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@ -45,9 +27,6 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/**
*
*/
public class MabTest { public class MabTest {
private final StringBuilder sb = new StringBuilder(); private final StringBuilder sb = new StringBuilder();
@ -165,7 +144,6 @@ public class MabTest {
writer.endCollection(); writer.endCollection();
sw.close(); sw.close();
assertNull(writer.getException()); assertNull(writer.getException());
assertStream(s, assertStream(s,
getClass().getResource("HT016424175-combined-keyvalue.txt").openStream(), sb.toString()); getClass().getResource("HT016424175-combined-keyvalue.txt").openStream(), sb.toString());
assertThat(sw.toString(), assertThat(sw.toString(),

View file

@ -1,9 +1,8 @@
package org.xbib.marc.dialects.mab; package org.xbib.marc.dialects.mab;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.xbib.marc.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.dialects.mab.xml.MabXMLContentHandler; import org.xbib.marc.dialects.mab.xml.MabXMLContentHandler;
import org.xbib.marc.json.MarcJsonWriter; import org.xbib.marc.json.MarcJsonWriter;
@ -11,7 +10,6 @@ import org.xbib.marc.xml.MarcContentHandler;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -20,9 +18,6 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.EnumSet; import java.util.EnumSet;
/**
*
*/
public class MabXmlTest { public class MabXmlTest {
@Test @Test

View file

@ -1,21 +1,16 @@
package org.xbib.marc.dialects.mab; package org.xbib.marc.dialects.mab;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcRecord; import org.xbib.marc.MarcRecord;
import org.xbib.marc.label.RecordLabel; import org.xbib.marc.label.RecordLabel;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
*
*/
public class OBVSGTest { public class OBVSGTest {
@Test @Test

View file

@ -1,37 +1,19 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.mab.diskette; package org.xbib.marc.dialects.mab.diskette;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
/** public class MabDisketteTest {
*
*/
public class MabDisketteTest extends Assert {
@Test @Test
public void testMABDiskette() throws Exception { public void testMABDiskette() throws Exception {

View file

@ -1,40 +1,19 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.pica; package org.xbib.marc.dialects.pica;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.xbib.marc.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcField; import org.xbib.marc.MarcField;
import org.xbib.marc.MarcListener; import org.xbib.marc.MarcListener;
import org.xbib.marc.MarcXchangeConstants; import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/**
*
*/
public class PicaTest { public class PicaTest {
@Test @Test

View file

@ -1,30 +1,14 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.sisis; package org.xbib.marc.dialects.sisis;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcXchangeConstants; import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.transformer.field.MarcFieldTransformer; import org.xbib.marc.transformer.field.MarcFieldTransformer;
import org.xbib.marc.transformer.field.MarcFieldTransformers; import org.xbib.marc.transformer.field.MarcFieldTransformers;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
@ -32,10 +16,7 @@ import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** public class SisisTest {
*
*/
public class SisisTest extends Assert {
/** /**
* Test file donated from DE-A96. * Test file donated from DE-A96.

View file

@ -1,36 +1,17 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.dialects.unimarc; package org.xbib.marc.dialects.unimarc;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.xml.MarcXchangeWriter; import org.xbib.marc.xml.MarcXchangeWriter;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** public class UnimarcTest {
*
*/
public class UnimarcTest extends Assert {
/** /**
* UNIMARC test. * UNIMARC test.

View file

@ -1,6 +1,6 @@
package org.xbib.marc.filter; package org.xbib.marc.filter;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.xbib.content.XContentBuilder; import org.xbib.content.XContentBuilder;
import org.xbib.content.json.JsonXContent; import org.xbib.content.json.JsonXContent;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;

View file

@ -1,14 +1,12 @@
package org.xbib.marc.filter; package org.xbib.marc.filter;
import static org.xbib.content.json.JsonXContent.contentBuilder; import static org.xbib.content.json.JsonXContent.contentBuilder;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.content.XContentBuilder; import org.xbib.content.XContentBuilder;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcField; import org.xbib.marc.MarcField;
import org.xbib.marc.MarcFieldAdapter; import org.xbib.marc.MarcFieldAdapter;
import org.xbib.marc.MarcListener; import org.xbib.marc.MarcListener;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View file

@ -1,34 +1,13 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.io; package org.xbib.marc.io;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.InputStream; import java.io.InputStream;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
*
*/
public class BufferedSeparatorInputStreamTest { public class BufferedSeparatorInputStreamTest {
private int dataCount = 0; private int dataCount = 0;

View file

@ -1,31 +1,10 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.io; package org.xbib.marc.io;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/**
*
*/
public class BytesStreamOutputTest { public class BytesStreamOutputTest {
/** /**

View file

@ -1,26 +1,8 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.io; package org.xbib.marc.io;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -28,9 +10,6 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
*
*/
public class PatternInputStreamTest { public class PatternInputStreamTest {
@Test @Test
@ -47,7 +26,6 @@ public class PatternInputStreamTest {
} }
separatorStream.close(); separatorStream.close();
assertEquals("{1=5, 2=5}", map.toString()); assertEquals("{1=5, 2=5}", map.toString());
;
} }
@Test @Test
@ -64,7 +42,6 @@ public class PatternInputStreamTest {
} }
separatorStream.close(); separatorStream.close();
assertEquals("{1=5, 2=5}", map.toString()); assertEquals("{1=5, 2=5}", map.toString());
;
} }
@Test @Test
@ -100,7 +77,6 @@ public class PatternInputStreamTest {
} }
separatorStream.close(); separatorStream.close();
assertEquals(20000, count.get()); assertEquals(20000, count.get());
;
} }
@Test @Test
@ -119,7 +95,6 @@ public class PatternInputStreamTest {
}); });
separatorStream.close(); separatorStream.close();
assertEquals(20000, count.get()); assertEquals(20000, count.get());
;
} }
} }

View file

@ -1,33 +1,12 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.io; package org.xbib.marc.io;
import static org.xbib.marc.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/**
*
*/
public class ReplaceStringInputStreamTest { public class ReplaceStringInputStreamTest {
@Test @Test

View file

@ -1,28 +1,8 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.io; package org.xbib.marc.io;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.Test;
/**
*
*/
public class ScanBufferTest { public class ScanBufferTest {
@Test @Test

View file

@ -1,7 +1,7 @@
package org.xbib.marc.io; package org.xbib.marc.io;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.marc4j.MarcPermissiveStreamReader; import org.marc4j.MarcPermissiveStreamReader;
import org.marc4j.MarcReader; import org.marc4j.MarcReader;
import org.marc4j.marc.Record; import org.marc4j.marc.Record;
@ -18,7 +18,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
@Ignore @Disabled("large file")
public class UncompressLargeFileTest { public class UncompressLargeFileTest {
private static final Logger logger = Logger.getLogger(UncompressLargeFileTest.class.getName()); private static final Logger logger = Logger.getLogger(UncompressLargeFileTest.class.getName());

View file

@ -1,42 +1,22 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.InOrder; import org.mockito.InOrder;
import java.io.IOException; import java.io.IOException;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
/** public class JsonArrayTest {
*
*/
public class JsonArrayTest extends TestUtil {
private JsonArray array; private JsonArray array;
@ -48,18 +28,18 @@ public class JsonArrayTest extends TestUtil {
return array; return array;
} }
@Before @BeforeEach
public void setUp() { public void setUp() {
array = new JsonArray(); array = new JsonArray();
} }
@Test @Test
public void copyConstructorfailsWithNull() { public void copyConstructorFailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> new JsonArray(null)); Assertions.assertThrows(NullPointerException.class, () -> new JsonArray(null));
} }
@Test @Test
public void copyConstructorhasSameValues() { public void copyConstructorHasSameValues() {
array.add(23); array.add(23);
JsonArray copy = new JsonArray(array); JsonArray copy = new JsonArray(array);
assertEquals(array.values(), copy.values()); assertEquals(array.values(), copy.values());
@ -80,7 +60,6 @@ public class JsonArrayTest extends TestUtil {
@Test @Test
public void isEmptyisFalseAfterAdd() { public void isEmptyisFalseAfterAdd() {
array.add(true); array.add(true);
assertFalse(array.isEmpty()); assertFalse(array.isEmpty());
} }
@ -109,19 +88,23 @@ public class JsonArrayTest extends TestUtil {
assertFalse(iterator.hasNext()); assertFalse(iterator.hasNext());
} }
@Test(expected = UnsupportedOperationException.class) @Test
public void iteratordoesNotAllowModification() { public void iteratordoesNotAllowModification() {
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
array.add(23); array.add(23);
Iterator<JsonValue> iterator = array.iterator(); Iterator<JsonValue> iterator = array.iterator();
iterator.next(); iterator.next();
iterator.remove(); iterator.remove();
});
} }
@Test(expected = ConcurrentModificationException.class) @Test
public void iteratordetectsConcurrentModification() { public void iteratordetectsConcurrentModification() {
Assertions.assertThrows(ConcurrentModificationException.class, () -> {
Iterator<JsonValue> iterator = array.iterator(); Iterator<JsonValue> iterator = array.iterator();
array.add(23); array.add(23);
iterator.next(); iterator.next();
});
} }
@Test @Test
@ -156,9 +139,9 @@ public class JsonArrayTest extends TestUtil {
assertEquals(Json.of(23), value); assertEquals(Json.of(23), value);
} }
@Test(expected = IndexOutOfBoundsException.class) @Test
public void getfailsWithInvalidIndex() { public void getfailsWithInvalidIndex() {
array.get(0); Assertions.assertThrows(IndexOutOfBoundsException.class, () -> array.get(0));
} }
@Test @Test
@ -258,7 +241,7 @@ public class JsonArrayTest extends TestUtil {
@Test @Test
public void addjsonfailsWithNull() { public void addjsonfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> array.add((JsonValue) null)); Assertions.assertThrows(NullPointerException.class, () -> array.add((JsonValue) null));
} }
@Test @Test
@ -395,12 +378,14 @@ public class JsonArrayTest extends TestUtil {
@Test @Test
public void setJsonFailsWithNull() { public void setJsonFailsWithNull() {
array.add(false); array.add(false);
assertException(NullPointerException.class, null, (Runnable) () -> array.set(0, (JsonValue) null)); Assertions.assertThrows(NullPointerException.class, () ->
array.set(0, (JsonValue) null));
} }
@Test(expected = IndexOutOfBoundsException.class) @Test
public void setjsonfailsWithInvalidIndex() { public void setjsonfailsWithInvalidIndex() {
array.set(0, JsonLiteral.NULL); Assertions.assertThrows(IndexOutOfBoundsException.class, () ->
array.set(0, JsonLiteral.NULL));
} }
@Test @Test
@ -416,9 +401,11 @@ public class JsonArrayTest extends TestUtil {
assertEquals("[3,4,5]", array.toString()); assertEquals("[3,4,5]", array.toString());
} }
@Test(expected = IndexOutOfBoundsException.class) @Test
public void removefailsWithInvalidIndex() { public void removefailsWithInvalidIndex() {
array.remove(0); Assertions.assertThrows(IndexOutOfBoundsException.class, () ->
array.remove(0)
);
} }
@Test @Test

View file

@ -1,39 +1,18 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.xbib.marc.json.JsonLiteral.FALSE; import static org.xbib.marc.json.JsonLiteral.FALSE;
import static org.xbib.marc.json.JsonLiteral.NULL; import static org.xbib.marc.json.JsonLiteral.NULL;
import static org.xbib.marc.json.JsonLiteral.TRUE; import static org.xbib.marc.json.JsonLiteral.TRUE;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
/**
*
*/
public class JsonLiteralTest { public class JsonLiteralTest {
@Test @Test
@ -129,5 +108,4 @@ public class JsonLiteralTest {
assertNotEquals(FALSE, Boolean.FALSE); assertNotEquals(FALSE, Boolean.FALSE);
assertNotEquals(NULL, Json.of("false")); assertNotEquals(NULL, Json.of("false"));
} }
} }

View file

@ -1,40 +1,21 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
/** public class JsonNumberTest {
*
*/
public class JsonNumberTest extends TestUtil {
private StringWriter output; private StringWriter output;
private JsonWriter writer; private JsonWriter writer;
@Before @BeforeEach
public void setUp() { public void setUp() {
output = new StringWriter(); output = new StringWriter();
writer = new JsonWriter(output); writer = new JsonWriter(output);
@ -42,7 +23,7 @@ public class JsonNumberTest extends TestUtil {
@Test @Test
public void constructorfailsWithNull() { public void constructorfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> new JsonNumber(null)); Assertions.assertThrows(NullPointerException.class, () -> new JsonNumber(null));
} }
@Test @Test
@ -66,19 +47,25 @@ public class JsonNumberTest extends TestUtil {
assertEquals(23, new JsonNumber("23").asInt()); assertEquals(23, new JsonNumber("23").asInt());
} }
@Test(expected = NumberFormatException.class) @Test
public void asIntfailsWithExceedingValues() { public void asIntfailsWithExceedingValues() {
Assertions.assertThrows(NumberFormatException.class, () -> {
new JsonNumber("10000000000").asInt(); new JsonNumber("10000000000").asInt();
});
} }
@Test(expected = NumberFormatException.class) @Test
public void asIntfailsWithExponent() { public void asIntfailsWithExponent() {
Assertions.assertThrows(NumberFormatException.class, () -> {
new JsonNumber("1e5").asInt(); new JsonNumber("1e5").asInt();
});
} }
@Test(expected = NumberFormatException.class) @Test
public void asIntfailsWithFractional() { public void asIntfailsWithFractional() {
Assertions.assertThrows(NumberFormatException.class, () -> {
new JsonNumber("23.5").asInt(); new JsonNumber("23.5").asInt();
});
} }
@Test @Test
@ -86,19 +73,25 @@ public class JsonNumberTest extends TestUtil {
assertEquals(23L, new JsonNumber("23").asLong()); assertEquals(23L, new JsonNumber("23").asLong());
} }
@Test(expected = NumberFormatException.class) @Test
public void asLongfailsWithExceedingValues() { public void asLongfailsWithExceedingValues() {
Assertions.assertThrows(NumberFormatException.class, () -> {
new JsonNumber("10000000000000000000").asLong(); new JsonNumber("10000000000000000000").asLong();
});
} }
@Test(expected = NumberFormatException.class) @Test
public void asLongfailsWithExponent() { public void asLongfailsWithExponent() {
Assertions.assertThrows(NumberFormatException.class, () -> {
new JsonNumber("1e5").asLong(); new JsonNumber("1e5").asLong();
});
} }
@Test(expected = NumberFormatException.class) @Test
public void asLongfailsWithFractional() { public void asLongfailsWithFractional() {
Assertions.assertThrows(NumberFormatException.class, () -> {
new JsonNumber("23.5").asLong(); new JsonNumber("23.5").asLong();
});
} }
@Test @Test

View file

@ -1,45 +1,25 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.InOrder; import org.mockito.InOrder;
import java.io.IOException; import java.io.IOException;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/** public class JsonObjectTest {
*
*/
public class JsonObjectTest extends TestUtil {
private JsonObject object; private JsonObject object;
@ -51,21 +31,20 @@ public class JsonObjectTest extends TestUtil {
return object; return object;
} }
@Before @BeforeEach
public void setUp() { public void setUp() {
object = new JsonObject(); object = new JsonObject();
} }
@Test @Test
public void copyConstructorfailsWithNull() { public void copyConstructorfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> new JsonObject(null)); Assertions.assertThrows(NullPointerException.class, () -> new JsonObject(null));
} }
@Test @Test
public void copyConstructorhasSameValues() { public void copyConstructorhasSameValues() {
object.add("foo", 23); object.add("foo", 23);
JsonObject copy = new JsonObject(object); JsonObject copy = new JsonObject(object);
assertEquals(object.names(), copy.names()); assertEquals(object.names(), copy.names());
assertSame(object.get("foo"), copy.get("foo")); assertSame(object.get("foo"), copy.get("foo"));
} }
@ -74,7 +53,6 @@ public class JsonObjectTest extends TestUtil {
public void copyConstructorworksOnSafeCopy() { public void copyConstructorworksOnSafeCopy() {
JsonObject copy = new JsonObject(object); JsonObject copy = new JsonObject(object);
object.add("foo", 23); object.add("foo", 23);
assertTrue(copy.isEmpty()); assertTrue(copy.isEmpty());
} }
@ -86,7 +64,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void isEmptyfalseAfterAdd() { public void isEmptyfalseAfterAdd() {
object.add("a", true); object.add("a", true);
assertFalse(object.isEmpty()); assertFalse(object.isEmpty());
} }
@ -98,7 +75,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void sizeoneAfterAdd() { public void sizeoneAfterAdd() {
object.add("a", true); object.add("a", true);
assertEquals(1, object.size()); assertEquals(1, object.size());
} }
@ -106,7 +82,6 @@ public class JsonObjectTest extends TestUtil {
public void keyRepetitionallowsMultipleEntries() { public void keyRepetitionallowsMultipleEntries() {
object.add("a", true); object.add("a", true);
object.add("a", "value"); object.add("a", "value");
assertEquals(2, object.size()); assertEquals(2, object.size());
} }
@ -114,7 +89,6 @@ public class JsonObjectTest extends TestUtil {
public void keyRepetitiongetsLastEntry() { public void keyRepetitiongetsLastEntry() {
object.add("a", true); object.add("a", true);
object.add("a", "value"); object.add("a", "value");
assertEquals("value", object.getString("a", "missing")); assertEquals("value", object.getString("a", "missing"));
} }
@ -122,11 +96,9 @@ public class JsonObjectTest extends TestUtil {
public void keyRepetitionequalityConsidersRepetitions() { public void keyRepetitionequalityConsidersRepetitions() {
object.add("a", true); object.add("a", true);
object.add("a", "value"); object.add("a", "value");
JsonObject onlyFirstProperty = new JsonObject(); JsonObject onlyFirstProperty = new JsonObject();
onlyFirstProperty.add("a", true); onlyFirstProperty.add("a", true);
assertNotEquals(onlyFirstProperty, object); assertNotEquals(onlyFirstProperty, object);
JsonObject bothProperties = new JsonObject(); JsonObject bothProperties = new JsonObject();
bothProperties.add("a", true); bothProperties.add("a", true);
bothProperties.add("a", "value"); bothProperties.add("a", "value");
@ -141,7 +113,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void namescontainsNameAfterAdd() { public void namescontainsNameAfterAdd() {
object.add("foo", true); object.add("foo", true);
List<String> names = object.names(); List<String> names = object.names();
assertEquals(1, names.size()); assertEquals(1, names.size());
assertEquals("foo", names.get(0)); assertEquals("foo", names.get(0));
@ -150,18 +121,17 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void namesreflectsChanges() { public void namesreflectsChanges() {
List<String> names = object.names(); List<String> names = object.names();
object.add("foo", true); object.add("foo", true);
assertEquals(1, names.size()); assertEquals(1, names.size());
assertEquals("foo", names.get(0)); assertEquals("foo", names.get(0));
} }
@Test(expected = UnsupportedOperationException.class) @Test
public void namespreventsModification() { public void namespreventsModification() {
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
List<String> names = object.names(); List<String> names = object.names();
names.add("foo"); names.add("foo");
});
} }
@Test @Test
@ -193,30 +163,37 @@ public class JsonObjectTest extends TestUtil {
assertEquals(new JsonObject.Member("b", JsonLiteral.FALSE), iterator.next()); assertEquals(new JsonObject.Member("b", JsonLiteral.FALSE), iterator.next());
} }
@Test(expected = NoSuchElementException.class) @Test
public void iteratornextFailsAtEnd() { public void iteratornextFailsAtEnd() {
Assertions.assertThrows(NoSuchElementException.class, () -> {
Iterator<JsonObject.Member> iterator = object.iterator(); Iterator<JsonObject.Member> iterator = object.iterator();
iterator.next(); iterator.next();
});
} }
@Test(expected = UnsupportedOperationException.class) @Test
public void iteratordoesNotAllowModification() { public void iteratordoesNotAllowModification() {
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
object.add("a", 23); object.add("a", 23);
Iterator<JsonObject.Member> iterator = object.iterator(); Iterator<JsonObject.Member> iterator = object.iterator();
iterator.next(); iterator.next();
iterator.remove(); iterator.remove();
});
} }
@Test(expected = ConcurrentModificationException.class) @Test
public void iteratordetectsConcurrentModification() { public void iteratordetectsConcurrentModification() {
Assertions.assertThrows(ConcurrentModificationException.class, () -> {
Iterator<JsonObject.Member> iterator = object.iterator(); Iterator<JsonObject.Member> iterator = object.iterator();
object.add("a", 23); object.add("a", 23);
iterator.next(); iterator.next();
});
} }
@Test @Test
public void getfailsWithNullName() { public void getfailsWithNullName() {
assertException(NullPointerException.class, null, (Runnable) () -> object.get(null)); Assertions.assertThrows(NullPointerException.class, () -> object.get(null));
} }
@Test @Test
@ -310,13 +287,12 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addfailsWithNullName() { public void addfailsWithNullName() {
assertException(NullPointerException.class, "name is null", (Runnable) () -> object.add(null, 23)); Assertions.assertThrows(NullPointerException.class, () -> object.add(null, 23));
} }
@Test @Test
public void addint() { public void addint() {
object.add("a", 23); object.add("a", 23);
assertEquals("{\"a\":23}", object.toString()); assertEquals("{\"a\":23}", object.toString());
} }
@ -328,7 +304,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addlong() { public void addlong() {
object.add("a", 23L); object.add("a", 23L);
assertEquals("{\"a\":23}", object.toString()); assertEquals("{\"a\":23}", object.toString());
} }
@ -340,7 +315,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addfloat() { public void addfloat() {
object.add("a", 3.14f); object.add("a", 3.14f);
assertEquals("{\"a\":3.14}", object.toString()); assertEquals("{\"a\":3.14}", object.toString());
} }
@ -352,7 +326,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void adddouble() { public void adddouble() {
object.add("a", 3.14d); object.add("a", 3.14d);
assertEquals("{\"a\":3.14}", object.toString()); assertEquals("{\"a\":3.14}", object.toString());
} }
@ -364,7 +337,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addboolean() { public void addboolean() {
object.add("a", true); object.add("a", true);
assertEquals("{\"a\":true}", object.toString()); assertEquals("{\"a\":true}", object.toString());
} }
@ -376,14 +348,12 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addstring() { public void addstring() {
object.add("a", "foo"); object.add("a", "foo");
assertEquals("{\"a\":\"foo\"}", object.toString()); assertEquals("{\"a\":\"foo\"}", object.toString());
} }
@Test @Test
public void addstringtoleratesNull() { public void addstringtoleratesNull() {
object.add("a", (String) null); object.add("a", (String) null);
assertEquals("{\"a\":null}", object.toString()); assertEquals("{\"a\":null}", object.toString());
} }
@ -395,21 +365,18 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addjsonNull() { public void addjsonNull() {
object.add("a", JsonLiteral.NULL); object.add("a", JsonLiteral.NULL);
assertEquals("{\"a\":null}", object.toString()); assertEquals("{\"a\":null}", object.toString());
} }
@Test @Test
public void addjsonArray() { public void addjsonArray() {
object.add("a", new JsonArray()); object.add("a", new JsonArray());
assertEquals("{\"a\":[]}", object.toString()); assertEquals("{\"a\":[]}", object.toString());
} }
@Test @Test
public void addjsonObject() { public void addjsonObject() {
object.add("a", new JsonObject()); object.add("a", new JsonObject());
assertEquals("{\"a\":{}}", object.toString()); assertEquals("{\"a\":{}}", object.toString());
} }
@ -420,16 +387,15 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void addjsonfailsWithNull() { public void addjsonfailsWithNull() {
assertException(NullPointerException.class, "value is null", (Runnable) () -> object.add("a", (JsonValue) null)); Assertions.assertThrows(NullPointerException.class, () ->
object.add("a", (JsonValue) null));
} }
@Test @Test
public void addjsonnestedArray() { public void addjsonnestedArray() {
JsonArray innerArray = new JsonArray(); JsonArray innerArray = new JsonArray();
innerArray.add(23); innerArray.add(23);
object.add("a", innerArray); object.add("a", innerArray);
assertEquals("{\"a\":[23]}", object.toString()); assertEquals("{\"a\":[23]}", object.toString());
} }
@ -437,9 +403,7 @@ public class JsonObjectTest extends TestUtil {
public void addjsonnestedArraymodifiedAfterAdd() { public void addjsonnestedArraymodifiedAfterAdd() {
JsonArray innerArray = new JsonArray(); JsonArray innerArray = new JsonArray();
object.add("a", innerArray); object.add("a", innerArray);
innerArray.add(23); innerArray.add(23);
assertEquals("{\"a\":[23]}", object.toString()); assertEquals("{\"a\":[23]}", object.toString());
} }
@ -447,9 +411,7 @@ public class JsonObjectTest extends TestUtil {
public void addjsonnestedObject() { public void addjsonnestedObject() {
JsonObject innerObject = new JsonObject(); JsonObject innerObject = new JsonObject();
innerObject.add("a", 23); innerObject.add("a", 23);
object.add("a", innerObject); object.add("a", innerObject);
assertEquals("{\"a\":{\"a\":23}}", object.toString()); assertEquals("{\"a\":{\"a\":23}}", object.toString());
} }
@ -457,16 +419,13 @@ public class JsonObjectTest extends TestUtil {
public void addjsonnestedObjectmodifiedAfterAdd() { public void addjsonnestedObjectmodifiedAfterAdd() {
JsonObject innerObject = new JsonObject(); JsonObject innerObject = new JsonObject();
object.add("a", innerObject); object.add("a", innerObject);
innerObject.add("a", 23); innerObject.add("a", 23);
assertEquals("{\"a\":{\"a\":23}}", object.toString()); assertEquals("{\"a\":{\"a\":23}}", object.toString());
} }
@Test @Test
public void setint() { public void setint() {
object.set("a", 23); object.set("a", 23);
assertEquals("{\"a\":23}", object.toString()); assertEquals("{\"a\":23}", object.toString());
} }
@ -478,7 +437,6 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void setlong() { public void setlong() {
object.set("a", 23L); object.set("a", 23L);
assertEquals("{\"a\":23}", object.toString()); assertEquals("{\"a\":23}", object.toString());
} }
@ -589,7 +547,7 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void removefailsWithNullName() { public void removefailsWithNullName() {
assertException(NullPointerException.class, null, (Runnable) () -> object.remove(null)); Assertions.assertThrows(NullPointerException.class, () -> object.remove(null));
} }
@Test @Test
@ -645,7 +603,7 @@ public class JsonObjectTest extends TestUtil {
@Test @Test
public void mergefailsWithNull() { public void mergefailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> object.merge(null)); Assertions.assertThrows(NullPointerException.class, () -> object.merge(null));
} }
@Test @Test

View file

@ -1,37 +1,17 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringStartsWith.startsWith; import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.xbib.marc.json.Json.parse; import static org.xbib.marc.json.Json.parse;
import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
/** public class JsonReaderTest {
*
*/
public class JsonReaderTest extends TestUtil {
private static String join(String... strings) { private static String join(String... strings) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -41,27 +21,35 @@ public class JsonReaderTest extends TestUtil {
return builder.toString(); return builder.toString();
} }
@Test(expected = NullPointerException.class) @Test
public void constructorRejectsNullHandler() { public void constructorRejectsNullHandler() {
Assertions.assertThrows(NullPointerException.class, () -> {
new JsonReader<>(null, null); new JsonReader<>(null, null);
});
} }
@Test(expected = NullPointerException.class) @Test
public void parseStringrRjectsNull() throws IOException { public void parseStringrRejectsNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(null), new TestHandler()); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(null), new TestHandler());
reader.parse(); reader.parse();
});
} }
@Test(expected = NullPointerException.class) @Test
public void parseReaderRejectsNull() throws IOException { public void parseReaderRejectsNull() {
Assertions.assertThrows(NullPointerException.class, () -> {
JsonReader<Object, Object> reader = new JsonReader<>(null, new TestHandler()); JsonReader<Object, Object> reader = new JsonReader<>(null, new TestHandler());
reader.parse(); reader.parse();
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void parseReaderRejectsNegativeBufferSize() throws IOException { public void parseReaderRejectsNegativeBufferSize() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader("[]"), new TestHandler()); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader("[]"), new TestHandler());
reader.parse(-1); reader.parse(-1);
});
} }
@Test @Test
@ -72,7 +60,7 @@ public class JsonReaderTest extends TestUtil {
@Test @Test
public void parseReaderRejectsEmpty() { public void parseReaderRejectsEmpty() {
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(""), new TestHandler()); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(""), new TestHandler());
JsonException exception = assertException(JsonException.class, (RunnableEx) reader::parse); JsonException exception = Assertions.assertThrows(JsonException.class, reader::parse);
assertThat(exception.getMessage(), startsWith("Unexpected end of input")); assertThat(exception.getMessage(), startsWith("Unexpected end of input"));
} }
@ -253,7 +241,7 @@ public class JsonReaderTest extends TestUtil {
final String input = "{\n \"a\": 23,\n \"b\": 42,\n}"; final String input = "{\n \"a\": 23,\n \"b\": 42,\n}";
TestHandler handler = new TestHandler(); TestHandler handler = new TestHandler();
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler);
assertException(JsonException.class, (RunnableEx) () -> reader.parse(3)); Assertions.assertThrows(JsonException.class, () -> reader.parse(3));
} }
@Test @Test
@ -265,7 +253,7 @@ public class JsonReaderTest extends TestUtil {
final String input = array.toString(); final String input = array.toString();
TestHandler handler = new TestHandler(); TestHandler handler = new TestHandler();
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler);
JsonException exception = assertException(JsonException.class, (RunnableEx) reader::parse); JsonException exception = Assertions.assertThrows(JsonException.class, reader::parse);
assertEquals("Nesting too deep", exception.getMessage()); assertEquals("Nesting too deep", exception.getMessage());
} }
@ -278,7 +266,7 @@ public class JsonReaderTest extends TestUtil {
final String input = object.toString(); final String input = object.toString();
TestHandler handler = new TestHandler(); TestHandler handler = new TestHandler();
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler);
JsonException exception = assertException(JsonException.class, (RunnableEx) reader::parse); JsonException exception = Assertions.assertThrows(JsonException.class, reader::parse);
assertEquals("Nesting too deep", exception.getMessage()); assertEquals("Nesting too deep", exception.getMessage());
} }
@ -291,7 +279,7 @@ public class JsonReaderTest extends TestUtil {
final String input = value.toString(); final String input = value.toString();
TestHandler handler = new TestHandler(); TestHandler handler = new TestHandler();
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(input), handler);
JsonException exception = assertException(JsonException.class, (RunnableEx) reader::parse); JsonException exception = Assertions.assertThrows(JsonException.class, reader::parse);
assertEquals("Nesting too deep", exception.getMessage()); assertEquals("Nesting too deep", exception.getMessage());
} }
@ -686,8 +674,7 @@ public class JsonReaderTest extends TestUtil {
private void assertParseException(int offset, String message, final String json) { private void assertParseException(int offset, String message, final String json) {
TestHandler handler = new TestHandler(); TestHandler handler = new TestHandler();
JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(json), handler); JsonReader<Object, Object> reader = new JsonReader<>(new StringReader(json), handler);
JsonException exception = Assertions.assertThrows(JsonException.class, () -> {
JsonException exception = assertException(JsonException.class, (Runnable) () -> {
try { try {
reader.parse(); reader.parse();
} catch (IOException e) { } catch (IOException e) {

View file

@ -1,65 +1,42 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Assertions;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
/** public class JsonStringTest {
*
*/
public class JsonStringTest extends TestUtil {
private StringWriter stringWriter; private StringWriter stringWriter;
private JsonWriter jsonWriter; private JsonWriter jsonWriter;
@Before @BeforeEach
public void setUp() { public void setUp() {
stringWriter = new StringWriter(); stringWriter = new StringWriter();
jsonWriter = new JsonWriter(stringWriter); jsonWriter = new JsonWriter(stringWriter);
} }
@Test @Test
public void constructor_failsWithNull() { public void constructorFailsWithNull() {
assertException(NullPointerException.class, null, new Runnable() { Assertions.assertThrows(NullPointerException.class, () -> {
public void run() {
new JsonString(null); new JsonString(null);
}
}); });
} }
@Test @Test
public void write() throws IOException { public void write() throws IOException {
new JsonString("foo").write(jsonWriter); new JsonString("foo").write(jsonWriter);
assertEquals("\"foo\"", stringWriter.toString()); assertEquals("\"foo\"", stringWriter.toString());
} }
@Test @Test
public void write_escapesStrings() throws IOException { public void writeEscapesStrings() throws IOException {
new JsonString("foo\\bar").write(jsonWriter); new JsonString("foo\\bar").write(jsonWriter);
assertEquals("\"foo\\\\bar\"", stringWriter.toString()); assertEquals("\"foo\\\\bar\"", stringWriter.toString());
} }
@ -74,41 +51,40 @@ public class JsonStringTest extends TestUtil {
} }
@Test @Test
public void equals_trueForSameInstance() { public void equalsTrueForSameInstance() {
JsonString string = new JsonString("foo"); JsonString string = new JsonString("foo");
assertEquals(string, string); assertEquals(string, string);
} }
@Test @Test
public void equals_trueForEqualStrings() { public void equalsTrueForEqualStrings() {
assertEquals(new JsonString("foo"), new JsonString("foo")); assertEquals(new JsonString("foo"), new JsonString("foo"));
} }
@Test @Test
public void equals_falseForDifferentStrings() { public void equalsFalseForDifferentStrings() {
assertNotEquals(new JsonString(""), new JsonString("foo")); assertNotEquals(new JsonString(""), new JsonString("foo"));
assertNotEquals(new JsonString("foo"), new JsonString("bar")); assertNotEquals(new JsonString("foo"), new JsonString("bar"));
} }
@Test @Test
public void equals_falseForNull() { public void equalsFalseForNull() {
assertNotEquals(null, new JsonString("foo")); assertNotEquals(null, new JsonString("foo"));
} }
@Test @Test
public void equals_falseForSubclass() { public void equalsFalseForSubclass() {
assertNotEquals(new JsonString("foo"), new JsonString("foo") { assertNotEquals(new JsonString("foo"), new JsonString("foo") {
}); });
} }
@Test @Test
public void hashCode_equalsForEqualStrings() { public void hashCodeEqualsForEqualStrings() {
assertEquals(new JsonString("foo").hashCode(), new JsonString("foo").hashCode()); assertEquals(new JsonString("foo").hashCode(), new JsonString("foo").hashCode());
} }
@Test @Test
public void hashCode_differsForDifferentStrings() { public void hashCodeDiffersForDifferentStrings() {
assertNotEquals(new JsonString("").hashCode(), new JsonString("foo").hashCode()); assertNotEquals(new JsonString("").hashCode(), new JsonString("foo").hashCode());
assertNotEquals(new JsonString("foo").hashCode(), new JsonString("bar").hashCode()); assertNotEquals(new JsonString("foo").hashCode(), new JsonString("bar").hashCode());
} }

View file

@ -1,35 +1,15 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
/** public class JsonTest {
*
*/
public class JsonTest extends TestUtil {
@Test @Test
public void literalConstants() { public void literalConstants() {
@ -72,14 +52,15 @@ public class JsonTest extends TestUtil {
@Test @Test
public void valueFloatFailsWithInfinity() { public void valueFloatFailsWithInfinity() {
String message = "Infinite and NaN values not permitted in JSON"; String message = "Infinite and NaN values not permitted in JSON";
assertException(IllegalArgumentException.class, message, Assertions.assertThrows(IllegalArgumentException.class,
(Runnable) () -> Json.of(Float.POSITIVE_INFINITY)); () -> Json.of(Float.POSITIVE_INFINITY), message);
} }
@Test @Test
public void valuefloatfailsWithNaN() { public void valuefloatfailsWithNaN() {
String message = "Infinite and NaN values not permitted in JSON"; String message = "Infinite and NaN values not permitted in JSON";
assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.of(Float.NaN)); Assertions.assertThrows(IllegalArgumentException.class,
() -> Json.of(Float.NaN), message);
} }
@Test @Test
@ -100,13 +81,15 @@ public class JsonTest extends TestUtil {
@Test @Test
public void valuedoublefailsWithInfinity() { public void valuedoublefailsWithInfinity() {
String message = "Infinite and NaN values not permitted in JSON"; String message = "Infinite and NaN values not permitted in JSON";
assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.of(Double.POSITIVE_INFINITY)); Assertions.assertThrows(IllegalArgumentException.class,
() -> Json.of(Double.POSITIVE_INFINITY), message);
} }
@Test @Test
public void valuedoublefailsWithNaN() { public void valuedoublefailsWithNaN() {
String message = "Infinite and NaN values not permitted in JSON"; String message = "Infinite and NaN values not permitted in JSON";
assertException(IllegalArgumentException.class, message, (Runnable) () -> Json.of(Double.NaN)); Assertions.assertThrows(IllegalArgumentException.class,
() -> Json.of(Double.NaN), message);
} }
@Test @Test
@ -140,7 +123,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void arrayintfailsWithNull() { public void arrayintfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> Json.array((int[]) null)); Assertions.assertThrows(NullPointerException.class, () -> Json.array((int[]) null));
} }
@Test @Test
@ -151,7 +134,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void arraylongfailsWithNull() { public void arraylongfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> Json.array((long[]) null)); Assertions.assertThrows(NullPointerException.class, () -> Json.array((long[]) null));
} }
@Test @Test
@ -162,7 +145,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void arrayfloatfailsWithNull() { public void arrayfloatfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> Json.array((float[]) null)); Assertions.assertThrows(NullPointerException.class, () -> Json.array((float[]) null));
} }
@Test @Test
@ -173,7 +156,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void arraydoublefailsWithNull() { public void arraydoublefailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> Json.array((double[]) null)); Assertions.assertThrows(NullPointerException.class, () -> Json.array((double[]) null));
} }
@Test @Test
@ -184,7 +167,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void arraybooleanfailsWithNull() { public void arraybooleanfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> Json.array((boolean[]) null)); Assertions.assertThrows(NullPointerException.class, () -> Json.array((boolean[]) null));
} }
@Test @Test
@ -195,7 +178,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void arraystringfailsWithNull() { public void arraystringfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> Json.array((String[]) null)); Assertions.assertThrows(NullPointerException.class, () -> Json.array((String[]) null));
} }
@Test @Test
@ -210,13 +193,7 @@ public class JsonTest extends TestUtil {
@Test @Test
public void parsestringfailsWithNull() { public void parsestringfailsWithNull() {
assertException(NullPointerException.class, null, (Runnable) () -> { Assertions.assertThrows(NullPointerException.class, () -> Json.parse((String) null));
try {
Json.parse((String) null);
} catch (IOException e) {
//
}
});
} }
@Test @Test

View file

@ -1,42 +1,22 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
/**
*
*/
public class JsonWriterTest { public class JsonWriterTest {
private StringWriter output; private StringWriter output;
private JsonWriter writer; private JsonWriter writer;
private static String string(char... chars) { private static String string(char... chars) {
return String.valueOf(chars); return String.valueOf(chars);
} }
@Before @BeforeEach
public void setUp() { public void setUp() {
output = new StringWriter(); output = new StringWriter();
writer = new JsonWriter(output); writer = new JsonWriter(output);

View file

@ -1,34 +1,16 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.xbib.marc.StreamMatcher.assertStream; import static org.xbib.marc.StreamMatcher.assertStream;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcRecordAdapter; import org.xbib.marc.MarcRecordAdapter;
import org.xbib.marc.MarcXchangeConstants; import org.xbib.marc.MarcXchangeConstants;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
import org.xbib.marc.xml.MarcContentHandler; import org.xbib.marc.xml.MarcContentHandler;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -37,9 +19,6 @@ import java.nio.charset.Charset;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.EnumSet; import java.util.EnumSet;
/**
*
*/
public class MarcJsonWriterTest { public class MarcJsonWriterTest {
/** /**

View file

@ -1,38 +1,17 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.xbib.marc.json.JsonWriterConfig.prettyPrint; import static org.xbib.marc.json.JsonWriterConfig.prettyPrint;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.util.Locale; import java.util.Locale;
/**
*
*/
public class PrettyPrintTest { public class PrettyPrintTest {
@Test @Test

View file

@ -1,23 +1,7 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.json; package org.xbib.marc.json;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -46,7 +30,7 @@ public class TestUtil {
public static <T extends Exception> T assertException(Class<T> type, RunnableEx runnable) { public static <T extends Exception> T assertException(Class<T> type, RunnableEx runnable) {
T exception = catchException(runnable, type); T exception = catchException(runnable, type);
assertNotNull("Expected exception: " + type.getName(), exception); assertNotNull(exception, "Expected exception: " + type.getName());
return exception; return exception;
} }

View file

@ -1,24 +1,8 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.label; package org.xbib.marc.label;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Assertions;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* *
@ -37,10 +21,12 @@ public class RecordLabelTest {
assertEquals(2, recordLabel.getIndicatorLength()); assertEquals(2, recordLabel.getIndicatorLength());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testIllegalIndicatorLength() { public void testIllegalIndicatorLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setIndicatorLength(10).build(); RecordLabel recordLabel = RecordLabel.builder().setIndicatorLength(10).build();
assertEquals(10, recordLabel.getIndicatorLength()); assertEquals(10, recordLabel.getIndicatorLength());
});
} }
@Test @Test
@ -49,15 +35,19 @@ public class RecordLabelTest {
assertEquals(2, recordLabel.getSubfieldIdentifierLength()); assertEquals(2, recordLabel.getSubfieldIdentifierLength());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testIllegalSubfieldIdentifierLength() { public void testIllegalSubfieldIdentifierLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setSubfieldIdentifierLength(10).build(); RecordLabel recordLabel = RecordLabel.builder().setSubfieldIdentifierLength(10).build();
assertEquals(10, recordLabel.getSubfieldIdentifierLength()); assertEquals(10, recordLabel.getSubfieldIdentifierLength());
});
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testNegativeMaxRecordLength() { public void testNegativeMaxRecordLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setRecordLength(-1).build(); RecordLabel recordLabel = RecordLabel.builder().setRecordLength(-1).build();
});
} }
@Test @Test
@ -66,9 +56,11 @@ public class RecordLabelTest {
assertEquals(9999, recordLabel.getRecordLength()); assertEquals(9999, recordLabel.getRecordLength());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testOverflowRecordLength() { public void testOverflowRecordLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setRecordLength(10000).build(); RecordLabel recordLabel = RecordLabel.builder().setRecordLength(10000).build();
});
} }
@Test @Test
@ -83,10 +75,12 @@ public class RecordLabelTest {
assertEquals(5, recordLabel.getDataFieldLength()); assertEquals(5, recordLabel.getDataFieldLength());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testIllegalDataFieldLength() { public void testIllegalDataFieldLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setDataFieldLength(10).build(); RecordLabel recordLabel = RecordLabel.builder().setDataFieldLength(10).build();
assertEquals(10, recordLabel.getDataFieldLength()); assertEquals(10, recordLabel.getDataFieldLength());
});
} }
@Test @Test
@ -95,10 +89,12 @@ public class RecordLabelTest {
assertEquals(4, recordLabel.getStartingCharacterPositionLength()); assertEquals(4, recordLabel.getStartingCharacterPositionLength());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testIllegalStartingCharacterPositionLength() { public void testIllegalStartingCharacterPositionLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setStartingCharacterPositionLength(10).build(); RecordLabel recordLabel = RecordLabel.builder().setStartingCharacterPositionLength(10).build();
assertEquals(10, recordLabel.getStartingCharacterPositionLength()); assertEquals(10, recordLabel.getStartingCharacterPositionLength());
});
} }
@Test @Test
@ -107,10 +103,12 @@ public class RecordLabelTest {
assertEquals(2, recordLabel.getSegmentIdentifierLength()); assertEquals(2, recordLabel.getSegmentIdentifierLength());
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testIllegalSegmentIdentifierLength() { public void testIllegalSegmentIdentifierLength() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
RecordLabel recordLabel = RecordLabel.builder().setSegmentIdentifierLength(10).build(); RecordLabel recordLabel = RecordLabel.builder().setSegmentIdentifierLength(10).build();
assertEquals(10, recordLabel.getSegmentIdentifierLength()); assertEquals(10, recordLabel.getSegmentIdentifierLength());
});
} }
@Test @Test

View file

@ -0,0 +1,130 @@
package org.xbib.marc.tools;
import org.junit.contrib.java.lang.system.internal.CheckExitCalled;
import org.junit.contrib.java.lang.system.internal.NoExitSecurityManager;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import org.junit.jupiter.api.extension.ExtensionContext.Store;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
import org.junit.platform.commons.support.ReflectionSupport;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.System.getSecurityManager;
import static java.lang.System.setSecurityManager;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* This class is original inspired from project {@code system-rules},
* rewrite it to JUnit5. It is a JUnit Jupiter extension that allows
* in-test specification of expected {@code System.exit(...)} calls.
*/
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@ExtendWith(ExpectedSystemExit.Extension.class)
public @interface ExpectedSystemExit {
class Extension implements BeforeEachCallback,
AfterEachCallback,
BeforeAllCallback,
ParameterResolver,
TestExecutionExceptionHandler {
private NoExitSecurityManager noExitSecurityManager;
private SecurityManager originalManager;
@Override
public void beforeAll(ExtensionContext context) {
noExitSecurityManager = new NoExitSecurityManager(getSecurityManager());
}
@Override
public void beforeEach(ExtensionContext context) {
originalManager = getSecurityManager();
setSecurityManager(noExitSecurityManager);
}
@Override
public void afterEach(ExtensionContext context) {
NoExitSecurityManager securityManager = (NoExitSecurityManager) getSecurityManager();
ExitCapture exitCapture = getExitCapture(context);
if (exitCapture.expectExit) {
checkSystemExit(securityManager, exitCapture);
}
setSecurityManager(originalManager);
}
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
boolean isTestMethodLevel = extensionContext.getTestMethod().isPresent();
boolean isOutputCapture = parameterContext.getParameter().getType() == ExitCapture.class;
return isTestMethodLevel && isOutputCapture;
}
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
return getExitCapture(extensionContext);
}
@Override
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
ExitCapture exitCapture = getExitCapture(context);
if (!(throwable instanceof CheckExitCalled) || !exitCapture.expectExit) {
throw throwable;
}
}
private void checkSystemExit(NoExitSecurityManager securityManager, ExitCapture exitCapture) {
if (securityManager.isCheckExitCalled()) {
exitCapture.handleSystemExitWithStatus(securityManager.getStatusOfFirstCheckExitCall());
} else {
exitCapture.handleMissingSystemExit();
}
}
private ExitCapture getExitCapture(ExtensionContext context) {
Store store = context.getStore(Namespace.create(getClass(), context.getRequiredTestMethod()));
return store.getOrComputeIfAbsent(ExitCapture.class, ReflectionSupport::newInstance, ExitCapture.class);
}
}
class ExitCapture {
private boolean expectExit = false;
private Integer expectedStatus = null;
public void expectSystemExit() {
expectExit = true;
}
public void expectSystemExitWithStatus(int status) {
expectSystemExit();
expectedStatus = status;
}
private void handleMissingSystemExit() {
if (expectExit) {
fail("System.exit has not been called.");
}
}
private void handleSystemExitWithStatus(int status) {
if (!expectExit) {
fail("Unexpected call of System.exit(" + status + ").");
} else if (expectedStatus != null) {
assertEquals(expectedStatus, Integer.valueOf(status), "Wrong exit status");
}
}
}
}

View file

@ -1,45 +1,25 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.tools; package org.xbib.marc.tools;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
/**
*/
public class ToolTest { public class ToolTest {
@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
@Test @Test
public void testToolSimple() throws Exception { @ExpectedSystemExit
public void testToolSimple(ExpectedSystemExit.ExitCapture exitCapture) {
String[] args = { String[] args = {
"--in", "src/test/resources/org/xbib/marc/chabon.mrc", "--in", "src/test/resources/org/xbib/marc/chabon.mrc",
"--charset", "ANSEL", "--charset", "ANSEL",
"--out", "build/chabon.mrc.xml" "--out", "build/chabon.mrc.xml"
}; };
exit.expectSystemExitWithStatus(0); exitCapture.expectSystemExitWithStatus(0);
MarcTool.main(args); MarcTool.main(args);
} }
@Test @Test
public void testToolStylesheet() throws Exception { @ExpectedSystemExit
public void testToolStylesheet(ExpectedSystemExit.ExitCapture exitCapture) {
String[] args = { String[] args = {
"--in", "src/test/resources/org/xbib/marc/summerland.mrc", "--in", "src/test/resources/org/xbib/marc/summerland.mrc",
"--out", "build/summerland.mrc.xml", "--out", "build/summerland.mrc.xml",
@ -48,7 +28,7 @@ public class ToolTest {
"--stylesheet", "http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3.xsl", "--stylesheet", "http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3.xsl",
"--result", "build/summerland.mods" "--result", "build/summerland.mods"
}; };
exit.expectSystemExitWithStatus(0); exitCapture.expectSystemExitWithStatus(0);
MarcTool.main(args); MarcTool.main(args);
} }
} }

View file

@ -1,27 +1,9 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.transformer; package org.xbib.marc.transformer;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.MarcField; import org.xbib.marc.MarcField;
import org.xbib.marc.transformer.field.MarcFieldTransformer; import org.xbib.marc.transformer.field.MarcFieldTransformer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View file

@ -1,36 +1,16 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.transformer; package org.xbib.marc.transformer;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.HEAD; import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.HEAD;
import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.TAIL; import static org.xbib.marc.transformer.field.MarcFieldTransformer.Operator.TAIL;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.MarcField; import org.xbib.marc.MarcField;
import org.xbib.marc.transformer.field.MarcFieldTransformer; import org.xbib.marc.transformer.field.MarcFieldTransformer;
import org.xbib.marc.transformer.field.MarcFieldTransformers; import org.xbib.marc.transformer.field.MarcFieldTransformers;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/**
*/
public class MarcFieldTransformersTest { public class MarcFieldTransformersTest {
@Test @Test

View file

@ -1,15 +1,11 @@
package org.xbib.marc.transformer; package org.xbib.marc.transformer;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.xbib.marc.MarcField; import org.xbib.marc.MarcField;
import org.xbib.marc.transformer.value.MarcValueTransformer; import org.xbib.marc.transformer.value.MarcValueTransformer;
import org.xbib.marc.transformer.value.MarcValueTransformers; import org.xbib.marc.transformer.value.MarcValueTransformers;
/**
*
*/
public class MarcValueTransformerTest { public class MarcValueTransformerTest {
@Test @Test

View file

@ -1,26 +1,10 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.xml; package org.xbib.marc.xml;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -28,7 +12,7 @@ import java.nio.charset.StandardCharsets;
/** /**
* *
*/ */
public class MarcEventConsumerTest extends Assert { public class MarcEventConsumerTest {
/** /**
* Parsing XML by STAX (streaming XML) from Aleph publishing interface (hbz dialect). * Parsing XML by STAX (streaming XML) from Aleph publishing interface (hbz dialect).

View file

@ -1,28 +1,11 @@
/*
Copyright 2016 Jörg Prante
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xbib.marc.xml; package org.xbib.marc.xml;
import org.junit.Assert; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.Test;
import org.xbib.marc.Marc; import org.xbib.marc.Marc;
import org.xbib.marc.MarcXchangeConstants; import org.xbib.marc.MarcXchangeConstants;
import org.xmlunit.matchers.CompareMatcher; import org.xmlunit.matchers.CompareMatcher;
import java.io.FileWriter;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -30,7 +13,7 @@ import java.nio.charset.StandardCharsets;
/** /**
* *
*/ */
public class MarcXMLTest extends Assert { public class MarcXMLTest {
/** /**
* Parsing MARC XML embedded in OAI response from DNB/ZDB. * Parsing MARC XML embedded in OAI response from DNB/ZDB.
@ -66,7 +49,6 @@ public class MarcXMLTest extends Assert {
} }
assertThat(sw.toString(), assertThat(sw.toString(),
CompareMatcher.isIdenticalTo(getClass().getResource(s + "-marcxchange.xml").openStream())); CompareMatcher.isIdenticalTo(getClass().getResource(s + "-marcxchange.xml").openStream()));
} }
/** /**

View file

@ -1,5 +0,0 @@
handlers = java.util.logging.ConsoleHandler
.level = INFO
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %1$tFT%1$tT.%1$tL%1$tz [%4$-11s] [%3$s] %5$s %6$s%n