|
@ -1,14 +1,19 @@ |
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
import org.mockito.Mockito; |
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
import java.io.ByteArrayInputStream; |
|
|
import java.io.ByteArrayOutputStream; |
|
|
import java.io.ByteArrayOutputStream; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.util.NoSuchElementException; |
|
|
import java.util.NoSuchElementException; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
|
public class VaultTest { |
|
|
public class VaultTest { |
|
|
|
|
|
|
|
|
|
|
|
//Vault vlt = new Vault(); |
|
|
|
|
|
|
|
|
static Vault vlt; |
|
|
static Vault vlt; |
|
|
|
|
|
|
|
|
@BeforeAll |
|
|
@BeforeAll |
|
@ -16,14 +21,11 @@ public class VaultTest { |
|
|
vlt = new Vault(); |
|
|
vlt = new Vault(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* @BeforeEach |
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
void reset() { |
|
|
void reset() { |
|
|
pm.outputStream = System.out; |
|
|
|
|
|
pm.inputStream = System.in; |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void configure() {vlt.configure();} |
|
|
|
|
|
|
|
|
vlt.outputS = System.out; |
|
|
|
|
|
vlt.inputS = System.in; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
void addCredential() {vlt.addCredential();} |
|
|
void addCredential() {vlt.addCredential();} |
|
@ -37,4 +39,90 @@ public class VaultTest { |
|
|
@Test |
|
|
@Test |
|
|
void loadFromJson() {vlt.loadFromJson();} |
|
|
void loadFromJson() {vlt.loadFromJson();} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void openConfigureMenu() { |
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
vlt.configure(); |
|
|
|
|
|
assertTrue(outputStream.toString().startsWith("Configure:")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void exitConfigurationMenu(){ |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("e".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
vlt.configure(); |
|
|
|
|
|
assertFalse(vlt.config); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void doNotExitConfigAfterWrongInput() { |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("__\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
vlt.configure(); |
|
|
|
|
|
assertTrue(vlt.config); |
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
|
vlt.inputS = getEmptyStringInputStream(); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
|
|
|
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> vlt.configure()); |
|
|
|
|
|
assertTrue(outputStream.toString().startsWith("Configure:")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void openSetPWLength() { |
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("12".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
vlt.setPWLength(); |
|
|
|
|
|
assertTrue(outputStream.toString().startsWith("Set")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void setPWLength() { |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("7\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
vlt.setPWLength(); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(7, vlt.PWLength); |
|
|
|
|
|
assertTrue(outputStream.toString().contains("now:")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void setPWLengthWrongInput() { |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("T\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
vlt.setPWLength(); |
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
|
vlt.inputS = getEmptyStringInputStream(); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
|
|
|
|
|
|
assertThrowsExactly(NoSuchElementException.class, () -> vlt.setPWLength()); |
|
|
|
|
|
assertTrue(outputStream.toString().startsWith("Set")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
void setCapital() { |
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("yes\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
vlt.setCapital(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(outputStream.toString().startsWith("Should")); |
|
|
|
|
|
assertTrue(vlt.haveCapitals = true); |
|
|
|
|
|
assertTrue(outputStream.toString().contains("contain")); |
|
|
|
|
|
|
|
|
|
|
|
vlt.inputS = new ByteArrayInputStream("no\n".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
vlt.outputS = outputStream; |
|
|
|
|
|
vlt.setCapital(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(outputStream.toString().startsWith("Should")); |
|
|
|
|
|
assertFalse(vlt.haveCapitals = false); |
|
|
|
|
|
assertTrue(outputStream.toString().contains("don´t")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ByteArrayInputStream getEmptyStringInputStream() { |
|
|
|
|
|
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |