Skip to content

Commit 03f034c

Browse files
authored
[fj-doc-feeemarker] migrate junit4 to junit5 #324 (#328)
fix #324
1 parent 4d34b47 commit 03f034c

10 files changed

+128
-134
lines changed

fj-doc-freemarker/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@
109109
</dependency>
110110

111111
<dependency>
112-
<groupId>junit</groupId>
113-
<artifactId>junit</artifactId>
112+
<groupId>org.junit.jupiter</groupId>
113+
<artifactId>junit-jupiter-api</artifactId>
114114
<scope>test</scope>
115115
</dependency>
116116

fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/coverage/TestFreemarkerCoverage.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlFragmentTypeHandlerUTF8;
1616
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandler;
1717
import org.fugerit.java.doc.freemarker.html.FreeMarkerHtmlTypeHandlerUTF8;
18-
import org.junit.Assert;
19-
import org.junit.Test;
2018

2119
import lombok.AllArgsConstructor;
2220
import lombok.Getter;
2321
import lombok.ToString;
2422
import lombok.extern.slf4j.Slf4j;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
2525

2626
@Slf4j
27-
public class TestFreemarkerCoverage {
27+
class TestFreemarkerCoverage {
2828

2929
private final static TestEntry[] TEST_LIST = {
3030
new TestEntry( "default_doc" , true ),
@@ -58,16 +58,16 @@ private boolean worker( String path, boolean result ) {
5858
}
5959

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

6969
@Test
70-
public void testAsciidoc() {
70+
void testAsciidoc() {
7171
String docId = "asciidoc";
7272
DocTypeHandler handler = FreeMarkerAsciidocTypeHandler.HANDLER_UTF8;
7373
String type = DocConfig.TYPE_ADOC;
@@ -78,7 +78,7 @@ public void testAsciidoc() {
7878
handler.handle( DocInput.newInput( handler.getType() , reader ) , DocOutput.newOutput( fos ) );
7979
}
8080
} );
81-
Assert.assertTrue( outputFile.exists() );
81+
Assertions.assertTrue( outputFile.exists() );
8282
}
8383

8484
}

fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreeMarkerConstants.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import org.fugerit.java.doc.base.process.DocProcessContext;
44
import org.fugerit.java.doc.freemarker.config.FreeMarkerConstants;
5-
import org.junit.Assert;
6-
import org.junit.Test;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
77

8-
public class TestFreeMarkerConstants {
8+
class TestFreeMarkerConstants {
99

1010
@Test
11-
public void testFreeMarkerConstants() {
12-
Assert.assertNotNull(FreeMarkerConstants.getFreeMarkerMap(DocProcessContext.newContext()));
11+
void testFreeMarkerConstants() {
12+
Assertions.assertNotNull(FreeMarkerConstants.getFreeMarkerMap(DocProcessContext.newContext()));
1313
}
1414

1515
}

fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerConfigStep.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@
66
import org.fugerit.java.doc.base.process.DocProcessContext;
77
import org.fugerit.java.doc.base.process.DocProcessData;
88
import org.fugerit.java.doc.freemarker.config.FreeMarkerConfigStep;
9-
import org.junit.Assert;
10-
import org.junit.Test;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
1111

1212
import java.util.Properties;
1313

14-
public class TestFreemarkerConfigStep {
14+
class TestFreemarkerConfigStep {
1515

1616
@Test
17-
public void test() throws Exception {
17+
void test() throws Exception {
1818
Properties params = new Properties();
1919
FreeMarkerConfigStep step = new FreeMarkerConfigStep();
2020
step.setCustomConfig( params );
2121
DocProcessContext context = new DocProcessContext();
2222
DocProcessData data = new DocProcessData();
23-
Assert.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
23+
Assertions.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
2424
params.setProperty( "id", "FJ_DOC_TEST_1" );
2525
params.setProperty( "version", "2.3.31" );
2626
params.setProperty( "mode", "class" );
27-
Assert.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
27+
Assertions.assertThrows( ConfigRuntimeException.class, () -> step.process( context, data ) ) ;
2828
params.setProperty( "id", "FJ_DOC_TEST_2" );
2929
params.setProperty( "path", "/fj_doc_test/template/" );
3030
params.setProperty( "class", "org.fugerit.java.doc.freemarker.fun.ImageBase64CLFun" );
3131
params.setProperty( "exception-handler", "RETHROW_HANDLER" );
32-
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
32+
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
3333
params.setProperty( "id", "FJ_DOC_TEST_3" );
3434
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE, FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_MODE_FOLDER );
3535
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_PATH, "target" );
36-
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
36+
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
3737
params.setProperty( "id", "FJ_DOC_TEST_4" );
3838
params.remove( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_CLASS );
39-
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
39+
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
4040
params.setProperty( "id", "FJ_DOC_TEST_5" );
4141
params.setProperty( FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_LOAD_BUNDLED_FUN, BooleanUtils.BOOLEAN_TRUE);
42-
Assert.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
42+
Assertions.assertEquals(MiniFilter.CONTINUE, step.process( context, data ) );
4343
}
4444

4545
}

fj-doc-freemarker/src/test/java/test/org/fugerit/java/doc/freemarker/process/TestFreemarkerDocProcessConfig.java

+34-35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package test.org.fugerit.java.doc.freemarker.process;
22

3-
import static org.junit.Assert.fail;
43

54
import java.io.*;
65
import java.time.LocalDateTime;
@@ -29,19 +28,19 @@
2928
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfig;
3029
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigFacade;
3130
import org.fugerit.java.doc.freemarker.process.FreemarkerDocProcessConfigValidator;
32-
import org.junit.Assert;
33-
import org.junit.Test;
3431

3532
import lombok.extern.slf4j.Slf4j;
33+
import org.junit.jupiter.api.Assertions;
34+
import org.junit.jupiter.api.Test;
3635
import test.org.fugerit.java.BasicTest;
3736

3837
@Slf4j
39-
public class TestFreemarkerDocProcessConfig extends BasicTest {
38+
class TestFreemarkerDocProcessConfig extends BasicTest {
4039

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

4342
@Test
44-
public void testConfigRead001() throws Exception {
43+
void testConfigRead001() throws Exception {
4544
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" };
4645
for ( int k=0 ;k<configList.length ;k++ ) {
4746
String currentConfig = configList[k];
@@ -50,7 +49,7 @@ public void testConfigRead001() throws Exception {
5049
String chainId = "sample_chain";
5150
String type = DocConfig.TYPE_HTML;
5251
log.info( "config {}", config.getChain( chainId ) );
53-
Assert.assertNotNull( config );
52+
Assertions.assertNotNull( config );
5453
try (FileOutputStream fos = new FileOutputStream( new File( "target", chainId+"_"+k+"."+type ) ) ) {
5554
config.fullProcess( chainId, DocProcessContext.newContext(), DocConfig.TYPE_HTML, fos );
5655
}
@@ -59,7 +58,7 @@ public void testConfigRead001() throws Exception {
5958
try (ByteArrayOutputStream fos = new ByteArrayOutputStream() ) {
6059
DocProcessContext context = DocProcessContext.newContext().withSourceType( DocFacadeSource.SOURCE_TYPE_XML );
6160
if ( k == 0 || k == 2 ) {
62-
Assert.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( chainIdError, context, DocConfig.TYPE_HTML, fos ) );
61+
Assertions.assertThrows( ConfigRuntimeException.class, () -> config.fullProcess( chainIdError, context, DocConfig.TYPE_HTML, fos ) );
6362
} else {
6463
config.fullProcess( chainIdError, context, DocConfig.TYPE_HTML, fos );
6564
}
@@ -69,7 +68,7 @@ public void testConfigRead001() throws Exception {
6968
}
7069

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

9190
@Test
92-
public void testSkipFM() throws Exception {
91+
void testSkipFM() throws Exception {
9392
DocProcessContext context = DocProcessContext.newContext();
9493
DocProcessData data = new DocProcessData();
9594
FreeMarkerConfigStep configStep = new FreeMarkerConfigStep();
@@ -103,23 +102,23 @@ public void testSkipFM() throws Exception {
103102
FreeMarkerSkipProcessStep step = new FreeMarkerSkipProcessStep();
104103
step.setParam01( "asciidoc-xml.ftl" );
105104
step.process( context, data );
106-
Assert.assertNotNull( data.getCurrentXmlData() );
105+
Assertions.assertNotNull( data.getCurrentXmlData() );
107106
}
108107

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

114113
@Test
115-
public void testConfigFail02() {
114+
void testConfigFail02() {
116115
Reader reader = null;
117-
Assert.assertThrows( ConfigException.class , () -> FreemarkerDocProcessConfigFacade.loadConfig( reader ) );
116+
Assertions.assertThrows( ConfigException.class , () -> FreemarkerDocProcessConfigFacade.loadConfig( reader ) );
118117
}
119118

120119
@Test
121-
public void testConfigSec() {
122-
Assert.assertNotNull( FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj_doc_test/freemarker-doc-process_sec.xml" ) );
120+
void testConfigSec() {
121+
Assertions.assertNotNull( FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj_doc_test/freemarker-doc-process_sec.xml" ) );
123122
}
124123

125124

@@ -138,66 +137,66 @@ private void templateTesting( FreemarkerDocProcessConfig config ) {
138137
runTestEx( () -> {
139138
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
140139
// need to make it work in the future!
141-
Assert.assertThrows( NullPointerException.class, () -> {
140+
Assertions.assertThrows( NullPointerException.class, () -> {
142141
config.process( "test_01_inline", DocConfig.TYPE_MD, context, baos, false );
143142
} );
144143
}
145144
} );
146-
Assert.assertThrows( ConfigException.class , () -> {
145+
Assertions.assertThrows( ConfigException.class , () -> {
147146
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
148147
config.process( "test_01_fail", DocConfig.TYPE_MD, context, baos, false );
149148
}
150149
} );
151150
}
152151

153152
@Test
154-
public void testConfigRead002() {
153+
void testConfigRead002() {
155154
FreemarkerDocProcessConfig config =
156155
FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://fj_doc_test/freemarker-doc-process_alt.xml" );
157-
Assert.assertNotNull( config );
156+
Assertions.assertNotNull( config );
158157
this.templateTesting(config);
159158
log.info( "keys : {}", config.getKeys() );
160159
}
161160

162161
@Test
163-
public void testConfigValidate001() {
162+
void testConfigValidate001() {
164163
try ( Reader xmlReader = new InputStreamReader( ClassHelper.loadFromDefaultClassLoader( "fj_doc_test/freemarker-doc-process.xml" ) ) ) {
165164
FreemarkerDocProcessConfigValidator.logValidation( xmlReader );
166165
} catch (Exception e) {
167166
String message = "Error : "+e;
168167
log.error( message, e );
169-
fail(message);
168+
Assertions.fail(message);
170169
}
171170
}
172171

173172
@Test
174-
public void testNewSimpleConfig() {
173+
void testNewSimpleConfig() {
175174
try {
176-
Assert.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-001", "/template").getChainCache( "test" ) );
175+
Assertions.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-001", "/template").getChainCache( "test" ) );
177176
} catch (Exception e) {
178177
this.failEx(e);
179178
}
180179
}
181180

182181
@Test
183-
public void testNewSimpleConfigVersion() {
182+
void testNewSimpleConfigVersion() {
184183
try {
185-
Assert.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-002", "/template", FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 ).getChainCache( "test" ) );
184+
Assertions.assertNotNull( FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-002", "/template", FreeMarkerConfigStep.ATT_FREEMARKER_CONFIG_KEY_VERSION_2_3_31 ).getChainCache( "test" ) );
186185
} catch (Exception e) {
187186
this.failEx(e);
188187
}
189188
}
190189

191190
@Test
192-
public void testProcess() {
191+
void testProcess() {
193192
SafeFunction.apply( () -> {
194193
FreemarkerDocProcessConfig config = FreemarkerDocProcessConfigFacade.newSimpleConfig( "simple-config-003", "/fj_doc_test/template/" );
195194
config.getFacade().registerHandler( FreeMarkerHtmlTypeHandlerUTF8.HANDLER );
196195
// test full process
197196
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
198197
DocProcessData data = config.fullProcess( "test_02" ,
199198
DocProcessContext.newContext(), DocConfig.TYPE_HTML, baos );
200-
Assert.assertNotEquals( 0 , data.getCurrentXmlData().length() );
199+
Assertions.assertNotEquals( 0 , data.getCurrentXmlData().length() );
201200
}
202201
// test process 1
203202
// handler list :
@@ -210,27 +209,27 @@ public void testProcess() {
210209
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
211210
DocProcessData data = new DocProcessData();
212211
config.process( "test_02" , DocProcessContext.newContext( "testKey", "<test/>" ), data, FreeMarkerHtmlTypeHandlerUTF8.HANDLER, DocOutput.newOutput(baos) );
213-
Assert.assertNotEquals( 0 , data.getCurrentXmlData().length() );
212+
Assertions.assertNotEquals( 0 , data.getCurrentXmlData().length() );
214213
File file = new File( "target/test_02_handler_"+k+".xml" );
215214
FileIO.writeBytes( data.getCurrentXmlData().getBytes() , file );
216215
}
217216
}
218217
} );
219-
Assert.assertTrue( Boolean.TRUE );
218+
Assertions.assertTrue( Boolean.TRUE );
220219
}
221220

222221
@Test
223-
public void testLoadConfigKo() {
222+
void testLoadConfigKo() {
224223
String fullPath = "fj_doc_test/freemarker-doc-process_ko.xml";
225-
Assert.assertThrows( ConfigRuntimeException.class, () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( fullPath ) );
224+
Assertions.assertThrows( ConfigRuntimeException.class, () -> FreemarkerDocProcessConfigFacade.loadConfigSafe( fullPath ) );
226225
try {
227226
FreemarkerDocProcessConfigFacade.loadConfigSafe( "cl://not-exists.xml" );
228227
} catch (ConfigRuntimeException e) {
229228
log.error( String.format( "Error : %s", e ), e );
230-
Assert.assertTrue( e.getMessage().contains( FreemarkerDocProcessConfigFacade.ERROR_CONFIG_PATH_NOT_FOUND_BASE_MESSAGE ) );
229+
Assertions.assertTrue( e.getMessage().contains( FreemarkerDocProcessConfigFacade.ERROR_CONFIG_PATH_NOT_FOUND_BASE_MESSAGE ) );
231230
}
232231
Exception testEx = new ConfigRuntimeException( "ex1", new ConfigRuntimeException( "ex0" ) );
233-
Assert.assertEquals( ConfigRuntimeException.class, FreemarkerDocProcessConfigFacade.EX_CONSUMER_LOAD_CONFIG.apply( testEx ).getClass() );
232+
Assertions.assertEquals( ConfigRuntimeException.class, FreemarkerDocProcessConfigFacade.EX_CONSUMER_LOAD_CONFIG.apply( testEx ).getClass() );
234233
}
235234

236235
}

0 commit comments

Comments
 (0)