Skip to content

Commit ceaca4d

Browse files
author
Philipp Kraus
committed
update to junit5
1 parent 39f15b9 commit ceaca4d

File tree

4 files changed

+50
-58
lines changed

4 files changed

+50
-58
lines changed

IBaseTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package org.lightjason.agentspeak.testing;
2525

2626
import org.apache.commons.io.IOUtils;
27-
import org.junit.Assert;
27+
import org.junit.jupiter.api.Assertions;
2828
import org.lightjason.agentspeak.action.IBaseAction;
2929
import org.lightjason.agentspeak.agent.IAgent;
3030
import org.lightjason.agentspeak.agent.IBaseAgent;
@@ -218,7 +218,7 @@ protected static void agentcycleassert( @Nonnull final IAgent<?> p_agent )
218218
catch ( final Exception l_exception )
219219
{
220220
l_exception.printStackTrace();
221-
Assert.fail( l_exception.getMessage() );
221+
Assertions.fail( l_exception.getMessage() );
222222
}
223223
}
224224

TestCActionNames.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
package org.lightjason.agentspeak.testing;
2525

26-
import org.junit.Assert;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
27+
import org.junit.jupiter.api.Test;
2828
import org.lightjason.agentspeak.action.IAction;
2929
import org.lightjason.agentspeak.common.CCommon;
3030

