|
@ -1,6 +1,7 @@ |
|
|
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; |
|
@ -68,10 +69,58 @@ public class VaultTest { |
|
|
assertTrue(outputStream.toString().startsWith("Configure:")); |
|
|
assertTrue(outputStream.toString().startsWith("Configure:")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// @Test |
|
|
|
|
|
// void |
|
|
|
|
|
|
|
|
@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() { |
|
|
private ByteArrayInputStream getEmptyStringInputStream() { |
|
|
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); |
|
|
return new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); |
|
|