Skip to content

Commit ae827f3

Browse files
authored
Refactor hashcode() samples (eugenp#2377)
1 parent 67448de commit ae827f3

7 files changed

Lines changed: 15 additions & 203 deletions

File tree

‎core-java/hashcode/pom.xml‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎core-java/hashcode/src/main/java/com/baeldung/application/Application.java‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎core-java/hashcode/src/main/java/com/baeldung/entities/User.java‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎core-java/hashcode/src/test/java/com/baeldung/application/ApplicationTest.java‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎core-java/hashcode/src/test/java/com/baeldung/entities/UserTest.java‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎core-java/src/main/java/com/baeldung/hashcode/application/Application.java‎

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package com.baeldung.hashcode.application;
22

3+
import com.baeldung.hashcode.entities.User;
34
import org.junit.After;
45
import org.junit.Before;
56
import org.junit.Test;
67
import java.io.ByteArrayOutputStream;
78
import java.io.PrintStream;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
812
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertTrue;
914

1015
public class ApplicationTest {
1116

12-
private ByteArrayOutputStream outContent;
13-
14-
@Before
15-
public void setUpPrintStreamInstance() throws Exception {
16-
this.outContent = new ByteArrayOutputStream();
17-
System.setOut(new PrintStream(outContent));
18-
}
19-
20-
@After
21-
public void tearDownByteArrayOutputStream() throws Exception {
22-
outContent = null;
23-
}
24-
2517
@Test
2618
public void main_NoInputState_TextPrintedToConsole() throws Exception {
27-
Application.main(new String[] {});
28-
assertEquals("User found in the collection", outContent.toString());
19+
Map<User, User> users = new HashMap<>();
20+
User user1 = new User(1L, "John", "john@domain.com");
21+
User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
22+
User user3 = new User(3L, "Mary", "mary@domain.com");
23+
24+
users.put(user1, user1);
25+
users.put(user2, user2);
26+
users.put(user3, user3);
27+
28+
assertTrue(users.containsKey(user1));
2929
}
3030
}

0 commit comments

Comments
 (0)