Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/test/java/java17/ex01/Method_01_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import java.util.List;


import org.junit.Test;



import java17.data.Data;
import java17.data.Person;

Expand All @@ -15,10 +18,19 @@ public class Method_01_Test {

// tag::IDao[]
interface IDao {

List<Person> findAll();

// TODO créer une méthode int sumAge()
// TODO Cette méthode retourne le résultat de l'addition des ages des personnes
public default int sumAge() {
int result = 0;
for (Person personne :findAll()) {
result += personne.getAge();
}
return result;
}

}
// end::IDao[]

Expand All @@ -42,13 +54,17 @@ public List<Person> findAll() {
}
}


@Test
public void test_daoA_sumAge() throws Exception {

DaoA daoA = new DaoA();

// TODO invoquer la méthode sumAge pour que le test soit passant
int result = 0;

int result = daoA.sumAge();



assert result == 210;
}
Expand All @@ -59,7 +75,9 @@ public void test_daoB_sumAge() throws Exception {
DaoB daoB = new DaoB();

// TODO invoquer la méthode sumAge pour que le test soit passant
int result = 0;

int result = daoB.sumAge();


assert result == 5050;

Expand Down
18 changes: 14 additions & 4 deletions src/test/java/java17/ex02/Method_02_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@ public class Method_02_Test {
// tag::IDao[]
interface IDao {
List<Person> findAll();


// TODO créer une méthode String format()
// TODO la méthode retourne une chaîne de la forme [<nb_personnes> persons]
// TODO exemple de résultat : "[14 persons]", "[30 persons]"
public String format();
}
// end::IDao[]

// tag::DaoA[]
class DaoA implements IDao {

List<Person> people = Data.buildPersonList(20);
List<Person> people = Data.buildPersonList(30);

@Override
public List<Person> findAll() {
return people;
}


// TODO redéfinir la méthode String format()
// TODO la méthode retourne une chaîne de la forme DaoA[<nb_personnes> persons]
// TODO exemple de résultat : "DaoA[14 persons]", "DaoA[30 persons]"
// TODO l'implémentation réutilise la méthode format() de l'interface

@Override
public String format() {
return "DaoA[" + findAll().size()+ " persons]";
}

}
// end::DaoA[]
Expand All @@ -46,8 +54,10 @@ public void test_daoA_format() throws Exception {
DaoA daoA = new DaoA();

// TODO invoquer la méthode format() pour que le test soit passant
String result = null;

assert "DaoA[20 persons]".equals(result);
String result = daoA.format();
System.out.println(result);
assert "DaoA[30 persons]".equals(result);


}
}