Skip to content

Commit f94749a

Browse files
committed
Use @beforeeach instead of @BeforeAll.
1 parent 26a1397 commit f94749a

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

exercises/concept/tim-from-marketing-2/.classpath

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
<attribute name="test" value="true"/>
2020
</attributes>
2121
</classpathentry>
22+
<classpathentry kind="src" output="bin/test" path="build/gen/test/java">
23+
<attributes>
24+
<attribute name="gradle_scope" value="test"/>
25+
<attribute name="gradle_used_by_scope" value="test"/>
26+
<attribute name="test" value="true"/>
27+
</attributes>
28+
</classpathentry>
2229
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
2330
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
2431
<classpathentry kind="output" path="bin"/>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Hints
22

3-
## 1.- Print the name of all the employees
43

4+
## 1.- Print the name of all the employees
55
WIP
66

77

88
## 2.- Print the name and department of a given employee
9-
109
WIP
11-

exercises/concept/tim-from-marketing-2/.docs/instructions.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Instructions
22

33
In this exercise you will be writing code to print all the names of the factory employees.
4-
54
Employees have an ID, a name and a department name, like in the [tim-from-marketing](/exercises/concept/tim-from-marketing) exercise.
65
Assume that the ID of the first employee is 0, the ID of the second employee is 1, and so on. The three fields of an employee may be empty, that's why they are declared as Optional<T> types.
76
The class constructor receives a parameter of type List<Optional<Employee>>, which is populated in the tests.
87

98
## 1.- Print the names of all the employees
10-
119
Implement the `printAllEmployeesNames()` method to print the names of all the employees, together with their id. If the employee does not exist, print "[id] - No employee found".
1210

1311
```java

exercises/concept/tim-from-marketing-2/.docs/introduction.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
## Introduction
66

77
The **Optional<T>** type was introduced in Java 8 as a way to indicate that a method will return an object of type T or an empty value. It is present in type signatures of many core Java methods.
8-
98
Before Java 8, developers had to implement null checks:
109

1110
```java
@@ -65,7 +64,6 @@ public Optional<Integer> getEmployeeAge(String name) {
6564
```
6665

6766
It is important to understand that the Optional API does not eliminate the null checking, but it defers it until the end of a series of methods, as long as all those methods return an optional object.
68-
6967
The fields of the Employee class have an Optional type. Notice that this is not recommended, as explained by one well-known Java language architect in [this SO answer](https://stackoverflow.com/questions/26327957/should-java-8-getters-return-optional-type)
7068

7169
## Flatmap operation
@@ -89,4 +87,4 @@ List<Optional<String>> listOfOptionals = Arrays.asList(
8987
System.out.println(result); // Output: [Java, Kotlin]
9088
}
9189
}
92-
```
90+
```

exercises/concept/tim-from-marketing-2/.meta/design.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
The goal of this exercise is to teach the student how to use the Optional API.
66
We will use the most common methods: `ifPresent`, `orElse`, `ifPresentOrElse`, `orElseThrow`.
77
The `isPresent` and `get` methods are not presented, since they do not provide any value over an ordinary null check.
8-
98
Some methods of the Stream API are needed. This is a bit problematic, since they have not been explained in the current Java track.
109

1110
## Learning objectives
@@ -30,13 +29,13 @@ This Concepts Exercise's Concepts are:
3029
This Concept Exercise's prerequisites Concepts are:
3130

3231
- `custom classes`.
32+
- `lists`.
3333
- `generic-types`.
3434
- `streams`.
3535

3636
## Analyzer
3737

3838
This exercise could benefit from the following rules in the [analyzer]:
39-
4039
- `actionable`: If the solution uses `null` in any method, encourage the student to use `Optional<T>` instead.
4140
- `actionable`: If the solution uses the `get` or `isPresent` methods of the Optional<T> API, encourage the student to use `orElse`, `orElseThrow` or `ifPresentOrElse` instead.
4241
- `informative`: TODO.

exercises/concept/tim-from-marketing-2/src/test/java/EmployeeServiceTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import org.junit.jupiter.api.DisplayName;
22
import org.junit.jupiter.api.Tag;
3-
import org.junit.jupiter.api.BeforeAll;
3+
import org.junit.jupiter.api.BeforeEach;
44
import org.junit.jupiter.api.Test;
55
import org.junit.jupiter.api.TestInstance;
66
import org.junit.jupiter.api.TestInstance.Lifecycle;
@@ -10,8 +10,7 @@
1010
import java.util.ArrayList;
1111
import java.util.Optional;
1212

13-
// Annotation in order to use @BeforeAll in a non-static method
14-
@TestInstance(Lifecycle.PER_CLASS)
13+
// @TestInstance(Lifecycle.PER_CLASS)
1514
public class EmployeeServiceTest {
1615

1716
private EmployeeService employeeService;
@@ -33,7 +32,7 @@ void initList() {
3332
listOfEmployees.add(Optional.of(new Employee(2, "John", "Engineering")));
3433
}
3534

36-
@BeforeAll
35+
@BeforeEach
3736
void setup() {
3837
initList();
3938
employeeService = new EmployeeService(listOfEmployees);

0 commit comments

Comments
 (0)