Utilisation de mockito
All checks were successful
Gradle Test / test (push) Successful in 52s

This commit is contained in:
Feror 2025-01-30 10:59:27 +01:00
parent 8cf3369aed
commit 446fbbf89b
2 changed files with 17 additions and 2 deletions

View file

@ -12,6 +12,7 @@ dependencies {
testImplementation('org.junit.jupiter:junit-jupiter')
// https://mvnrepository.com/artifact/org.assertj/assertj-core
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.24.2'
testImplementation "org.mockito:mockito-core:3.+"
}

View file

@ -1,11 +1,14 @@
package org.example;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
class CartTest {
@Test
@ -17,8 +20,19 @@ class CartTest {
@Test
void testInitiateOrder() {
StockManagement stock = new StockManagement("Stock1");
Accounting compta = new Accounting("Compta1");
StockManagement stock = mock(StockManagement.class);
Accounting compta = mock(Accounting.class);
doAnswer(invocation -> {
System.out.println("G.DES.STOCKS:" + invocation.getArgument(0).toString().toUpperCase());
return null;
}).when(stock).process(anyString());
doAnswer(invocation -> {
System.out.println("comptabilité:" + invocation.getArgument(0).toString().toLowerCase());
return null;
}).when(compta).process(anyString());
Cart cart = new Cart();
cart.addObserver(stock);