Skip to content

[fj-doc-feeemarker] migrate junit4 to junit5 #324 #328

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 17, 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-freemarker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,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 @@ -15,16 +15,16 @@
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerUTF8;
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandler;
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8;
import org.junit.Assert;
import org.junit.Test;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

@Slf4j
public class TestFreemarkerCoverage {
class TestFreemarkerCoverage {

private final static TestEntry[] TEST_LIST = {
new TestEntry( "default_doc" , true ),
Expand Down Expand Up @@ -58,16 +58,16 @@ private boolean worker( String path, boolean result ) {
}

@Test
public void test01() {
void test01() {
Arrays.asList( TEST_LIST ).stream().forEach( c -> {
log.info( "test -> {}", c );
Assert.assertTrue( this.worker( "coverage/xml/"+c.getId()+".xml", c.isResult() ) );
Assertions.assertTrue( this.worker( "coverage/xml/"+c.getId()+".xml", c.isResult() ) );
} );
Assert.assertTrue( Boolean.TRUE );
Assertions.assertTrue( Boolean.TRUE );
}

@Test
public void testAsciidoc() {
void testAsciidoc() {
String docId = "asciidoc";
DocTypeHandler handler = FreeMarkerAsciidocTypeHandler.HANDLER_UTF8;
String type = DocConfig.TYPE_ADOC;
Expand All @@ -78,7 +78,7 @@ public void testAsciidoc() {
handler.handle( DocInput.newInput( handler.getType() , reader ) , DocOutput.newOutput( fos ) );
}
} );
Assert.assertTrue( outputFile.exists() );
Assertions.assertTrue( outputFile.exists() );
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import org.fugerit.java.doc.base.process.DocProcessContext;
import org.fugerit.java.doc.freemarker.config.FreeMarkerConstants;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestFreeMarkerConstants {
class TestFreeMarkerConstants {

@Test
public void testFreeMarkerConstants() {
Assert.assertNotNull(FreeMarkerConstants.getFreeMarkerMap(DocProcessContext.newContext()));
void testFreeMarkerConstants() {
Assertions.assertNotNull(FreeMarkerConstants.getFreeMarkerMap(DocProcessContext.newContext()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@
import org.fugerit.java.doc.base.process.DocProcessContext;
import org.fugerit.java.doc.base.process.DocProcessData;
import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Properties;

public class TestFreemarkerConfigStep {
class TestFreemarkerConfigStep {

@Test
public void test() throws Exception {
void test() throws Exception {
Properties params = new Properties();
FreeMarkerConfigStep step = new FreeMarkerConfigStep();
step.setCustomConfig( params );
DocProcessContext context = new DocProcessContext();
DocProcessData data = new DocProcessData();
Assert.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
Assertions.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
params.setProperty( "id", "FJ_DOC_TEST_1" );
params.setProperty( "version", "2.3.31" );
params.setProperty( "mode", "class" );
Assert.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
Assertions.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
params.setProperty( "id", "FJ_DOC_TEST_2" );
params.setProperty( "path", "/fj_doc_test/template/" );
params.setProperty( "class", "org.fugerit.java.doc.freemarker.fun.ImageBase64CLFun" );
params.setProperty( "exception-handler", "RETHROW_HANDLER" );
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
params.setProperty( "id", "FJ_DOC_TEST_3" );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE, FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE_FOLDER );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH, "target" );
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
params.setProperty( "id", "FJ_DOC_TEST_4" );
params.remove( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS );
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
params.setProperty( "id", "FJ_DOC_TEST_5" );
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOAD_BUNDLED_FUN, BooleanUtils.BOOLEAN_TRUE);
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package test.org.fugerit.java.doc.freemarker.process;

import static org.junit.Assert.fail;

import java.io.*;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -29,19 +28,19 @@
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig;
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade;
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigValidator;
import org.junit.Assert;
import org.junit.Test;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import test.org.fugerit.java.BasicTest;

@Slf4j
public class TestFreemarkerDocProcessConfig extends BasicTest {
class TestFreemarkerDocProcessConfig extends BasicTest {

private static final String MAIN_CONFIG = "fj_doc_test/freemarker-doc-process.xml";

@Test
public void testConfigRead001() throws Exception {
void testConfigRead001() throws Exception {
String[] configList = { MAIN_CONFIG, "fj_doc_test/freemarker-doc-process-1.xml", "fj_doc_test/freemarker-doc-process-2.xml", "fj_doc_test/freemarker-doc-process-3.xml" };
for ( int k=0 ;k<configList.length ;k++ ) {
String currentConfig = configList[k];
Expand All @@ -50,7 +49,7 @@ public void testConfigRead001() throws Exception {
String chainId = "sample_chain";
String type = DocConfig.TYPE_HTML;
log.info( "config {}", config.getChain( chainId ) );
Assert.assertNotNull( config );
Assertions.assertNotNull( config );
try (FileOutputStream fos = new FileOutputStream( new File( "target", chainId+"_"+k+"."+type ) ) ) {
config.fullProcess( chainId, DocProcessContext.newContext(), DocConfig.TYPE_HTML, fos );
}
Expand All @@ -59,7 +58,7 @@ public void testConfigRead001() throws Exception {
try (ByteArrayOutputStream fos = new ByteArrayOutputStream() ) {
DocProcessContext context = DocProcessContext.newContext().withSourceType( DocFacadeSource.SOURCE_TYPE_XML );
if ( k == 0 || k == 2 ) {
Assert.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( chainIdError, context, DocConfig.TYPE_HTML, fos ) );
Assertions.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( chainIdError, context, DocConfig.TYPE_HTML, fos ) );
} else {
config.fullProcess( chainIdError, context, DocConfig.TYPE_HTML, fos );
}
Expand All @@ -69,7 +68,7 @@ public void testConfigRead001() throws Exception {
}

@Test
public void testSource() throws Exception {
void testSource() throws Exception {
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://"+MAIN_CONFIG );
String[] chainId = { "xml", "json", "yaml" };
for ( int k=0 ;k<chainId.length ;k++ ) {
Expand All @@ -84,12 +83,12 @@ public void testSource() throws Exception {
// test template does not exist
try ( ByteArrayOutputStream os = new ByteArrayOutputStream() ) {
DocProcessContext context = DocProcessContext.newContext();
Assert.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( "not-exists", context, DocConfig.TYPE_HTML, os ) );
Assertions.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( "not-exists", context, DocConfig.TYPE_HTML, os ) );
}
}

@Test
public void testSkipFM() throws Exception {
void testSkipFM() throws Exception {
DocProcessContext context = DocProcessContext.newContext();
DocProcessData data = new DocProcessData();
FreeMarkerConfigStep configStep = new FreeMarkerConfigStep();
Expand All @@ -103,23 +102,23 @@ public void testSkipFM() throws Exception {
FreeMarkerSkipProcessStep step = new FreeMarkerSkipProcessStep();
step.setParam01( "asciidoc-xml.ftl" );
step.process( context, data );
Assert.assertNotNull( data.getCurrentXmlData() );
Assertions.assertNotNull( data.getCurrentXmlData() );
}

@Test
public void testConfigFail01() {
Assert.assertThrows( ConfigRuntimeException.class , () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://not-exists.xml" ) );
void testConfigFail01() {
Assertions.assertThrows( ConfigRuntimeException.class , () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://not-exists.xml" ) );
}

@Test
public void testConfigFail02() {
void testConfigFail02() {
Reader reader = null;
Assert.assertThrows( ConfigException.class , () -> FreemarkerDocProcessConfigFacade.loadConfig( reader ) );
Assertions.assertThrows( ConfigException.class , () -> FreemarkerDocProcessConfigFacade.loadConfig( reader ) );
}

@Test
public void testConfigSec() {
Assert.assertNotNull( FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj_doc_test/freemarker-doc-process_sec.xml" ) );
void testConfigSec() {
Assertions.assertNotNull( FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj_doc_test/freemarker-doc-process_sec.xml" ) );
}


Expand All @@ -138,66 +137,66 @@ private void templateTesting( FreemarkerDocProcessConfig config ) {
runTestEx( () -> {
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
// need to make it work in the future!
Assert.assertThrows( NullPointerException.class, () -> {
Assertions.assertThrows( NullPointerException.class, () -> {
config.process( "test_01_inline", DocConfig.TYPE_MD, context, baos, false );
} );
}
} );
Assert.assertThrows( ConfigException.class , () -> {
Assertions.assertThrows( ConfigException.class , () -> {
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
config.process( "test_01_fail", DocConfig.TYPE_MD, context, baos, false );
}
} );
}

@Test
public void testConfigRead002() {
void testConfigRead002() {
FreemarkerDocProcessConfig config =
FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj_doc_test/freemarker-doc-process_alt.xml" );
Assert.assertNotNull( config );
Assertions.assertNotNull( config );
this.templateTesting(config);
log.info( "keys : {}", config.getKeys() );
}

@Test
public void testConfigValidate001() {
void testConfigValidate001() {
try ( Reader xmlReader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "fj_doc_test/freemarker-doc-process.xml" ) ) ) {
FreemarkerDocProcessConfigValidator.logValidation( xmlReader );
} catch (Exception e) {
String message = "Error : "+e;
log.error( message, e );
fail(message);
Assertions.fail(message);
}
}

@Test
public void testNewSimpleConfig() {
void testNewSimpleConfig() {
try {
Assert.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-001", "/template").getChainCache( "test" ) );
Assertions.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-001", "/template").getChainCache( "test" ) );
} catch (Exception e) {
this.failEx(e);
}
}

@Test
public void testNewSimpleConfigVersion() {
void testNewSimpleConfigVersion() {
try {
Assert.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-002", "/template", FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 ).getChainCache( "test" ) );
Assertions.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-002", "/template", FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 ).getChainCache( "test" ) );
} catch (Exception e) {
this.failEx(e);
}
}

@Test
public void testProcess() {
void testProcess() {
SafeFunction.apply( () -> {
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-003", "/fj_doc_test/template/" );
config.getFacade().registerHandler( FreeMarkerHtmlTypeHandlerUTF8.HANDLER );
// test full process
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
DocProcessData data = config.fullProcess( "test_02" ,
DocProcessContext.newContext(), DocConfig.TYPE_HTML, baos );
Assert.assertNotEquals( 0 , data.getCurrentXmlData().length() );
Assertions.assertNotEquals( 0 , data.getCurrentXmlData().length() );
}
// test process 1
// handler list :
Expand All @@ -210,27 +209,27 @@ public void testProcess() {
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
DocProcessData data = new DocProcessData();
config.process( "test_02" , DocProcessContext.newContext( "testKey", "<test/>" ), data, FreeMarkerHtmlTypeHandlerUTF8.HANDLER, DocOutput.newOutput(baos) );
Assert.assertNotEquals( 0 , data.getCurrentXmlData().length() );
Assertions.assertNotEquals( 0 , data.getCurrentXmlData().length() );
File file = new File( "target/test_02_handler_"+k+".xml" );
FileIO.writeBytes( data.getCurrentXmlData().getBytes() , file );
}
}
} );
Assert.assertTrue( Boolean.TRUE );
Assertions.assertTrue( Boolean.TRUE );
}

@Test
public void testLoadConfigKo() {
void testLoadConfigKo() {
String fullPath = "fj_doc_test/freemarker-doc-process_ko.xml";
Assert.assertThrows( ConfigRuntimeException.class, () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( fullPath ) );
Assertions.assertThrows( ConfigRuntimeException.class, () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( fullPath ) );
try {
FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://not-exists.xml" );
} catch (ConfigRuntimeException e) {
log.error( String.format( "Error : %s", e ), e );
Assert.assertTrue( e.getMessage().contains( FreemarkerDocProcessConfigFacade.ERROR_CONFIG_PATH_NOT_FOUND_BASE_MESSAGE ) );
Assertions.assertTrue( e.getMessage().contains( FreemarkerDocProcessConfigFacade.ERROR_CONFIG_PATH_NOT_FOUND_BASE_MESSAGE ) );
}
Exception testEx = new ConfigRuntimeException( "ex1", new ConfigRuntimeException( "ex0" ) );
Assert.assertEquals( ConfigRuntimeException.class, FreemarkerDocProcessConfigFacade.EX_CONSUMER_LOAD_CONFIG.apply( testEx ).getClass() );
Assertions.assertEquals( ConfigRuntimeException.class, FreemarkerDocProcessConfigFacade.EX_CONSUMER_LOAD_CONFIG.apply( testEx ).getClass() );
}

}
Loading
Loading