Browse Source

Merge commit 'a81194074a49eabe723e7ad599411d45545a5b1d' into HEAD

feature-password-validator
jenkins 2 years ago
parent
commit
d67e9f419d
  1. 24
      README.md
  2. 27
      pom.xml
  3. 50
      src/main/java/Storage.java
  4. 4
      src/main/java/StorageInterface.java
  5. 62
      src/test/java/StorageTest.java

24
README.md

@ -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

27
pom.xml

@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.ciip-gruppe8-password-manager</groupId>
<artifactId>ciip-gruppe8-password-manager</artifactId>
<groupId>org.ciip-grp8-password-manager</groupId>
<artifactId>ciip-grp8-password-manager</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
@ -70,9 +70,26 @@
<version>5.7.0</version>
</dependency>
</dependencies>
<!-- <configuration>
<argLine>${argLine}</argLine>
</configuration> -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
</dependency>
</dependencies>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>PasswordManager</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

50
src/main/java/Storage.java

@ -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;
}
}

4
src/main/java/StorageInterface.java

@ -0,0 +1,4 @@
public interface StorageInterface {
public void export();
public void load();
}

62
src/test/java/StorageTest.java

@ -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));
}
}
Loading…
Cancel
Save