-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArticleTest.java
More file actions
149 lines (106 loc) · 3.92 KB
/
Copy pathArticleTest.java
File metadata and controls
149 lines (106 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import static org.junit.jupiter.api.Assertions.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ArticleTest {
private final PrintStream standardOut = System.out;
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
@BeforeEach
/** Dans la méthode setUp, nous réaffectons le flux de sortie
* standard à un nouveau PrintStream avec un ByteArrayOutputStream.
* Ce flux de sortie est l'endroit
* où les valeurs seront maintenant imprimées
*/
public void setUp() {
System.setOut(new PrintStream(outputStreamCaptor));
}
@Test
/** Test of afficherArticle() **/
public void testAfficherArticle() {
Article instance = new Article("ski",10,10,"P");
instance.afficherArticle();
String message_attendu = ("Nom article: "+instance.getNom().toUpperCase()+" Prix d'achat: "+instance.getPrixAchat()+" Prix de vente: "+instance.getPrixVente()+" Categorie: "+ instance.getCategorie());
assertEquals(message_attendu, outputStreamCaptor.toString()
.trim()); /* trimp permet de supprimer le retour à la ligne */
}
@AfterEach
/** Dans la méthode tearDown on restaure le flux de sortie intial
* car c'est une ressource partagé par d'autre parties du systèmes.
*/
public void tearDown() {
System.setOut(standardOut); }
@Test
/** Test of setPrixAchat **/
public void testsetPrixAchat() {
System.out.println("setPrixAchat");
double prix = 10.0;
Article instance = new Article("ski",10,10,"P");
instance.setPrixAchat(prix);
assertEquals(instance.getPrixAchat(), prix);
}
@Test
/** Test of getPrixAchat **/
public void testGetPrixAchat() {
System.out.println("testGetPrixAchat");
Article instance = new Article("ski",10,10,"P");
double resultat_attendu = 10.0 ;
double resultat = instance.getPrixAchat();
assertEquals(resultat_attendu,resultat);
}
@Test
/** Test of setPrixVente **/
public void testsetPrixVente() {
System.out.println("setPrixVente");
double prix = 10.0;
Article instance = new Article("ski",10,10,"P");
instance.setPrixVente(prix);
assertEquals(instance.getPrixVente(), prix);
}
@Test
/** Test of getPrixVente **/
public void testGetPrixVente() {
System.out.println("testGetPrixVente");
Article instance = new Article("ski",10,10,"P");
double resultat_attendu = 10.0 ;
double resultat = instance.getPrixVente();
assertEquals(resultat_attendu,resultat);
}
@Test
/** Test of setNom **/
public void testsetNom() {
System.out.println("testSetNom");
String nom = "ski";
Article instance = new Article("s",10,10,"P");
instance.setNom("ski");
assertEquals(instance.getNom(), nom);
}
@Test
/** Test of getNom **/
public void testGetNom() {
System.out.println("testGetNom");
Article instance = new Article("ski",10,10,"P");
String resultat_attendu = "ski" ;
String nom = instance.getNom();
assertEquals(resultat_attendu,nom);
}
@Test
/** Test of setCategorie **/
public void testsetCategorie() {
System.out.println("testSeStCategorie");
String Categorie = "P";
Article instance = new Article("s",10,10,"P");
instance.setCategorie("P");
assertEquals(instance.getCategorie(), Categorie);
}
@Test
/** Test of getCategorie **/
public void testGetCategorie() {
System.out.println("testGetCategorie");
Article instance = new Article("ski",10,10,"P");
String resultat_attendu = "P" ;
String Categorie = instance.getCategorie();
assertEquals(resultat_attendu,Categorie);
}
}