1414import net .ladenthin .llama .args .MiroStat ;
1515import net .ladenthin .llama .args .Sampler ;
1616import net .ladenthin .llama .json .CompletionResponseParser ;
17- import org .junit .AfterClass ;
18- import org .junit .Assert ;
19- import org .junit .Assume ;
20- import org .junit .BeforeClass ;
21- import org .junit .Test ;
17+ import org .junit .jupiter . api . AfterAll ;
18+ import static org .junit .jupiter . api . Assertions .* ;
19+ import org .junit .jupiter . api . Assumptions ;
20+ import org .junit .jupiter . api . BeforeAll ;
21+ import org .junit .jupiter . api . Test ;
2222
2323/**
2424 * Advanced inference parameter scenarios covering code paths untested by
@@ -53,10 +53,9 @@ public class ChatAdvancedTest {
5353
5454 private static LlamaModel model ;
5555
56- @ BeforeClass
56+ @ BeforeAll
5757 public static void setup () {
58- Assume .assumeTrue ("Model file not found, skipping ChatAdvancedTest" ,
59- new File (TestConstants .MODEL_PATH ).exists ());
58+ Assumptions .assumeTrue (new File (TestConstants .MODEL_PATH ).exists (), "Model file not found, skipping ChatAdvancedTest" );
6059 int gpuLayers = Integer .getInteger (TestConstants .PROP_TEST_NGL , TestConstants .DEFAULT_TEST_NGL );
6160 model = new LlamaModel (
6261 new ModelParameters ()
@@ -67,7 +66,7 @@ public static void setup() {
6766 );
6867 }
6968
70- @ AfterClass
69+ @ AfterAll
7170 public static void tearDown () {
7271 if (model != null ) {
7372 model .close ();
@@ -94,9 +93,8 @@ public void testCachePromptConsistentOutput() {
9493 String first = model .complete (params );
9594 String second = model .complete (params );
9695
97- Assert .assertFalse ("First cached call must produce output" , first .isEmpty ());
98- Assert .assertEquals ("Same prompt with cache_prompt must produce identical output" ,
99- first , second );
96+ assertFalse (first .isEmpty (), "First cached call must produce output" );
97+ assertEquals (first , second , "Same prompt with cache_prompt must produce identical output" );
10098 }
10199
102100 // ------------------------------------------------------------------
@@ -119,10 +117,9 @@ public void testUnboundedGenerationTerminatesAtStopString() {
119117
120118 String output = model .complete (params );
121119
122- Assert . assertNotNull ("Unbounded+stop output must not be null" , output );
120+ assertNotNull (output , "Unbounded+stop output must not be null" );
123121 // The stop string itself must not appear in the completion
124- Assert .assertFalse ("Output must not contain the stop string 'E'" ,
125- output .contains ("E" ));
122+ assertFalse (output .contains ("E" ), "Output must not contain the stop string 'E'" );
126123 }
127124
128125 // ------------------------------------------------------------------
@@ -150,7 +147,7 @@ public void testSetNProbsStreamingJsonHasProbabilities() {
150147 boolean done = false ;
151148 while (!done ) {
152149 String json = model .receiveCompletionJson (taskId );
153- Assert . assertNotNull ("receiveCompletionJson must not be null" , json );
150+ assertNotNull (json , "receiveCompletionJson must not be null" );
154151 LlamaOutput output = completionParser .parse (json );
155152 if (json .contains ("\" completion_probabilities\" " )) {
156153 foundProbabilities = true ;
@@ -166,10 +163,7 @@ public void testSetNProbsStreamingJsonHasProbabilities() {
166163 }
167164 }
168165
169- Assert .assertTrue (
170- "At least one streaming JSON chunk must contain 'completion_probabilities' when nProbs>0" ,
171- foundProbabilities
172- );
166+ assertTrue (foundProbabilities , "At least one streaming JSON chunk must contain 'completion_probabilities' when nProbs>0" );
173167 }
174168
175169 // ------------------------------------------------------------------
@@ -211,13 +205,9 @@ public void testCustomChatTemplateAcceptedWithoutError() {
211205 // Must not throw; parameter is accepted and forwarded to native layer
212206 String result = model .applyTemplate (params );
213207
214- Assert .assertNotNull ("applyTemplate with setChatTemplate must return non-null" , result );
215- Assert .assertFalse ("applyTemplate with setChatTemplate must return non-empty result" ,
216- result .isEmpty ());
217- Assert .assertTrue (
218- "Result must contain the message content 'hello world' regardless of template used" ,
219- result .contains ("hello world" )
220- );
208+ assertNotNull (result , "applyTemplate with setChatTemplate must return non-null" );
209+ assertFalse (result .isEmpty (), "applyTemplate with setChatTemplate must return non-empty result" );
210+ assertTrue (result .contains ("hello world" ), "Result must contain the message content 'hello world' regardless of template used" );
221211 }
222212
223213 // ------------------------------------------------------------------
@@ -247,8 +237,7 @@ public void testUseChatTemplateInGenerate() {
247237 output .append (token .text );
248238 }
249239
250- Assert .assertFalse ("generate() with use_chat_template must produce output" ,
251- output .toString ().isEmpty ());
240+ assertFalse (output .toString ().isEmpty (), "generate() with use_chat_template must produce output" );
252241 }
253242
254243 // ------------------------------------------------------------------
@@ -272,7 +261,7 @@ public void testRepeatAndFrequencyAndPresencePenalty() {
272261 .setRepeatLastN (32 );
273262
274263 String output = model .complete (params );
275- Assert . assertFalse ("Penalty params must not produce empty output" , output . isEmpty () );
264+ assertFalse (output . isEmpty (), "Penalty params must not produce empty output" );
276265 }
277266
278267 // ------------------------------------------------------------------
@@ -295,7 +284,7 @@ public void testCustomSamplerChain() {
295284 .setSamplers (Sampler .TOP_K , Sampler .TOP_P , Sampler .TEMPERATURE );
296285
297286 String output = model .complete (params );
298- Assert . assertFalse ("Custom sampler chain must produce non-empty output" , output . isEmpty () );
287+ assertFalse (output . isEmpty (), "Custom sampler chain must produce non-empty output" );
299288 }
300289
301290 // ------------------------------------------------------------------
@@ -317,7 +306,7 @@ public void testMiroStatV2Sampling() {
317306 .setMiroStatEta (0.1f );
318307
319308 String output = model .complete (params );
320- Assert . assertFalse ("MiroStat V2 must produce non-empty output" , output . isEmpty () );
309+ assertFalse (output . isEmpty (), "MiroStat V2 must produce non-empty output" );
321310 }
322311
323312 // ------------------------------------------------------------------
@@ -344,7 +333,7 @@ public void testRequestCompletionDirectStreaming() {
344333 boolean stopped = false ;
345334 while (!stopped ) {
346335 String json = model .receiveCompletionJson (taskId );
347- Assert . assertNotNull ("receiveCompletionJson must not return null" , json );
336+ assertNotNull (json , "receiveCompletionJson must not return null" );
348337 LlamaOutput output = completionParser .parse (json );
349338 sb .append (output .text );
350339 tokens ++;
@@ -354,13 +343,12 @@ public void testRequestCompletionDirectStreaming() {
354343 }
355344 if (tokens > N_PREDICT + 2 ) {
356345 model .releaseTask (taskId );
357- Assert . fail ("Direct streaming did not stop within nPredict tokens" );
346+ fail ("Direct streaming did not stop within nPredict tokens" );
358347 }
359348 }
360349
361- Assert .assertTrue ("Direct non-chat streaming must emit at least one token" , tokens > 0 );
362- Assert .assertFalse ("Direct non-chat streaming must produce non-empty content" ,
363- sb .toString ().isEmpty ());
350+ assertTrue (tokens > 0 , "Direct non-chat streaming must emit at least one token" );
351+ assertFalse (sb .toString ().isEmpty (), "Direct non-chat streaming must produce non-empty content" );
364352 }
365353
366354 // ------------------------------------------------------------------
@@ -397,7 +385,7 @@ public void testDisableTokenIdsAccepted() {
397385 .disableTokenIds (Collections .singletonList (disabledId ));
398386
399387 String output = model .complete (params );
400- Assert . assertFalse ("disableTokenIds must not produce empty output" , output . isEmpty () );
388+ assertFalse (output . isEmpty (), "disableTokenIds must not produce empty output" );
401389 }
402390
403391 // ------------------------------------------------------------------
@@ -418,14 +406,13 @@ public void testPenaltyPromptStringAccepted() {
418406 .setPenaltyPrompt ("def " )
419407 .setRepeatPenalty (1.2f );
420408
421- Assert .assertFalse ("setPenaltyPrompt(String) must produce output" ,
422- model .complete (params ).isEmpty ());
409+ assertFalse (model .complete (params ).isEmpty (), "setPenaltyPrompt(String) must produce output" );
423410 }
424411
425412 @ Test
426413 public void testPenaltyPromptTokenArrayAccepted () {
427414 int [] penaltyTokens = model .encode ("def " );
428- Assume .assumeTrue ("Need at least one penalty token" , penaltyTokens . length > 0 );
415+ Assumptions .assumeTrue (penaltyTokens . length > 0 , "Need at least one penalty token" );
429416
430417 InferenceParameters params = new InferenceParameters (SIMPLE_PROMPT )
431418 .setNPredict (N_PREDICT )
@@ -434,8 +421,7 @@ public void testPenaltyPromptTokenArrayAccepted() {
434421 .setPenaltyPrompt (penaltyTokens )
435422 .setRepeatPenalty (1.2f );
436423
437- Assert .assertFalse ("setPenaltyPrompt(int[]) must produce output" ,
438- model .complete (params ).isEmpty ());
424+ assertFalse (model .complete (params ).isEmpty (), "setPenaltyPrompt(int[]) must produce output" );
439425 }
440426
441427 // ------------------------------------------------------------------
@@ -457,13 +443,10 @@ public void testMultipleStopStringsFirstMatchTerminates() {
457443
458444 String output = model .complete (params );
459445
460- Assert . assertNotNull (output );
446+ assertNotNull (output );
461447 // None of the stop strings should appear in the output
462448 for (String stop : new String []{"4" , "5" , "6" }) {
463- Assert .assertFalse (
464- "Output must not contain stop string '" + stop + "', got: " + output ,
465- output .contains (stop )
466- );
449+ assertFalse (output .contains (stop ), "Output must not contain stop string '" + stop + "', got: " + output );
467450 }
468451 }
469452
@@ -484,7 +467,7 @@ public void testMinPSamplerAccepted() {
484467 .setTemperature (0.7f )
485468 .setMinP (0.05f );
486469
487- Assert . assertFalse ("setMinP must produce output" , model .complete (params ).isEmpty ());
470+ assertFalse (model .complete (params ).isEmpty (), "setMinP must produce output" );
488471 }
489472
490473 @ Test
@@ -495,7 +478,7 @@ public void testTfsZSamplerAccepted() {
495478 .setTemperature (0.7f )
496479 .setTfsZ (0.95f );
497480
498- Assert . assertFalse ("setTfsZ must produce output" , model .complete (params ).isEmpty ());
481+ assertFalse (model .complete (params ).isEmpty (), "setTfsZ must produce output" );
499482 }
500483
501484 @ Test
@@ -506,7 +489,7 @@ public void testTypicalPSamplerAccepted() {
506489 .setTemperature (0.7f )
507490 .setTypicalP (0.9f );
508491
509- Assert . assertFalse ("setTypicalP must produce output" , model .complete (params ).isEmpty ());
492+ assertFalse (model .complete (params ).isEmpty (), "setTypicalP must produce output" );
510493 }
511494
512495 // ------------------------------------------------------------------
@@ -526,7 +509,7 @@ public void testNKeepAllTokensAccepted() {
526509 .setTemperature (0.0f )
527510 .setNKeep (-1 );
528511
529- Assert . assertFalse ("setNKeep(-1) must produce output" , model . complete ( params ). isEmpty () );
512+ assertFalse (model . complete ( params ). isEmpty (), "setNKeep(-1) must produce output" );
530513 }
531514
532515 // ------------------------------------------------------------------
@@ -547,8 +530,7 @@ public void testDisableTokensStringFormAccepted() {
547530 .setTemperature (0.0f )
548531 .disableTokens (Arrays .asList ("!!!" ));
549532
550- Assert .assertFalse ("disableTokens must not produce empty output" ,
551- model .complete (params ).isEmpty ());
533+ assertFalse (model .complete (params ).isEmpty (), "disableTokens must not produce empty output" );
552534 }
553535
554536 // ------------------------------------------------------------------
@@ -568,7 +550,6 @@ public void testMiroStatV1Sampling() {
568550 .setMiroStatTau (5.0f )
569551 .setMiroStatEta (0.1f );
570552
571- Assert .assertFalse ("MiroStat V1 must produce non-empty output" ,
572- model .complete (params ).isEmpty ());
553+ assertFalse (model .complete (params ).isEmpty (), "MiroStat V1 must produce non-empty output" );
573554 }
574555}
0 commit comments