commit
7a20b0ef89
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -0,0 +1,68 @@
|
||||
package test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import model.Commande;
|
||||
import model.CommandeAllumerJacuzzi;
|
||||
import model.CommandeAllumerLampe;
|
||||
import model.CommandeAllumerStereo;
|
||||
import model.CommandeAllumerTV;
|
||||
import model.CommandeEteindreJacuzzi;
|
||||
import model.CommandeEteindreLampe;
|
||||
import model.CommandeEteindreStereo;
|
||||
import model.CommandeEteindreTV;
|
||||
import model.Jacuzzi;
|
||||
import model.Lampe;
|
||||
import model.MacroCommande;
|
||||
import model.Stereo;
|
||||
import model.TV;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ChargeurTelecommandeTest {
|
||||
|
||||
@Test
|
||||
public void testMacroAllumage() {
|
||||
// Création des équipements
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
TV tv = new TV("Séjour");
|
||||
Stereo stereo = new Stereo("Séjour");
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
|
||||
// Création des commandes pour allumer les équipements
|
||||
CommandeAllumerLampe lampeAllumee = new CommandeAllumerLampe(lampe);
|
||||
CommandeAllumerStereo stereoAllumee = new CommandeAllumerStereo(stereo);
|
||||
CommandeAllumerTV tvAllumee = new CommandeAllumerTV(tv);
|
||||
CommandeAllumerJacuzzi jacuzziAllume = new CommandeAllumerJacuzzi(jacuzzi);
|
||||
|
||||
// Création de la macro commande d'allumage
|
||||
Commande[] allumageGroupe = {lampeAllumee, stereoAllumee, tvAllumee, jacuzziAllume};
|
||||
MacroCommande macroAllumageGroupe = new MacroCommande(allumageGroupe);
|
||||
|
||||
// Vérification que la macro commande d'allumage fonctionne correctement
|
||||
assertNotNull(macroAllumageGroupe);
|
||||
macroAllumageGroupe.executer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMacroExtinction() {
|
||||
// Création des équipements
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
TV tv = new TV("Séjour");
|
||||
Stereo stereo = new Stereo("Séjour");
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
|
||||
// Création des commandes pour éteindre les équipements
|
||||
CommandeEteindreLampe lampeEteinte = new CommandeEteindreLampe(lampe);
|
||||
CommandeEteindreStereo stereoEteinte = new CommandeEteindreStereo(stereo);
|
||||
CommandeEteindreTV tvEteinte = new CommandeEteindreTV(tv);
|
||||
CommandeEteindreJacuzzi jacuzziEteint = new CommandeEteindreJacuzzi(jacuzzi);
|
||||
|
||||
// Création de la macro commande d'extinction
|
||||
Commande[] extinctionGroupe = {lampeEteinte, stereoEteinte, tvEteinte, jacuzziEteint};
|
||||
MacroCommande macroExtinctionGroupe = new MacroCommande(extinctionGroupe);
|
||||
|
||||
// Vérification que la macro commande d'extinction fonctionne correctement
|
||||
assertNotNull(macroExtinctionGroupe);
|
||||
}
|
||||
}
|
@ -1,43 +1,214 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
//package test;
|
||||
//
|
||||
//import static org.junit.Assert.assertEquals;
|
||||
//
|
||||
//import org.junit.Test;
|
||||
//
|
||||
//import model.Commande;
|
||||
//import model.PasDeCommande;
|
||||
//import model.Telecommande;
|
||||
//import static org.junit.Assert.*;
|
||||
//
|
||||
//public class TelecommandeTest {
|
||||
//
|
||||
// @Test
|
||||
// public void testTelecommande() {
|
||||
// Telecommande telecommande = new Telecommande();
|
||||
// Commande marcheCommande = new PasDeCommande();
|
||||
// Commande arretCommande = new PasDeCommande();
|
||||
//
|
||||
// telecommande.setCommande(0, marcheCommande, arretCommande);
|
||||
// telecommande.boutonMarchePresse(0);
|
||||
//
|
||||
// assertEquals(marcheCommande, telecommande.commandeAnnulation);
|
||||
// }
|
||||
//
|
||||
//// @Test
|
||||
//// public void testToString() {
|
||||
//// // Arrange
|
||||
//// Telecommande telecommande = new Telecommande();
|
||||
//// Commande marcheCommande = new PasDeCommande();
|
||||
//// Commande arretCommande = new PasDeCommande();
|
||||
//// telecommande.setCommande(0, marcheCommande, arretCommande);
|
||||
////
|
||||
//// // Act
|
||||
//// String result = telecommande.toString();
|
||||
////
|
||||
//// // Assert
|
||||
//// String expected = "\n------ Télécommande -------\n" +
|
||||
//// "[empt 0] PasDeCommande PasDeCommande\n" +
|
||||
//// "[annulation] PasDeCommande\n";
|
||||
//// assertEquals(expected, result);
|
||||
//// }
|
||||
//}
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import model.Commande;
|
||||
import model.CommandeAllumerLampe;
|
||||
import model.CommandeEteindreLampe;
|
||||
import model.Lampe;
|
||||
import model.PasDeCommande;
|
||||
import model.Telecommande;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TelecommandeTest {
|
||||
|
||||
@Test
|
||||
public void testTelecommande() {
|
||||
public void testSetCommande() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeMarche = new CommandeAllumerLampe(lampe);
|
||||
Commande commandeArret = new CommandeEteindreLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
assertSame(commandeMarche, telecommande.commandesMarche[0]);
|
||||
assertSame(commandeArret, telecommande.commandesArret[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonMarchePresse() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande marcheCommande = new PasDeCommande();
|
||||
Commande arretCommande = new PasDeCommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeMarche = new CommandeAllumerLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, commandeMarche, null);
|
||||
|
||||
telecommande.setCommande(0, marcheCommande, arretCommande);
|
||||
telecommande.boutonMarchePresse(0);
|
||||
|
||||
assertEquals(marcheCommande, telecommande.commandeAnnulation);
|
||||
assertTrue(lampe.estAllumee());
|
||||
assertSame(commandeMarche, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testToString() {
|
||||
// // Arrange
|
||||
// Telecommande telecommande = new Telecommande();
|
||||
// Commande marcheCommande = new PasDeCommande();
|
||||
// Commande arretCommande = new PasDeCommande();
|
||||
// telecommande.setCommande(0, marcheCommande, arretCommande);
|
||||
//
|
||||
// // Act
|
||||
// String result = telecommande.toString();
|
||||
//
|
||||
// // Assert
|
||||
// String expected = "\n------ Télécommande -------\n" +
|
||||
// "[empt 0] PasDeCommande PasDeCommande\n" +
|
||||
// "[annulation] PasDeCommande\n";
|
||||
// assertEquals(expected, result);
|
||||
// }
|
||||
@Test
|
||||
public void testBoutonArretPresse() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeArret = new CommandeEteindreLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, null, commandeArret);
|
||||
|
||||
telecommande.boutonArretPresse(0);
|
||||
|
||||
assertFalse(lampe.estAllumee());
|
||||
assertSame(commandeArret, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonAnnulPresse() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeMarche = new CommandeAllumerLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, commandeMarche, null);
|
||||
|
||||
telecommande.boutonMarchePresse(0);
|
||||
assertTrue(lampe.estAllumee());
|
||||
|
||||
telecommande.boutonAnnulPresse();
|
||||
|
||||
assertFalse(lampe.estAllumee());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
String expected = "\n------ Télécommande -------\n";
|
||||
for (int i = 0; i < 7; i++) {
|
||||
expected += "[empt " + i + "] model.PasDeCommande model.PasDeCommande\n";
|
||||
}
|
||||
expected += "[annulation] model.PasDeCommande\n";
|
||||
|
||||
assertEquals(expected, telecommande.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstruction() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
|
||||
assertNotNull(telecommande.commandesMarche);
|
||||
assertNotNull(telecommande.commandesArret);
|
||||
assertNotNull(telecommande.commandeAnnulation);
|
||||
|
||||
assertEquals(7, telecommande.commandesMarche.length);
|
||||
assertEquals(7, telecommande.commandesArret.length);
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
assertTrue(telecommande.commandesMarche[i] instanceof PasDeCommande);
|
||||
assertTrue(telecommande.commandesArret[i] instanceof PasDeCommande);
|
||||
}
|
||||
|
||||
assertTrue(telecommande.commandeAnnulation instanceof PasDeCommande);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCommande1() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerLampe(new Lampe("Test"));
|
||||
Commande commandeArret = new CommandeEteindreLampe(new Lampe("Test"));
|
||||
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
assertSame(commandeMarche, telecommande.commandesMarche[0]);
|
||||
assertSame(commandeArret, telecommande.commandesArret[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonMarchePresse1() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeMarche = new CommandeAllumerLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, commandeMarche, null);
|
||||
|
||||
telecommande.boutonMarchePresse(0);
|
||||
|
||||
assertTrue(lampe.estAllumee());
|
||||
assertSame(commandeMarche, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonArretPresse1() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeArret = new CommandeEteindreLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, null, commandeArret);
|
||||
|
||||
telecommande.boutonArretPresse(0);
|
||||
|
||||
assertFalse(lampe.estAllumee());
|
||||
assertSame(commandeArret, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonAnnulPresse1() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Lampe lampe = new Lampe("Test");
|
||||
Commande commandeMarche = new CommandeAllumerLampe(lampe);
|
||||
|
||||
telecommande.setCommande(0, commandeMarche, null);
|
||||
|
||||
telecommande.boutonMarchePresse(0);
|
||||
assertTrue(lampe.estAllumee());
|
||||
|
||||
telecommande.boutonAnnulPresse();
|
||||
|
||||
assertFalse(lampe.estAllumee());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString1() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
String expected = "\n------ Télécommande -------\n";
|
||||
for (int i = 0; i < 7; i++) {
|
||||
expected += "[empt " + i + "] model.PasDeCommande model.PasDeCommande\n";
|
||||
}
|
||||
expected += "[annulation] model.PasDeCommande\n";
|
||||
|
||||
assertEquals(expected, telecommande.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="corr_telecommande_groupe/models"/>
|
||||
<classpathentry kind="src" path="corr_telecommande_groupe/tests"/>
|
||||
<classpathentry kind="output" path="out/production/ex_patron_macrocommande"/>
|
||||
</classpath>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ex_patron_macrocommande</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,37 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class ChargeurTelecommande {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Telecommande remoteControl = new Telecommande();
|
||||
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
TV tv = new TV("Séjour");
|
||||
Stereo stereo = new Stereo("Séjour");
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
|
||||
CommandeAllumerLampe lampeAllumee = new CommandeAllumerLampe(lampe);
|
||||
CommandeAllumerStereo stereoAllumee = new CommandeAllumerStereo(stereo);
|
||||
CommandeAllumerTV tvAllumee = new CommandeAllumerTV(tv);
|
||||
CommandeAllumerJacuzzi jacuzziAllume = new CommandeAllumerJacuzzi(jacuzzi);
|
||||
CommandeEteindreLampe lampeEteinte = new CommandeEteindreLampe(lampe);
|
||||
CommandeEteindreStereo stereoEteinte = new CommandeEteindreStereo(stereo);
|
||||
CommandeEteindreTV tvEteinte = new CommandeEteindreTV(tv);
|
||||
CommandeEteindreJacuzzi jacuzziEteint = new CommandeEteindreJacuzzi(jacuzzi);
|
||||
|
||||
Commande[] allumageGroupe = { lampeAllumee, stereoAllumee, tvAllumee, jacuzziAllume};
|
||||
Commande[] extinctionGroupe = { lampeEteinte, stereoEteinte, tvEteinte, jacuzziEteint};
|
||||
|
||||
MacroCommande macroAllumageGroupe = new MacroCommande(allumageGroupe);
|
||||
MacroCommande macroExtinctionGroupe = new MacroCommande(extinctionGroupe);
|
||||
|
||||
remoteControl.setCommande(0, macroAllumageGroupe, macroExtinctionGroupe);
|
||||
|
||||
System.out.println(remoteControl);
|
||||
System.out.println("---Exécution de Macro Marche ---");
|
||||
remoteControl.boutonMarchePresse(0);
|
||||
System.out.println("--- Exécution de Macro Arret ---");
|
||||
remoteControl.boutonArretPresse(0);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public interface Commande {
|
||||
public void executer();
|
||||
public void annuler();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeAllumerJacuzzi implements Commande {
|
||||
Jacuzzi jacuzzi;
|
||||
|
||||
public CommandeAllumerJacuzzi(Jacuzzi jacuzzi) {
|
||||
this.jacuzzi = jacuzzi;
|
||||
}
|
||||
public void executer() {
|
||||
jacuzzi.allumer();
|
||||
jacuzzi.setTemperature(40);
|
||||
jacuzzi.bouillonner();
|
||||
}
|
||||
public void annuler() {
|
||||
jacuzzi.eteindre();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeAllumerLampe implements Commande {
|
||||
Lampe lampe;
|
||||
|
||||
public CommandeAllumerLampe(Lampe lampe) {
|
||||
this.lampe = lampe;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
lampe.marche();
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
lampe.arret();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeAllumerLampeSejour implements Commande {
|
||||
Lampe lampe;
|
||||
|
||||
public CommandeAllumerLampeSejour(Lampe lampe) {
|
||||
this.lampe = lampe;
|
||||
}
|
||||
public void executer() {
|
||||
lampe.arret();
|
||||
}
|
||||
public void annuler() {
|
||||
lampe.marche();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeAllumerStereo implements Commande {
|
||||
Stereo stereo;
|
||||
|
||||
public CommandeAllumerStereo(Stereo stereo) {
|
||||
this.stereo = stereo;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
stereo.marche();
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
stereo.arret();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeAllumerStereoAvecCD implements Commande {
|
||||
Stereo stereo;
|
||||
|
||||
public CommandeAllumerStereoAvecCD(Stereo stereo) {
|
||||
this.stereo = stereo;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
stereo.marche();
|
||||
stereo.setCD();
|
||||
stereo.setVolume(11);
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
stereo.arret();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeAllumerTV implements Commande {
|
||||
TV tv;
|
||||
|
||||
public CommandeAllumerTV(TV tv) {
|
||||
this.tv= tv;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
tv.marche();
|
||||
tv.selectionnerCanal();
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
tv.arret();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeEteindreJacuzzi implements Commande {
|
||||
Jacuzzi jacuzzi;
|
||||
|
||||
public CommandeEteindreJacuzzi(Jacuzzi jacuzzi) {
|
||||
this.jacuzzi = jacuzzi;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
jacuzzi.setTemperature(36);
|
||||
jacuzzi.eteindre();
|
||||
}
|
||||
public void annuler() {
|
||||
jacuzzi.allumer();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeEteindreLampe implements Commande {
|
||||
Lampe lampe;
|
||||
|
||||
public CommandeEteindreLampe(Lampe lampe) {
|
||||
this.lampe = lampe;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
lampe.arret();
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
lampe.marche();
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeEteindreLampeSejour implements Commande {
|
||||
Lampe lampe;
|
||||
|
||||
public CommandeEteindreLampeSejour(Lampe lampe) {
|
||||
this.lampe = lampe;
|
||||
}
|
||||
public void executer() {
|
||||
lampe.marche();
|
||||
}
|
||||
public void annuler() {
|
||||
lampe.arret();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeEteindreStereo implements Commande {
|
||||
Stereo stereo;
|
||||
|
||||
public CommandeEteindreStereo(Stereo stereo) {
|
||||
this.stereo = stereo;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
stereo.arret();
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
stereo.marche();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeEteindreTV implements Commande {
|
||||
TV tv;
|
||||
|
||||
public CommandeEteindreTV(TV tv) {
|
||||
this.tv= tv;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
tv.arret();
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
tv.marche();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeEteindreVentilateur implements Commande {
|
||||
Ventilateur ventilateur;
|
||||
int derniereVitesse;
|
||||
|
||||
public CommandeEteindreVentilateur(Ventilateur ventilateur) {
|
||||
this.ventilateur = ventilateur;
|
||||
}
|
||||
public void executer() {
|
||||
derniereVitesse = ventilateur.getVitesse();
|
||||
ventilateur.arreter();
|
||||
}
|
||||
public void annuler() {
|
||||
switch (derniereVitesse) {
|
||||
case Ventilateur.RAPIDE: ventilateur.rapide(); break;
|
||||
case Ventilateur.MOYEN: ventilateur.moyen(); break;
|
||||
case Ventilateur.LENT: ventilateur.lent(); break;
|
||||
default: ventilateur.arreter(); break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeVentilateurMoyen implements Commande {
|
||||
Ventilateur ventilateur;
|
||||
int derniereVitesse;
|
||||
|
||||
public CommandeVentilateurMoyen(Ventilateur ventilateur) {
|
||||
this.ventilateur = ventilateur;
|
||||
}
|
||||
public void executer() {
|
||||
derniereVitesse = ventilateur.getVitesse();
|
||||
ventilateur.moyen();
|
||||
}
|
||||
public void annuler() {
|
||||
switch (derniereVitesse) {
|
||||
case Ventilateur.RAPIDE: ventilateur.rapide(); break;
|
||||
case Ventilateur.MOYEN: ventilateur.moyen(); break;
|
||||
case Ventilateur.LENT: ventilateur.lent(); break;
|
||||
default: ventilateur.arreter(); break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class CommandeVentilateurRapide implements Commande {
|
||||
Ventilateur ventilateur;
|
||||
int derniereVitesse;
|
||||
|
||||
public CommandeVentilateurRapide(Ventilateur ventilateur) {
|
||||
this.ventilateur = ventilateur;
|
||||
}
|
||||
public void executer() {
|
||||
derniereVitesse = ventilateur.getVitesse();
|
||||
ventilateur.rapide();
|
||||
}
|
||||
public void annuler() {
|
||||
switch (derniereVitesse) {
|
||||
case Ventilateur.RAPIDE: ventilateur.rapide(); break;
|
||||
case Ventilateur.MOYEN: ventilateur.moyen(); break;
|
||||
case Ventilateur.LENT: ventilateur.lent(); break;
|
||||
default: ventilateur.arreter(); break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
public class Jacuzzi {
|
||||
boolean allume;
|
||||
int temperature;
|
||||
|
||||
public Jacuzzi() {
|
||||
}
|
||||
|
||||
public void allumer() {
|
||||
allume = true;
|
||||
}
|
||||
|
||||
public void eteindre() {
|
||||
allume = false;
|
||||
}
|
||||
|
||||
public void bouillonner() {
|
||||
if (allume) {
|
||||
System.out.println("Le jaccuzi bouillonne !");
|
||||
} else {
|
||||
throw new IllegalStateException("Impossible de bouillonner lorsque le jacuzzi est éteint.");
|
||||
}
|
||||
}
|
||||
|
||||
public void marche() {
|
||||
if (allume) {
|
||||
System.out.println("Le jaccuzi est en marche");
|
||||
} else {
|
||||
throw new IllegalStateException("Impossible de démarrer le jacuzzi lorsque celui-ci est éteint.");
|
||||
}
|
||||
}
|
||||
|
||||
public void arret() {
|
||||
if (allume) {
|
||||
System.out.println("Le jaccuzi est arrêté");
|
||||
} else {
|
||||
throw new IllegalStateException("Impossible d'arrêter le jacuzzi car il est déjà éteint.");
|
||||
}
|
||||
}
|
||||
|
||||
public void setTemperature(int temperature) {
|
||||
if (temperature > this.temperature) {
|
||||
System.out.println("Le jacuzzi chauffe à " + temperature + "°");
|
||||
} else {
|
||||
System.out.println("Le jacuzzi refroidit à " + temperature + "°");
|
||||
}
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class Lampe {
|
||||
String localisation;
|
||||
int niveau;
|
||||
|
||||
public Lampe(String localisation) {
|
||||
this.localisation = localisation;
|
||||
}
|
||||
|
||||
public void marche() {
|
||||
niveau = 100;
|
||||
System.out.println(localisation+": lumière allumée");
|
||||
}
|
||||
|
||||
public void arret() {
|
||||
niveau = 0;
|
||||
System.out.println(localisation+": lumière éteinte");
|
||||
}
|
||||
|
||||
public void attenuer(int niveau) {
|
||||
this.niveau = niveau;
|
||||
if (niveau == 0) {
|
||||
arret();
|
||||
}
|
||||
else {
|
||||
System.out.println("Le niveau de la lampe est positionné sur " + niveau + "%");
|
||||
}
|
||||
}
|
||||
|
||||
public int getNiveau() {
|
||||
return niveau;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class MacroCommande implements Commande {
|
||||
Commande[] commandes;
|
||||
|
||||
public MacroCommande(Commande[] commandes) {
|
||||
this.commandes = commandes;
|
||||
}
|
||||
|
||||
public void executer() {
|
||||
for (int i = 0; i < commandes.length; i++) {
|
||||
commandes[i].executer();
|
||||
}
|
||||
}
|
||||
|
||||
public void annuler() {
|
||||
for (int i = 0; i < commandes.length; i++) {
|
||||
commandes[i].annuler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class PasDeCommande implements Commande {
|
||||
public void executer() { }
|
||||
public void annuler() { }
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
public class Stereo {
|
||||
String localisation;
|
||||
boolean allume;
|
||||
int volume;
|
||||
|
||||
public Stereo(String localisation) {
|
||||
this.localisation = localisation;
|
||||
}
|
||||
|
||||
public void marche() {
|
||||
this.allume = true;
|
||||
System.out.println(localisation + ": stéréo allumée");
|
||||
}
|
||||
|
||||
public void arret() {
|
||||
this.allume = false;
|
||||
System.out.println(localisation + ": stéréo éteinte");
|
||||
}
|
||||
|
||||
public void setCD() {
|
||||
if (!allume) {
|
||||
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
|
||||
}
|
||||
System.out.println(localisation + ": stéréo réglée pour l'entrée CD");
|
||||
}
|
||||
|
||||
public void setDVD() {
|
||||
if (!allume) {
|
||||
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
|
||||
}
|
||||
System.out.println(localisation + ": stéréo réglée pour l'entrée DVD");
|
||||
}
|
||||
|
||||
public void setRadio() {
|
||||
if (!allume) {
|
||||
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
|
||||
}
|
||||
System.out.println(localisation + ": stéréo réglée pour la radio");
|
||||
}
|
||||
|
||||
public void setVolume(int volume) {
|
||||
if (!allume) {
|
||||
throw new IllegalStateException("La stéréo est éteinte. Allumez-la d'abord.");
|
||||
}
|
||||
if (volume < 0 || volume > 11) {
|
||||
throw new IllegalArgumentException("Le volume doit être compris entre 0 et 11.");
|
||||
}
|
||||
this.volume = volume;
|
||||
System.out.println(localisation + ": le volume stéréo est " + volume);
|
||||
}
|
||||
|
||||
public int getVolume() {
|
||||
return volume;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class TV {
|
||||
String localisation;
|
||||
int canal;
|
||||
|
||||
public TV(String location) {
|
||||
this.localisation = location;
|
||||
}
|
||||
|
||||
public void marche() {
|
||||
System.out.println(localisation + ": la télé est allumée");
|
||||
}
|
||||
|
||||
public void arret() {
|
||||
System.out.println(localisation + ": la télé est éteinte");
|
||||
}
|
||||
|
||||
public void selectionnerCanal() {
|
||||
this.canal = 3;
|
||||
System.out.println(localisation + ": le canal est positionné sur VCR");
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
//
|
||||
// Voici l'invocateur
|
||||
//
|
||||
public class Telecommande {
|
||||
Commande[] commandesMarche;
|
||||
Commande[] commandesArret;
|
||||
Commande commandeAnnulation;
|
||||
|
||||
public Telecommande() {
|
||||
commandesMarche = new Commande[7];
|
||||
commandesArret = new Commande[7];
|
||||
|
||||
Commande pasDeCommande = new PasDeCommande();
|
||||
for(int i=0;i<7;i++) {
|
||||
commandesMarche[i] = pasDeCommande;
|
||||
commandesArret[i] = pasDeCommande;
|
||||
}
|
||||
commandeAnnulation = pasDeCommande;
|
||||
}
|
||||
|
||||
public void setCommande(int empt, Commande comMarche, Commande comArret) {
|
||||
commandesMarche[empt] = comMarche;
|
||||
commandesArret[empt] = comArret;
|
||||
}
|
||||
|
||||
public void boutonMarchePresse(int empt) {
|
||||
commandesMarche[empt].executer();
|
||||
commandeAnnulation = commandesMarche[empt];
|
||||
}
|
||||
|
||||
public void boutonArretPresse(int empt) {
|
||||
commandesArret[empt].executer();
|
||||
commandeAnnulation = commandesArret[empt];
|
||||
}
|
||||
|
||||
public void boutonAnnulPresse() {
|
||||
commandeAnnulation.annuler();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer stringBuff = new StringBuffer();
|
||||
stringBuff.append("\n------ Télécommande -------\n");
|
||||
for (int i = 0; i < commandesMarche.length; i++) {
|
||||
stringBuff.append("[empt " + i + "] " + commandesMarche[i].getClass().getName()
|
||||
+ " " + commandesArret[i].getClass().getName() + "\n");
|
||||
}
|
||||
stringBuff.append("[annulation] " + commandeAnnulation.getClass().getName() + "\n");
|
||||
return stringBuff.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
// package tetepremiere.commande.groupe;
|
||||
|
||||
public class Ventilateur {
|
||||
public static final int RAPIDE = 3;
|
||||
public static final int MOYEN = 2;
|
||||
public static final int LENT = 1;
|
||||
public static final int ARRET = 0;
|
||||
String localisation;
|
||||
int vitesse;
|
||||
|
||||
public Ventilateur(String localisation) {
|
||||
this.localisation = localisation;
|
||||
}
|
||||
|
||||
public void rapide() {
|
||||
// regler le ventilateur sur rapide
|
||||
vitesse = RAPIDE;
|
||||
System.out.println(localisation + ": ventilateur sur rapide");
|
||||
}
|
||||
|
||||
public void moyen() {
|
||||
// regler le ventilateur sur moyen
|
||||
vitesse = MOYEN;
|
||||
System.out.println(localisation + ": ventilateur sur moyen");
|
||||
}
|
||||
|
||||
public void lent() {
|
||||
// regler le ventilateur sur lent
|
||||
vitesse = LENT;
|
||||
System.out.println(localisation + ": ventilateur sur lent");
|
||||
}
|
||||
|
||||
public void arreter() {
|
||||
// arrete le ventilateur
|
||||
vitesse = 0;
|
||||
System.out.println(localisation + ": ventilateur arrêté");
|
||||
}
|
||||
|
||||
public int getVitesse() {
|
||||
return vitesse;
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CommandesTest {
|
||||
@Test
|
||||
public void testCommandeAllumerJacuzzi() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
Commande commande = new CommandeAllumerJacuzzi(jacuzzi);
|
||||
commande.executer();
|
||||
|
||||
assertTrue(jacuzzi.allume);
|
||||
assertEquals(40, jacuzzi.temperature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeEteindreJacuzzi() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
Commande commande = new CommandeEteindreJacuzzi(jacuzzi);
|
||||
commande.executer();
|
||||
|
||||
assertFalse(jacuzzi.allume);
|
||||
assertEquals(36, jacuzzi.temperature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAnnulerJacuzzi() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
Commande commande = new CommandeAllumerJacuzzi(jacuzzi);
|
||||
commande.executer();
|
||||
commande.annuler();
|
||||
|
||||
assertFalse(jacuzzi.allume);
|
||||
assertEquals(40, jacuzzi.temperature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPasDeCommande() {
|
||||
Commande pasDeCommande = new PasDeCommande();
|
||||
pasDeCommande.executer();
|
||||
pasDeCommande.annuler();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMacroCommande() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
Commande commande1 = new CommandeAllumerJacuzzi(jacuzzi);
|
||||
Commande commande2 = new CommandeEteindreJacuzzi(jacuzzi);
|
||||
Commande[] commandes = {commande1, commande2};
|
||||
MacroCommande macroCommande = new MacroCommande(commandes);
|
||||
macroCommande.executer();
|
||||
macroCommande.annuler();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAllumerLampe() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
Commande commande = new CommandeAllumerLampe(lampe);
|
||||
commande.executer();
|
||||
assertEquals(100, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeEteindreLampe() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
Commande commande = new CommandeEteindreLampe(lampe);
|
||||
commande.executer();
|
||||
assertEquals(0, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAnnulerLampe() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
Commande commande = new CommandeAllumerLampe(lampe);
|
||||
commande.executer();
|
||||
commande.annuler();
|
||||
assertEquals(0, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeEteindreLampeAnnuler() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
Commande commande = new CommandeEteindreLampe(lampe);
|
||||
commande.executer();
|
||||
commande.annuler();
|
||||
assertEquals(100, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAllumerLampeSejour() {
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
Commande commande = new CommandeAllumerLampeSejour(lampe);
|
||||
commande.executer();
|
||||
assertEquals(0, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeEteindreLampeSejour() {
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
Commande commande = new CommandeEteindreLampeSejour(lampe);
|
||||
commande.executer();
|
||||
assertEquals(100, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAnnulerLampeSejour() {
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
Commande commande = new CommandeAllumerLampeSejour(lampe);
|
||||
commande.executer();
|
||||
commande.annuler();
|
||||
assertEquals(100, lampe.niveau);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAnnulerEteindreLampeSejour() {
|
||||
Lampe lampe = new Lampe("Séjour");
|
||||
Commande commande = new CommandeEteindreLampeSejour(lampe);
|
||||
commande.executer();
|
||||
commande.annuler();
|
||||
assertEquals(0, lampe.niveau);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCommandeAllumerStereoAvecCD() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
Commande commande = new CommandeAllumerStereoAvecCD(stereo);
|
||||
commande.executer();
|
||||
assertEquals(11, stereo.volume);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAnnulerStereoAvecCD() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
Commande commande = new CommandeAllumerStereoAvecCD(stereo);
|
||||
commande.executer();
|
||||
commande.annuler();
|
||||
assertFalse(stereo.allume);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandeAllumerTV() {
|
||||
TV tv = new TV("Salon");
|
||||
Commande commande = new CommandeAllumerTV(tv);
|
||||
commande.executer();
|
||||
assertEquals(3, tv.canal);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class JacuzziTest {
|
||||
|
||||
@Test
|
||||
public void testAllumer() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.allumer();
|
||||
assertTrue(jacuzzi.allume);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEteindre() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.allumer();
|
||||
jacuzzi.eteindre();
|
||||
assertFalse(jacuzzi.allume);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBouillonnerQuandAllume() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.allumer();
|
||||
assertDoesNotThrow(jacuzzi::bouillonner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBouillonnerQuandPasAllume() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
assertThrows(IllegalStateException.class, jacuzzi::bouillonner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarcheQuandAllume() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.allumer();
|
||||
assertDoesNotThrow(jacuzzi::marche);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarcheQuandPasAllume() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
assertThrows(IllegalStateException.class, jacuzzi::marche);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArretQuandAllume() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.allumer();
|
||||
assertDoesNotThrow(jacuzzi::arret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArretQuandPasAllume() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
assertThrows(IllegalStateException.class, jacuzzi::arret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAugmenterTemp() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.setTemperature(30);
|
||||
jacuzzi.setTemperature(35);
|
||||
assertEquals(35, jacuzzi.temperature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaisserTemp() {
|
||||
Jacuzzi jacuzzi = new Jacuzzi();
|
||||
jacuzzi.setTemperature(30);
|
||||
jacuzzi.setTemperature(25);
|
||||
assertEquals(25, jacuzzi.temperature);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class LampeTest {
|
||||
|
||||
@Test
|
||||
public void testMarche() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
lampe.marche();
|
||||
assertEquals(100, lampe.getNiveau());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArret() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
lampe.marche();
|
||||
lampe.arret();
|
||||
assertEquals(0, lampe.getNiveau());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttenuer() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
lampe.attenuer(50);
|
||||
assertEquals(50, lampe.getNiveau());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttenuerToZero() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
lampe.attenuer(0);
|
||||
assertEquals(0, lampe.getNiveau());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttenuerToZeroAfterOn() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
lampe.marche();
|
||||
lampe.attenuer(0);
|
||||
assertEquals(0, lampe.getNiveau());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNiveau() {
|
||||
Lampe lampe = new Lampe("Salon");
|
||||
assertEquals(0, lampe.getNiveau());
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class StereoTest {
|
||||
|
||||
@Test
|
||||
public void testSetCDQuandPasAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.arret();
|
||||
assertThrows(IllegalStateException.class, stereo::setCD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDVDQuandPasAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.arret();
|
||||
assertThrows(IllegalStateException.class, stereo::setDVD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRadioQuandPasAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.arret();
|
||||
assertThrows(IllegalStateException.class, stereo::setRadio);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCDQuandAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.marche();
|
||||
assertDoesNotThrow(stereo::setCD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDVDQuandAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.marche();
|
||||
assertDoesNotThrow(stereo::setDVD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRadioQuandAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.marche();
|
||||
assertDoesNotThrow(stereo::setRadio);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVolumeQuandAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.marche();
|
||||
assertDoesNotThrow(() -> stereo.setVolume(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVolumeQuandPasAllume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.arret();
|
||||
assertThrows(IllegalStateException.class, () -> stereo.setVolume(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVolumeOutOfRange() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.marche();
|
||||
assertThrows(IllegalArgumentException.class, () -> stereo.setVolume(20));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetVolume() {
|
||||
Stereo stereo = new Stereo("Salon");
|
||||
stereo.marche();
|
||||
stereo.setVolume(8);
|
||||
assertEquals(8, stereo.getVolume());
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TVTest {
|
||||
|
||||
@Test
|
||||
public void testMarche() {
|
||||
TV tv = new TV("Salon");
|
||||
assertDoesNotThrow(tv::marche);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArret() {
|
||||
TV tv = new TV("Salon");
|
||||
assertDoesNotThrow(tv::arret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectionnerCanal() {
|
||||
TV tv = new TV("Salon");
|
||||
tv.selectionnerCanal();
|
||||
assertEquals(3, tv.canal);
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TelecommandeTest {
|
||||
|
||||
@Test
|
||||
public void testSetCommande() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerJacuzzi(new Jacuzzi());
|
||||
Commande commandeArret = new CommandeEteindreJacuzzi(new Jacuzzi());
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
assertEquals(commandeMarche, telecommande.commandesMarche[0]);
|
||||
assertEquals(commandeArret, telecommande.commandesArret[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonMarchePresse() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerLampe(new Lampe("Salon"));
|
||||
Commande commandeArret = new CommandeEteindreLampe(new Lampe("Salon"));
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
telecommande.boutonMarchePresse(0);
|
||||
assertEquals(commandeMarche, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonArretPresse() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerTV(new TV("Salon"));
|
||||
Commande commandeArret = new CommandeEteindreTV(new TV("Salon"));
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
telecommande.boutonArretPresse(0);
|
||||
assertEquals(commandeArret, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoutonAnnulPresse() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerStereo(new Stereo("Salon"));
|
||||
Commande commandeArret = new CommandeEteindreStereo(new Stereo("Salon"));
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
telecommande.boutonMarchePresse(0);
|
||||
telecommande.boutonAnnulPresse();
|
||||
assertEquals(commandeMarche, telecommande.commandeAnnulation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMacroCommande() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commande1 = new CommandeEteindreVentilateur(new Ventilateur("Salon"));
|
||||
Commande commande2 = new CommandeVentilateurMoyen(new Ventilateur("Salon"));
|
||||
Commande commande3 = new CommandeVentilateurRapide(new Ventilateur("Salon"));
|
||||
Commande[] commandes = {commande1, commande2, commande3};
|
||||
MacroCommande macroCommande = new MacroCommande(commandes);
|
||||
|
||||
telecommande.setCommande(0, macroCommande, new PasDeCommande());
|
||||
telecommande.boutonMarchePresse(0);
|
||||
|
||||
assertEquals(commande1, ((MacroCommande) telecommande.commandesMarche[0]).commandes[0]);
|
||||
assertEquals(commande2, ((MacroCommande) telecommande.commandesMarche[0]).commandes[1]);
|
||||
assertEquals(commande3, ((MacroCommande) telecommande.commandesMarche[0]).commandes[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCommandeStereoCD() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerStereoAvecCD(new Stereo("Salon"));
|
||||
Commande commandeArret = new CommandeEteindreStereo(new Stereo("Salon"));
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
assertEquals(commandeMarche, telecommande.commandesMarche[0]);
|
||||
assertEquals(commandeArret, telecommande.commandesArret[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Telecommande telecommande = new Telecommande();
|
||||
Commande commandeMarche = new CommandeAllumerLampeSejour(new Lampe("Salon"));
|
||||
Commande commandeArret = new CommandeEteindreLampeSejour(new Lampe("Salon"));
|
||||
telecommande.setCommande(0, commandeMarche, commandeArret);
|
||||
|
||||
String expected = "\n------ Télécommande -------\n" +
|
||||
"[empt 0] CommandeAllumerLampeSejour CommandeEteindreLampeSejour\n" +
|
||||
"[empt 1] PasDeCommande PasDeCommande\n" +
|
||||
"[empt 2] PasDeCommande PasDeCommande\n" +
|
||||
"[empt 3] PasDeCommande PasDeCommande\n" +
|
||||
"[empt 4] PasDeCommande PasDeCommande\n" +
|
||||
"[empt 5] PasDeCommande PasDeCommande\n" +
|
||||
"[empt 6] PasDeCommande PasDeCommande\n" +
|
||||
"[annulation] PasDeCommande\n";
|
||||
|
||||
assertEquals(expected, telecommande.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class VentilateurTest {
|
||||
|
||||
@Test
|
||||
public void testRapide() {
|
||||
Ventilateur ventilateur = new Ventilateur("Salon");
|
||||
ventilateur.rapide();
|
||||
assertEquals(Ventilateur.RAPIDE, ventilateur.getVitesse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoyen() {
|
||||
Ventilateur ventilateur = new Ventilateur("Salon");
|
||||
ventilateur.moyen();
|
||||
assertEquals(Ventilateur.MOYEN, ventilateur.getVitesse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLent() {
|
||||
Ventilateur ventilateur = new Ventilateur("Salon");
|
||||
ventilateur.lent();
|
||||
assertEquals(Ventilateur.LENT, ventilateur.getVitesse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArreter() {
|
||||
Ventilateur ventilateur = new Ventilateur("Salon");
|
||||
ventilateur.arreter();
|
||||
assertEquals(Ventilateur.ARRET, ventilateur.getVitesse());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/corr_telecommande_groupe/models" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/corr_telecommande_groupe/tests" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="JUnit5.8.1">
|
||||
<CLASSES>
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
|
||||
<root url="jar:///home/scratch/vidufour1/.m2/repository/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue