Browse Source
Merge commit 'a81194074a49eabe723e7ad599411d45545a5b1d' into HEAD
feature-password-validator
Merge commit 'a81194074a49eabe723e7ad599411d45545a5b1d' into HEAD
feature-password-validator
jenkins
3 years ago
5 changed files with 161 additions and 6 deletions
-
24README.md
-
27pom.xml
-
50src/main/java/Storage.java
-
4src/main/java/StorageInterface.java
-
62src/test/java/StorageTest.java
@ -1,2 +1,24 @@ |
|||
# ciip-gruppe8-password-manager |
|||
# ciip-grp8-password-manager |
|||
|
|||
## Dependencies |
|||
- productive |
|||
- java 11 |
|||
- development |
|||
- java 11 |
|||
- maven |
|||
|
|||
## Build jar file artifact |
|||
- requires development dependencies |
|||
|
|||
`mvn package` |
|||
|
|||
## Run jar file artifact |
|||
- requires productive dependencies |
|||
- requires a built jar file to run |
|||
|
|||
`java -jar target/ciip-grp8-password-manager-1.0-SNAPSHOT.jar` |
|||
|
|||
## Contributors |
|||
- binsky - Timo Triebensky |
|||
- fdai6352 - Pascal Schubert |
|||
- fdai5728 - Claudia Metzler |
@ -0,0 +1,50 @@ |
|||
import java.io.*; |
|||
import java.util.Scanner; |
|||
|
|||
public class Storage implements StorageInterface { |
|||
@Override |
|||
public void export() { |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public void load() { |
|||
|
|||
} |
|||
|
|||
public boolean writeFile(String path, String content) { |
|||
if (!path.isEmpty() && !content.isEmpty()) { |
|||
try { |
|||
BufferedWriter writer = new BufferedWriter(new FileWriter(path, false)); |
|||
writer.append(content); |
|||
writer.close(); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public String readFile(String path) { |
|||
if (!path.isEmpty()) { |
|||
StringBuilder data = new StringBuilder(); |
|||
try { |
|||
File f = new File(path); |
|||
Scanner myReader = new Scanner(f); |
|||
while (myReader.hasNextLine()) { |
|||
data.append(myReader.nextLine()); |
|||
} |
|||
myReader.close(); |
|||
} catch (FileNotFoundException e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
|
|||
return data.toString(); |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,4 @@ |
|||
public interface StorageInterface { |
|||
public void export(); |
|||
public void load(); |
|||
} |
@ -0,0 +1,62 @@ |
|||
import org.junit.jupiter.api.AfterAll; |
|||
import org.junit.jupiter.api.BeforeAll; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.io.File; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
class StorageTest { |
|||
|
|||
static Storage storage; |
|||
static String testFilePath = "/tmp/test.txt"; |
|||
|
|||
@BeforeAll |
|||
static void init() { |
|||
storage = new Storage(); |
|||
|
|||
if (System.getProperty("os.name").toLowerCase().contains("win")) { |
|||
testFilePath = "C:\\test.txt"; |
|||
} |
|||
} |
|||
|
|||
@AfterAll |
|||
static void clear() { |
|||
File myObj = new File(testFilePath); |
|||
myObj.delete(); |
|||
} |
|||
|
|||
@Test |
|||
void constructor() { |
|||
assertInstanceOf(Storage.class, storage); |
|||
} |
|||
|
|||
@Test |
|||
void export() { |
|||
} |
|||
|
|||
@Test |
|||
void load() { |
|||
} |
|||
|
|||
@Test |
|||
void writeFile() { |
|||
String content = "test"; |
|||
assertTrue(storage.writeFile(testFilePath, content)); |
|||
|
|||
File f = new File(testFilePath); |
|||
assertTrue(f.isFile()); |
|||
} |
|||
|
|||
@Test |
|||
void readFile() { |
|||
String content = "test"; |
|||
|
|||
File f = new File(testFilePath); |
|||
if (!f.isFile()) { |
|||
assertTrue(storage.writeFile(testFilePath, content)); |
|||
} |
|||
|
|||
assertEquals(content, storage.readFile(testFilePath)); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue