Skip to content

[fj-doc-mod-fop] migrate junit4 to junit5 #361 #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fj-doc-mod-fop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
import org.fugerit.java.doc.mod.fop.FreeMarkerFopTypeHandlerUTF8;
import org.fugerit.java.doc.mod.fop.InitFopHandler;
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import lombok.extern.slf4j.Slf4j;
import test.org.fugerit.java.BasicTest;

@Slf4j
public class TestAlt extends BasicTest {
class TestAlt extends BasicTest {

@BeforeClass
public static void init() {
@BeforeAll
static void init() {
SafeFunction.apply( () -> InitFopHandler.initDoc() );
}

Expand All @@ -42,10 +42,10 @@ private boolean testHelper( DocTypeHandler handler ) {
private static final DocTypeHandler[] HANDLERS = { PdfFopTypeHandler.HANDLER, new FreeMarkerFopTypeHandlerUTF8() };

@Test
public void testAlt001Ok() {
void testAlt001Ok() {
for ( int k=0; k<HANDLERS.length; k++ ) {
boolean ok = this.testHelper(HANDLERS[k]);
Assert.assertTrue(ok);
Assertions.assertTrue(ok);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
import org.fugerit.java.core.function.SafeFunction;
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
import org.fugerit.java.doc.mod.fop.config.ResourceResolverWrapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import test.org.fugerit.java.BasicTest;

public class TestFopConfig extends BasicTest {
class TestFopConfig extends BasicTest {

@Test
public void testResolver1() {
Assert.assertNotNull( SafeFunction.get( () -> {
void testResolver1() {
Assertions.assertNotNull( SafeFunction.get( () -> {
FopConfigClassLoaderWrapper wrapper = new FopConfigClassLoaderWrapper( "test", ResourceResolverFactory.createDefaultResourceResolver() );
return this.fullSerializationTest( wrapper );
} ) );
}

@Test
public void testResolver2() {
Assert.assertNotNull( SafeFunction.get( () -> {
void testResolver2() {
Assertions.assertNotNull( SafeFunction.get( () -> {
FopConfigClassLoaderWrapper wrapper = new FopConfigClassLoaderWrapper( "test" );
return this.fullSerializationTest( wrapper );
} ) );
}

@Test
public void testResolver3() {
Assert.assertNotNull( SafeFunction.get( () -> {
void testResolver3() {
Assertions.assertNotNull( SafeFunction.get( () -> {
ResourceResolverWrapper rrw = new ResourceResolverWrapper( ResourceResolverFactory.createDefaultResourceResolver() );
FopConfigClassLoaderWrapper wrapper = new FopConfigClassLoaderWrapper( "test", rrw );
return this.fullSerializationTest( wrapper );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import org.fugerit.java.core.cfg.ConfigRuntimeException;
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestInitFreeMarkerConfig {
class TestInitFreeMarkerConfig {

@Test
public void restError() {
void restError() {
try {
FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj-test-error-config.xml" );
} catch (ConfigRuntimeException e) {
Assert.assertTrue( e.getMessage().contains( "Cannot find fop config path" ) );
Assertions.assertTrue( e.getMessage().contains( "Cannot find fop config path" ) );
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
import org.fugerit.java.doc.mod.fop.FopConfigDefault;
import org.fugerit.java.doc.mod.fop.InitFopHandler;
import org.fugerit.java.doc.mod.fop.PdfFopTypeHandler;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;

import lombok.extern.slf4j.Slf4j;
import test.org.fugerit.java.BasicTest;

@Slf4j
public class TestPdfFopTypeHandler extends BasicTest {
class TestPdfFopTypeHandler extends BasicTest {

@BeforeClass
public static void init() {
@BeforeAll
static void init() {
SafeFunction.apply( () -> InitFopHandler.initDocAsync() );
}

Expand All @@ -43,14 +43,14 @@ private boolean testHelper( DocTypeHandler handler ) {
}

@Test
public void test001Ok() {
void test001Ok() {
FopConfig config = new FopConfigDefault();
PdfFopTypeHandler handler = new PdfFopTypeHandler();
handler.setSuppressEvents( true );
log.info( "suppress events : {}", handler.isSuppressEvents() );
handler.setFopConfig( config );
boolean ok = this.testHelper(handler);
Assert.assertTrue(ok);
Assertions.assertTrue(ok);
}

private boolean configureHelper( String path ) {
Expand All @@ -67,22 +67,22 @@ private boolean configureHelper( String path ) {
}

@Test
public void test002Ko() {
Assert.assertThrows( ConfigRuntimeException.class , () -> {
void test002Ko() {
Assertions.assertThrows( ConfigRuntimeException.class , () -> {
this.configureHelper( "config/test_config_err1.xml" );
});
}


@Test
public void test003Ok() {
void test003Ok() {
boolean ok = this.configureHelper( "config/test_config_ok.xml" );
Assert.assertTrue(ok);
Assertions.assertTrue(ok);
}

@Test
public void test004Ko() {
Assert.assertThrows( ConfigRuntimeException.class , () -> {
void test004Ko() {
Assertions.assertThrows( ConfigRuntimeException.class , () -> {
this.configureHelper( "config/test_config_err2.xml" );
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,32 @@
import org.fugerit.java.core.xml.dom.DOMIO;
import org.fugerit.java.doc.base.config.DocInput;
import org.fugerit.java.doc.base.config.DocOutput;
import org.fugerit.java.doc.base.config.DocTypeHandler;
import org.fugerit.java.doc.mod.fop.*;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import test.org.fugerit.java.BasicTest;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
public class TestPdfFopTypePooledHandler extends BasicTest {
class TestPdfFopTypePooledHandler extends BasicTest {

@Test
public void testPoolUtils() throws ConfigException {
void testPoolUtils() throws ConfigException {
UnsafeSupplier<FopConfigWrap, ConfigException> supplier = () -> new FopConfigWrap( null, null );
FopConfigWrap configWrap1 = PoolUtils.handleFopWrap( null, null, 1, 2, supplier );
Assert.assertNotNull( configWrap1 );
Assertions.assertNotNull( configWrap1 );
FopConfigWrap configWrap2 = PoolUtils.handleFopWrap( null, new ArrayList<FopConfigWrap>(), 1, 2, supplier );
Assert.assertNotNull( configWrap2 );
Assertions.assertNotNull( configWrap2 );
}

@Test
public void pooledTest1() throws ConfigException, XMLException {
void pooledTest1() throws ConfigException, XMLException {
PdfFopTypeHandler handler = new PdfFopTypeHandler();

Element config = DOMIO.loadDOMDoc( "<conf><docHandlerCustomConfig fop-pool-min='1' fop-pool-max='1' fop-suppress-events='2'/></conf>" ).getDocumentElement();
Expand All @@ -50,7 +46,7 @@ public void pooledTest1() throws ConfigException, XMLException {
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "sample/doc_test_01.xml" ) );
FileOutputStream fos = new FileOutputStream( outputFile ) ) {
handler.handle( DocInput.newInput( handler.getType(), reader ) , DocOutput.newOutput( fos ) );
Assert.assertTrue( outputFile.exists() );
Assertions.assertTrue( outputFile.exists() );
} catch (Exception e) {
this.failEx( e );
}
Expand All @@ -59,20 +55,20 @@ public void pooledTest1() throws ConfigException, XMLException {
t.start();
log.info( "thread started : {}", k );
}
Assert.assertTrue( Boolean.TRUE );
Assertions.assertTrue( Boolean.TRUE );
}


@Test
public void pooledTest2() {
void pooledTest2() {
PdfFopTypeHandler handler = new PdfFopTypeHandler();
File outputFile = new File( "target/test"+System.currentTimeMillis()+"."+handler.getType() );
try ( InputStreamReader reader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "sample/doc_test_01.xml" ) );
FileOutputStream fos = new FileOutputStream( outputFile ) ) {
Element config = DOMIO.loadDOMDoc( "<conf><docHandlerCustomConfig fop-pool-min='10' fop-suppress-events='1'/></conf>" ).getDocumentElement();
handler.configure( config );
handler.handle( DocInput.newInput( handler.getType(), reader ) , DocOutput.newOutput( fos ) );
Assert.assertTrue( outputFile.exists() );
Assertions.assertTrue( outputFile.exists() );
} catch (Exception e) {
this.failEx( e );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,57 @@
import org.fugerit.java.doc.mod.fop.config.ClassLoaderResourceResolverWrapper;
import org.fugerit.java.doc.mod.fop.config.FopConfigClassLoaderWrapper;
import org.fugerit.java.doc.mod.fop.config.ResourceResolverWrapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import lombok.extern.slf4j.Slf4j;
import test.org.fugerit.java.BasicTest;

@Slf4j
public class TestResourceResolver extends BasicTest {
class TestResourceResolver extends BasicTest {

@Test
public void testResourceResolverWrapper() throws IOException {
@Test
void testResourceResolverWrapper() throws IOException {
File target = new File( "target" );
ResourceResolverWrapper wrapper = new ResourceResolverWrapper( new DoNothingResourceResolver() );
log.info( "wrapper : {} : {}", wrapper, wrapper.unwrap() );
Assert.assertNotNull( this.fullSerializationTest( wrapper ) );
Assert.assertNull( wrapper.getResource( target.toURI() ) );
Assert.assertNull( wrapper.getOutputStream( target.toURI() ) );
Assertions.assertNotNull( this.fullSerializationTest( wrapper ) );
Assertions.assertNull( wrapper.getResource( target.toURI() ) );
Assertions.assertNull( wrapper.getOutputStream( target.toURI() ) );
}

@Test
public void testClassLoaderResourceResolverWrapper() throws IOException, URISyntaxException {
void testClassLoaderResourceResolverWrapper() throws IOException, URISyntaxException {
ClassLoaderResourceResolverWrapper rr = new ClassLoaderResourceResolverWrapper();
File target = new File( "target/test.txt" );
rr.wrap( new DoNothingResourceResolver() );
URI u = new URI( ClassLoaderResourceResolverWrapper.CLASSPATH_SCHEMA+"sample/doc_alt_01.xml" );
log.info( "wrapper : {} : {}", rr, rr.unwrap() );
Assert.assertNotNull( rr.getResource( u ) );
Assert.assertNull( rr.getResource( target.toURI() ) );
Assert.assertNull( rr.getOutputStream( target.toURI() ) );
Assertions.assertNotNull( rr.getResource( u ) );
Assertions.assertNull( rr.getResource( target.toURI() ) );
Assertions.assertNull( rr.getOutputStream( target.toURI() ) );
}

@Test
public void testFopConfigClassLoaderWrapper() throws IOException, ConfigException {
void testFopConfigClassLoaderWrapper() throws IOException, ConfigException {
FopConfigClassLoaderWrapper config1 = new FopConfigClassLoaderWrapper( "fop-config.xml" );
Assert.assertNotNull( config1.newFactory() );
Assertions.assertNotNull( config1.newFactory() );
FopConfigClassLoaderWrapper config2 = new FopConfigClassLoaderWrapper( "fop-config-pdfa.xml" );
Assert.assertNotNull( config2.newFactory() );
Assertions.assertNotNull( config2.newFactory() );
FopConfigClassLoaderWrapper config3 = new FopConfigClassLoaderWrapper( "fop-config-pdfua.xml" );
Assert.assertNotNull( config3.newFactory() );
Assert.assertNotNull( new PdfFopTypeHandler( StandardCharsets.UTF_8 , config3) );
Assert.assertNotNull( new PdfFopTypeHandler( StandardCharsets.UTF_8 , false, false ) );
Assert.assertNotNull( new PdfFopTypeHandler( StandardCharsets.UTF_8 ) );
Assert.assertNotNull( config1.getCustomResourceResolver() );
Assertions.assertNotNull( config3.newFactory() );
Assertions.assertNotNull( new PdfFopTypeHandler( StandardCharsets.UTF_8 , config3) );
Assertions.assertNotNull( new PdfFopTypeHandler( StandardCharsets.UTF_8 , false, false ) );
Assertions.assertNotNull( new PdfFopTypeHandler( StandardCharsets.UTF_8 ) );
Assertions.assertNotNull( config1.getCustomResourceResolver() );
}

@Test
public void testFmConfig() throws Exception {
void testFmConfig() throws Exception {
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fm-config.xml" );
for ( DocTypeHandler handler : config.getFacade().handlers() ) {
log.info( "init handler : {}", handler );
Assert.assertTrue( InitHandler.initDoc( handler ) );
Assertions.assertTrue( InitHandler.initDoc( handler ) );
}
}

Expand Down