@@ -54,9 +54,9 @@ public void actionnames()
5454
*/
5555
private static void checkname( @Nonnull final IAction p_action )
5656
{
57-
Assert.assertTrue(
58-
p_action.getClass().getCanonicalName(),
59-
p_action.name().toString().contains( p_action.getClass().getSimpleName().substring( 1 ).toLowerCase( Locale.ROOT ) )
57+
Assertions.assertTrue(
58+
p_action.name().toString().contains( p_action.getClass().getSimpleName().substring( 1 ).toLowerCase( Locale.ROOT ) ),
59+
p_action.getClass().getCanonicalName()
6060
);
6161
}
6262

TestCAsl.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323

2424
package org.lightjason.agentspeak.testing;
2525

26-
import com.tngtech.java.junit.dataprovider.DataProvider;
27-
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
28-
import com.tngtech.java.junit.dataprovider.UseDataProvider;
2926
import org.apache.commons.io.IOUtils;
30-
import org.junit.Assert;
31-
import org.junit.Assume;
32-
import org.junit.Before;
33-
import org.junit.Test;
34-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.Assertions;
28+
import org.junit.jupiter.api.Assumptions;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.params.ParameterizedTest;
31+
import org.junit.jupiter.params.provider.Arguments;
32+
import org.junit.jupiter.params.provider.MethodSource;
3533
import org.lightjason.agentspeak.action.IBaseAction;
3634
import org.lightjason.agentspeak.agent.IAgent;
3735
import org.lightjason.agentspeak.common.CCommon;
@@ -75,7 +73,6 @@
7573
* test agent structure.
7674
* If a file agentprintin.conf exists on the main directory alls print statements will be shown
7775
*/
78-
@RunWith( DataProviderRunner.class )
7976
public final class TestCAsl extends IBaseTest
8077
{
8178
/**
@@ -108,7 +105,7 @@ public final class TestCAsl extends IBaseTest
108105
/**
109106
* initialize
110107
*/
111-
@Before
108+
@BeforeEach
112109
public void initialize()
113110
{
114111
m_count = new AtomicInteger();
@@ -118,8 +115,7 @@ public void initialize()
118115
* data provider for defining asl files
119116
* @return triple of test-cases (asl file, number of iterations, expected log items)
120117
*/
121-
@DataProvider
122-
public static Object[] generate()
118+
public static Stream<Arguments> generate()
123119
{
124120
try
125121
(
@@ -131,12 +127,12 @@ public static Object[] generate()
131127
return l_walk.filter( Files::isRegularFile )
132128
.map( Path::toString )
133129
.filter( i -> i.endsWith( ".asl" ) )
134-
.toArray();
130+
.map( Arguments::of );
135131

136132
}
137133
catch ( final IOException l_exception )
138134
{
139-
return new Object[]{""};
135+
return Stream.of( Arguments.of() );
140136
}
141137
}
142138

@@ -147,11 +143,11 @@ public static Object[] generate()
147143
* @param p_file tripel of asl code, cycles and expected success calls
148144
* @throws Exception on any error
149145
*/
150-
@Test
151-
@UseDataProvider( "generate" )
146+
@ParameterizedTest
147+
@MethodSource( "generate" )
152148
public void testASLDefault( @Nonnull final String p_file ) throws Exception
153149
{
154-
Assume.assumeFalse( "asl files does not exist", p_file.isEmpty() );
150+
Assumptions.assumeFalse( p_file.isEmpty(), "asl files does not exist" );
155151

156152
final IAgent<?> l_agent;
157153
final int l_iteration;
@@ -208,17 +204,17 @@ public void testASLDefault( @Nonnull final String p_file ) throws Exception
208204
catch ( final Exception l_exception )
209205
{
210206
l_exception.printStackTrace();
211-
Assert.fail( p_file );
207+
Assertions.fail( p_file );
212208
return;
213209
}
214210

215211
IntStream.range( 0, l_iteration )
216212
.forEach( i -> agentcycle( l_agent ) );
217213

218-
Assert.assertEquals(
219-
MessageFormat.format( "{0} {1}", "number of tests", p_file ),
214+
Assertions.assertEquals(
220215
l_testcount,
221-
m_count.get()
216+
m_count.get(),
217+
MessageFormat.format( "{0} {1}", "number of tests", p_file )
222218
);
223219

224220
}
@@ -258,14 +254,14 @@ public int minimalArgumentNumber()
258254
public Stream<IFuzzyValue<?>> execute( final boolean p_parallel, @Nonnull final IContext p_context,
259255
@Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return )
260256
{
261-
Assert.assertTrue(
257+
Assertions.assertTrue(
258+
p_argument.get( 0 ).<Boolean>raw(),
262259
MessageFormat.format(
263260
"{0}{1}{2}",
264261
p_context.instance().literal(),
265262
p_argument.size() > 1 ? ": " : "",
266263
p_argument.size() > 1 ? p_argument.get( 1 ).raw() : ""
267-
),
268-
p_argument.get( 0 ).<Boolean>raw()
264+
)
269265
);
270266
m_count.incrementAndGet();
271267
return Stream.empty();

TestCLanguageLabel.java

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
3333
import org.apache.commons.lang3.ClassUtils;
3434
import org.apache.commons.lang3.StringUtils;
35-
import org.junit.Assert;
36-
import org.junit.Assume;
37-
import org.junit.Test;
35+
import org.junit.jupiter.api.Assertions;
36+
import org.junit.jupiter.api.Assumptions;
37+
import org.junit.jupiter.api.Test;
3838
import org.lightjason.agentspeak.common.CCommon;
3939

4040
import javax.annotation.Nonnull;
@@ -65,10 +65,6 @@
6565
import java.util.stream.IntStream;
6666
import java.util.stream.Stream;
6767

68-
import static org.junit.Assert.assertFalse;
69-
import static org.junit.Assume.assumeTrue;
70-
71-
7268
/**
7369
* test all resource strings
7470
*/
@@ -97,7 +93,7 @@ public final class TestCLanguageLabel extends IBaseTest
9793
}
9894
catch ( final Exception l_exception )
9995
{
100-
assumeTrue( MessageFormat.format( "source directory cannot be read: {0}", l_exception.getMessage() ), false );
96+
Assumptions.assumeTrue( false, MessageFormat.format( "source directory cannot be read: {0}", l_exception.getMessage() ) );
10197
}
10298

10399
// read all possible languages and define the first as default
@@ -128,7 +124,7 @@ public final class TestCLanguageLabel extends IBaseTest
128124
}
129125
catch ( final Exception l_exception )
130126
{
131-
assumeTrue( MessageFormat.format( "source directory cannot be read: {0}", l_exception.getMessage() ), false );
127+
Assumptions.assumeTrue( false, MessageFormat.format( "source directory cannot be read: {0}", l_exception.getMessage() ) );
132128
}
133129
} );
134130

@@ -141,7 +137,7 @@ public final class TestCLanguageLabel extends IBaseTest
141137
@Test
142138
public void testTranslation()
143139
{
144-
assumeTrue( "no languages are defined for checking", !LANGUAGEPROPERY.isEmpty() );
140+
Assumptions.assumeTrue( !LANGUAGEPROPERY.isEmpty(), "no languages are defined for checking" );
145141

146142
// --- read language definitions of the configuration
147143
final Set<String> l_translation = Collections.unmodifiableSet(
@@ -154,26 +150,26 @@ public void testTranslation()
154150
// --- check if a test (language resource) exists for each definied language
155151
final Set<String> l_translationtesting = new HashSet<>( l_translation );
156152
l_translationtesting.removeAll( LANGUAGEPROPERY.keySet() );
157-
assertFalse(
153+
Assertions.assertFalse(
154+
!l_translationtesting.isEmpty(),
158155
MessageFormat.format(
159156
"configuration defines {1,choice,1#translation|1<translations} {0} that {1,choice,1#is|1<are} not tested",
160157
l_translationtesting,
161158
l_translationtesting.size()
162-
),
163-
!l_translationtesting.isEmpty()
159+
)
164160
);
165161

166162

167163
// --- check unused language resource files
168164
final Set<String> l_translationusing = new HashSet<>( LANGUAGEPROPERY.keySet() );
169165
l_translationusing.removeAll( l_translation );
170-
assertFalse(
166+
Assertions.assertFalse(
167+
!l_translationusing.isEmpty(),
171168
MessageFormat.format(
172169
"{1,choice,1#translation|1<translations} {0} {1,choice,1#is|1<are} checked, which will not be used within the package configuration",
173170
l_translationusing,
174171
l_translationusing.size()
175-
),
176-
!l_translationusing.isEmpty()
172+
)
177173
);
178174
}
179175

@@ -185,8 +181,8 @@ public void testTranslation()
185181
@Test
186182
public void testResourceString() throws IOException
187183
{
188-
Assume.assumeTrue( "no languages are defined for checking", !LANGUAGEPROPERY.isEmpty() );
189-
Assume.assumeTrue( "language files does not exist", LANGUAGEPROPERY.values().stream().anyMatch( i -> new File( i ).isFile() ) );
184+
Assumptions.assumeTrue( !LANGUAGEPROPERY.isEmpty(), "no languages are defined for checking" );
185+
Assumptions.assumeTrue( LANGUAGEPROPERY.values().stream().anyMatch( i -> new File( i ).isFile() ), "language files does not exist" );
190186

191187
final Set<String> l_ignoredlabel = new HashSet<>();
192188

@@ -197,7 +193,7 @@ public void testResourceString() throws IOException
197193
.flatMap( i -> labels( i, l_ignoredlabel ) ).collect( Collectors.toUnmodifiableSet() );
198194

199195
// --- check of any label is found
200-
Assert.assertFalse( "translation labels are empty, check naming of translation method", l_label.isEmpty() );
196+
Assertions.assertFalse( l_label.isEmpty(), "translation labels are empty, check naming of translation method" );
201197

202198
// --- check label towards the property definition
203199
if ( l_ignoredlabel.size() > 0 )
@@ -219,14 +215,14 @@ public void testResourceString() throws IOException
219215

220216
// --- check if all property items are within the parsed labels
221217
l_parseditems.removeAll( l_propertyitems );
222-
Assert.assertTrue(
218+
Assertions.assertTrue(
219+
l_parseditems.isEmpty(),
223220
MessageFormat.format(
224221
"the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the language file:\n{2}",
225222
k,
226223
l_parseditems.size(),
227224
StringUtils.join( l_parseditems, ", " )
228-
),
229-
l_parseditems.isEmpty()
225+
)
230226
);
231227

232228

@@ -238,19 +234,19 @@ public void testResourceString() throws IOException
238234
.allMatch( l -> false )
239235
)
240236
.collect( Collectors.toSet() );
241-
Assert.assertTrue(
237+
Assertions.assertTrue(
238+
l_ignoredpropertyitems.isEmpty(),
242239
MessageFormat.format(
243240
"the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the source code:\n{2}",
244241
k,
245242
l_ignoredpropertyitems.size(),
246243
StringUtils.join( l_ignoredpropertyitems, ", " )
247-
),
248-
l_ignoredpropertyitems.isEmpty()
244+
)
249245
);
250246
}
251247
catch ( final IOException l_exception )
252248
{
253-
Assert.fail( MessageFormat.format( "io exception: {0}", l_exception.getMessage() ) );
249+
Assertions.fail( MessageFormat.format( "io exception: {0}", l_exception.getMessage() ) );
254250
}
255251
} );
256252
}
@@ -272,7 +268,7 @@ private static Stream<String> labels( @Nonnull final Path p_file, @Nonnull final
272268
}
273269
catch ( final IOException l_excpetion )
274270
{
275-
Assert.fail( MessageFormat.format( "io error on file [{0}]: {1}", p_file, l_excpetion.getMessage() ) );
271+
Assertions.fail( MessageFormat.format( "io error on file [{0}]: {1}", p_file, l_excpetion.getMessage() ) );
276272
return Stream.empty();
277273
}
278274
catch ( final ParseProblemException l_exception )

0 commit comments

Comments
 (0)