Skip to content

Commit

Permalink
Replace System.exit with Assert.fail
Browse files Browse the repository at this point in the history
  • Loading branch information
INCENDE committed Nov 4, 2016
1 parent 1dd49d5 commit 38fda52
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/test/java/seedu/agendum/MainAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.util.Optional;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -73,7 +74,7 @@ public void initPrefs_invalidUserPrefsFileFormat_returnsDefaultUserPrefs() {

UserPrefs userPrefs = mainApp.initPrefs(config);
assertEquals(userPrefs, defaultUserPrefs);

mainApp.storage = null;
}

Expand All @@ -86,17 +87,17 @@ public void initPrefs_validUserPrefsFileFormatButUnwriteable_returnsDefaultUserP

UserPrefs userPrefs = mainApp.initPrefs(config);
assertEquals(userPrefs, defaultUserPrefs);

mainApp.storage = null;
}

@Test
public void initPrefs_exceptionThrowingStorage_returnsDefaultUserPrefsLogsWarning() {
mainApp.storage = new ExceptionThrowingStorageManagerStub();

UserPrefs userPrefs = mainApp.initPrefs(defaultConfig);
assertEquals(userPrefs, defaultUserPrefs);

mainApp.storage = null;
}

Expand All @@ -111,8 +112,7 @@ private void createEmptyFile(String filePath) {
try {
file.createNewFile();
} catch (IOException e) {
System.out.println("Error creating empty file at: " + filePath);
System.exit(1);
Assert.fail("Error creating empty file at: " + filePath);
}
}

Expand All @@ -127,13 +127,11 @@ private void createReadOnlyConfigFile() {
try {
ConfigUtil.saveConfig(defaultConfig, pathToReadOnlyConfig);
} catch (IOException e) {
System.out.println("Error creating read only config file");
System.exit(1);
Assert.fail("Error creating read only config file");
}

if (!file.setReadOnly()) {
System.out.println("Unable to set read only config to read only");
System.exit(1);
Assert.fail("Unable to set read only config to read only");
}
}

Expand All @@ -149,29 +147,25 @@ private void createReadOnlyUserPrefsFile() {
JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(pathToReadOnlyUserPrefs);
userPrefsStorage.saveUserPrefs(defaultUserPrefs, pathToReadOnlyUserPrefs);
} catch (IOException e) {
System.out.println("Error creating read only user prefs file");
System.exit(1);
Assert.fail("Error creating read only user prefs file");
}

if (!file.setReadOnly()) {
System.out.println("Unable to set read only user prefs to read only");
System.exit(1);
Assert.fail("Unable to set read only user prefs to read only");
}
}

class CustomUserPrefsStorageManagerStub extends StorageManager {

public CustomUserPrefsStorageManagerStub(String userPrefsPath) {
super("", "", userPrefsPath, null);
}
}

class ExceptionThrowingStorageManagerStub extends StorageManager {

class ExceptionThrowingStorageManagerStub extends StorageManager {
public ExceptionThrowingStorageManagerStub() {
super("","","",null);
super("", "", "", null);
}

@Override
public Optional<UserPrefs> readUserPrefs() throws IOException {
throw new IOException("ExceptionThrowingStorageManagerStub: IOException");
Expand Down

0 comments on commit 38fda52

Please sign in to comment.