Repository: maxime64100/sharePortfolio---VSCode
Pull request #41: ajout de tests et methode pour afficher/consulter le portefeuille
Author: login: Mathis-Lague
Created: 2025-05-21T08:31:44Z | Merged: 2025-05-23T07:47:12Z

new method: 
afficherPortefeuille()

new tests:
testConsulterPortefeuilleActionSimple()
testConsulterPortefeuilleActionComposee()
testAfficherDetailsPortefeuille()


Diff:
diff --git a/src/main/java/fr/utc/miage/shares/Portefeuille.java b/src/main/java/fr/utc/miage/shares/Portefeuille.java
index 7bbe88f..a66df28 100644
--- a/src/main/java/fr/utc/miage/shares/Portefeuille.java
+++ b/src/main/java/fr/utc/miage/shares/Portefeuille.java
@@ -103,4 +103,18 @@ public Map<Action, Integer> getActions() {
     public int getQuantite(Action action) {
         return actions.getOrDefault(action, 0);
     }
+
+    public String afficherPortefeuille() {
+        StringBuilder sb = new StringBuilder("Contenu du portefeuille :\n");
+        for (Map.Entry<Action, Integer> entry : actions.entrySet()) {
+            Action action = entry.getKey();
+            int quantite = entry.getValue();
+            sb.append(action.toString())
+              .append(" - Quantité : ")
+              .append(quantite)
+              .append("\n");
+        }
+        return sb.toString();
+    }
+    
 }
diff --git a/src/test/java/fr/utc/miage/shares/PortefeuilleTest.java b/src/test/java/fr/utc/miage/shares/PortefeuilleTest.java
index 86a4840..697b764 100644
--- a/src/test/java/fr/utc/miage/shares/PortefeuilleTest.java
+++ b/src/test/java/fr/utc/miage/shares/PortefeuilleTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2024 David Navarre &lt;David.Navarre at irit.fr&gt;.
+ * Copyright 2025 David Navarre &lt;David.Navarre at irit.fr&gt;.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +15,13 @@
  */
 package fr.utc.miage.shares;
 
+import fr.utc.miage.shares.Action;
+import fr.utc.miage.shares.ActionSimple;
+import fr.utc.miage.shares.ActionComposee;
+
+import java.util.HashMap;
+import java.util.Map;
+
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -113,6 +120,70 @@ void testAcheterActionSimpleQuantiteNegative() {
         }
     }
 
