Skip to content

Commit

Permalink
* Improved conversation name creator
Browse files Browse the repository at this point in the history
* Improved names of encryption tests
* Added trello task link to todo in inputworker
  • Loading branch information
Zargess committed Feb 2, 2025
1 parent 7ca23cb commit 8f35cd0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 9 additions & 3 deletions fagiServer/src/main/java/com/fagi/model/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand All @@ -47,10 +49,14 @@ public synchronized Conversation createConversation(List<String> participants) {
.reduce(
"",
(a, b) -> {
if (!a.isEmpty()) {
return a + ", " + b;
var joiner = new StringJoiner(", ");
if (Objects.nonNull(a) && !a.isEmpty()) {
joiner.add(a);
}
return b;
if (Objects.nonNull(b) && !b.isEmpty()) {
joiner.add(b);
}
return joiner.toString();
}
);

Expand Down
1 change: 1 addition & 0 deletions fagiServer/src/main/java/com/fagi/worker/InputWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public InputWorker(
Data data) throws IOException {
this.data = data;
// TODO: This sysout does not make sense. Should be in the run method or where the thread is started.
// https://trello.com/c/SVazRIgj/58-inputworker-should-not-print-starting-an-input-thread-in-its-constructor
System.out.println("Starting an input thread");
objIn = new ObjectInputStream(socket.getInputStream());
this.out = out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void tearDown() {
}

@Test
public void constructorLoadKeyPairThrowsExceptionIOExceptionWhenLoadKeyThrowsThat() throws Exception {
public void whenLoadKeyPairThrowsIOException_ThenConstructorPrintsStacktrace() throws Exception {
try (var mockedKeyStorage = Mockito.mockStatic(KeyStorage.class)) {
mockedKeyStorage
.when(() -> KeyStorage.LoadKeyPair("RSA"))
Expand All @@ -49,7 +49,7 @@ public void constructorLoadKeyPairThrowsExceptionIOExceptionWhenLoadKeyThrowsTha
}

@Test
public void constructorLoadKeyPairThrowsNoSuchAlgorithmExceptionWhenLoadKeyThrowsThat() throws Exception {
public void whenLoadKeyPairThrowsNoSuchAlgorithmException_ThenConstructorPrintsStacktrace() throws Exception {
try (var mockedKeyStorage = Mockito.mockStatic(KeyStorage.class)) {
mockedKeyStorage
.when(() -> KeyStorage.LoadKeyPair("RSA"))
Expand All @@ -68,7 +68,7 @@ public void constructorLoadKeyPairThrowsNoSuchAlgorithmExceptionWhenLoadKeyThrow
}

@Test
public void constructorLoadKeyPairThrowsInvalidKeySpecExceptionWhenLoadKeyThrowsThat() throws Exception {
public void whenLoadKeyPairThrowsInvalidKeySpecException_ThenConstructorPrintsStacktrace() throws Exception {
try (var mockedKeyStorage = Mockito.mockStatic(KeyStorage.class)) {
mockedKeyStorage
.when(() -> KeyStorage.LoadKeyPair("RSA"))
Expand All @@ -87,7 +87,7 @@ public void constructorLoadKeyPairThrowsInvalidKeySpecExceptionWhenLoadKeyThrows
}

@Test
void constructorSaveKeyPairThrowsIOExceptionWhenSaveKeyPairThrowsThat() {
void whenSaveKeyPairThrowsIOException_ThenConstructorPrintsStacktrace() {
try (var mockedKeyStorage = Mockito.mockStatic(KeyStorage.class)) {
mockedKeyStorage
.when(() -> KeyStorage.SaveKeyPair(any()))
Expand All @@ -104,7 +104,7 @@ void constructorSaveKeyPairThrowsIOExceptionWhenSaveKeyPairThrowsThat() {
}

@Test
void constructorCreatesRSAKeyAndTriesToStoreIt() {
void givenNoKeyPairFileExists_WhenConstructingEncryption_ThenConstructorAttemptsToStoreRSAKeyPair() {
try (var mockedStatic = Mockito.mockStatic(KeyStorage.class)) {
var encryption = new Encryption(PUBLIC_KEY_PATH);
mockedStatic.verify(() -> KeyStorage.SaveKeyPair(eq((KeyPair) encryption
Expand All @@ -115,7 +115,7 @@ void constructorCreatesRSAKeyAndTriesToStoreIt() {
}

@Test
void constructorCanLoadRSAKeyFromDisk() throws IOException {
void givenKeyPairFileExists_WhenConstructingEncryption_ThenConstructorLoadsKeyPairFromDisk() throws IOException {
var rsa = new RSA(1024);
KeyStorage.SaveKeyPair((KeyPair) rsa
.getKey()
Expand Down

0 comments on commit 8f35cd0

Please sign in to comment.