+
+    //test d'affichage des actions
+    @Test
+    void testConsulterPortefeuilleActionSimple() {
+        //Arrange
+        Portefeuille portefeuille = new Portefeuille();
+        Action action1 = new ActionSimple("GOOGLE");
+        Action action2 = new ActionSimple("FACEBOOK");
+
+        //Action
+        portefeuille.acheter(action1, 10);
+        portefeuille.acheter(action2, 5);
+
+        //Assert
+        assert portefeuille.getActions().size() == 2;
+        assert portefeuille.getQuantite(action1) == 10;
+        assert portefeuille.getQuantite(action2) == 5;
+
+    }
+
+    @Test
+    void testConsulterPortefeuilleActionComposee() {
+        //Arrange
+        ActionSimple facebookStock = new ActionSimple("FB1");
+        ActionSimple metaStock = new ActionSimple("META1");
+        Portefeuille portefeuille = new Portefeuille();
+        Map<ActionSimple, Float> proportions = new HashMap<>();
+
+        //Action
+        proportions.put(facebookStock, 0.6f);
+        proportions.put(metaStock, 0.4f);
+        Action actionComposee = new ActionComposee("FACEBOOK", proportions);
+        portefeuille.acheter(actionComposee, 10);
+        portefeuille.acheter(actionComposee, 5);
+
+        //Assert
+        assert portefeuille.getActions().containsKey(actionComposee);
+        assert portefeuille.getQuantite(actionComposee) == 15;
+    }
+
+    @Test
+    void testAfficherDetailsPortefeuille() {
+        //Arrange
+        ActionSimple google = new ActionSimple("GOOGLE");
+        ActionSimple fb1 = new ActionSimple("FB1");
+        Map<ActionSimple, Float> proportions = new HashMap<>();
+        Portefeuille portefeuille = new Portefeuille();
+
+        //Action
+        proportions.put(fb1, 0.6f);
+        proportions.put(google, 0.4f);
+        ActionComposee composedFb = new ActionComposee("FACEBOOK", proportions);
+        portefeuille.acheter(google, 10);
+        portefeuille.acheter(composedFb, 5);
+        String affichage = portefeuille.afficherPortefeuille();
+        System.out.println(affichage); // utile pour visualiser pendant le dev
+
+        //Assert
+        assert affichage.contains("GOOGLE");
+        assert affichage.contains("FACEBOOK");
+        assert affichage.contains("Quantité : 10");
+        assert affichage.contains("Quantité : 5");
+    }
+
     @Test
     void testAcheterActionComposeeNonDetenue() {
         ActionSimple france2 = new ActionSimple("France 2");


Reviews:
user: login: Munozmu
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-21T09:37:25Z
user: login: Munozmu
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-21T09:38:49Z
user: login: MathysALZURIA
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-05-23T07:41:22Z

Review comments:
diff_hunk: @@ -1,8 +1,74 @@
 package fr.utc.miage.shares;
 
+import fr.utc.miage.shares.Action;
+import fr.utc.miage.shares.ActionSimple;
+import fr.utc.miage.shares.ActionComposee;
+
+import java.util.HashMap;
+import java.util.Map;
+
 import org.junit.jupiter.api.Test;
 
 public class PortefeuilleTest {
+
+    //test d'affichage des actions
+    @Test
+    void testConsulterPortefeuilleActionSimple() {
+        Portefeuille portefeuille = new Portefeuille();
+        Action action1 = new ActionSimple("GOOGLE");
+        Action action2 = new ActionSimple("FACEBOOK");
+        portefeuille.acheter(action1, 10);
+        portefeuille.acheter(action2, 5);
+
+        assert portefeuille.getActions().size() == 2;
+        assert portefeuille.getQuantite(action1) == 10;
+        assert portefeuille.getQuantite(action2) == 5;
path: src/test/java/fr/utc/miage/shares/PortefeuilleTest.java
user: login: Munozmu
body: sur tous les tests c'est bien de respecter la formulation du cours je pense @MathysALZURIA 
<img width="1156" alt="image" src="https://github.com/user-attachments/assets/094c705d-b1c2-44a1-9cc5-51fdc846ca76" />

created_at: 2025-05-21T09:37:25Z
author_association: COLLABORATOR
diff_hunk: @@ -1,8 +1,74 @@
 package fr.utc.miage.shares;
 
+import fr.utc.miage.shares.Action;
+import fr.utc.miage.shares.ActionSimple;
+import fr.utc.miage.shares.ActionComposee;
+
+import java.util.HashMap;
+import java.util.Map;
+
 import org.junit.jupiter.api.Test;
 
 public class PortefeuilleTest {
+
+    //test d'affichage des actions
+    @Test
+    void testConsulterPortefeuilleActionSimple() {
+        Portefeuille portefeuille = new Portefeuille();
+        Action action1 = new ActionSimple("GOOGLE");
+        Action action2 = new ActionSimple("FACEBOOK");
path: src/test/java/fr/utc/miage/shares/PortefeuilleTest.java
user: login: Munozmu
body: si c'est des Actions ou des objets qui vont être réutilisés dans plusieurs tests, déclares-les de manière globale au niveau classe de test 
exemple : 
`private static final ActionSimple action = new ActionSimple("APPL");`
created_at: 2025-05-21T09:38:49Z
author_association: COLLABORATOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-05-23T07:45:22Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=maxime64100_sharePortfolio---VSCode&pullRequest=41) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [11 New issues](https://sonarcloud.io/project/issues?id=maxime64100_sharePortfolio---VSCode&pullRequest=41&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=maxime64100_sharePortfolio---VSCode&pullRequest=41&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=maxime64100_sharePortfolio---VSCode&pullRequest=41&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=maxime64100_sharePortfolio---VSCode&pullRequest=41&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=maxime64100_sharePortfolio---VSCode&pullRequest=41&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=maxime64100_sharePortfolio---VSCode&pullRequest=41)


author_association: NONE