Commit 2405f819 authored by Levy, Matyáš's avatar Levy, Matyáš
Browse files

Commit

parent 7b2c66ff
# Enterprice architect model
*.EAP
# Exported diagrams
*.png
# Intellij
.idea/
*.iml
*.iws
# Maven
log/
target/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="cv2_assignment" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="cv2_assignment" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/cv2_assignment/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/cv2_assignment/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: junit:junit:4.11">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.apiguardian:apiguardian-api:1.1.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.junit.jupiter:junit-jupiter-api:5.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.5.2/junit-jupiter-api-5.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.5.2/junit-jupiter-api-5.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.5.2/junit-jupiter-api-5.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.junit.jupiter:junit-jupiter-engine:5.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.5.2/junit-jupiter-engine-5.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.5.2/junit-jupiter-engine-5.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.5.2/junit-jupiter-engine-5.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.junit.platform:junit-platform-commons:1.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.5.2/junit-platform-commons-1.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.5.2/junit-platform-commons-1.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.5.2/junit-platform-commons-1.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.junit.platform:junit-platform-engine:1.5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.5.2/junit-platform-engine-1.5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.5.2/junit-platform-engine-1.5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.5.2/junit-platform-engine-1.5.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Maven: org.opentest4j:opentest4j:1.2.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/solution2/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="false" project-jdk-name="13" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/cv2_assignment/cv2_assignment.iml" filepath="$PROJECT_DIR$/cv2_assignment/cv2_assignment.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -19,6 +19,11 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
</dependency>
</dependencies>
<build>
......
......@@ -8,5 +8,38 @@ import java.util.List;
* GpsTrackingSystem class represents the newly introduced tool for gaining control over company car park.
*/
public class GpsTrackingSystem {
// IMPLEMENT ME, PLEASE!
private List<Tracker> trackers;
private static int counter;
public GpsTrackingSystem(){
this.trackers = new ArrayList<>();
counter = 0;
}
public GpsTrackingSystem(List<Tracker> trackers){
this.trackers = trackers;
counter = 0;
}
public void attachTrackingDevices(List<Vehicle> vehicles){
for (Vehicle car: vehicles){
trackers.add(new Tracker(car,counter,car.getMileage()));
counter++;
}
}
public void generateMonthlyReport(){
System.out.println("—– GPS Tracking system: Monthly report —–\n" +
"\n" +
"Currently active devices:\n");
int kmCounter = 0;
for(Tracker tracker:trackers){
kmCounter+=tracker.getTrackerMilage();
System.out.println(tracker.toString() + "\n");
tracker.resetTrackerMilage();
}
System.out.println("This month traveled distance: "+ kmCounter +" Km.");
}
}
......@@ -11,7 +11,7 @@ public class Main {
public static void main(String[] args) {
/* UNCOMMENT ME, WHEN READY
// 1. Initialize company car park
List<Vehicle> carPark = new ArrayList<>();
GpsTrackingSystem companySpy = new GpsTrackingSystem();
......@@ -39,7 +39,7 @@ public class Main {
// End of another month, generate new report
companySpy.generateMonthlyReport();
*/
}
}
......@@ -4,5 +4,36 @@ package cz.cvut.fel.omo.trackingSystem;
* Tracker is device installed into company vehicles, connected to car computer in order to obtain necessary data.
*/
public class Tracker {
private Vehicle currentVehicle;
private final int trackerId;
private int innerMemory;
// IMPLEMENT ME, PLEASE!
public Tracker(Vehicle currentVehicle, int trackerId, int innerMemory) {
this.currentVehicle = currentVehicle;
this.trackerId = trackerId;
this.innerMemory = innerMemory;
}
public Vehicle getCurrentVehicle() {
return currentVehicle;
}
public void attachVehicle(Vehicle vehicle){
this.currentVehicle = vehicle;
resetTrackerMilage();
}
public int getTrackerMilage(){
//This difference in value should determine, just how many kilometers have gone by since we attached the tracker
return currentVehicle.getMileage() - innerMemory;
}
public void resetTrackerMilage(){
this.innerMemory = currentVehicle.getMileage();
}
public String toString(){
return "Tracker_" + trackerId + ", attached to " + currentVehicle.toString();
}
}
package cz.cvut.fel.omo.trackingSystem;
import java.util.stream.Stream;
/**
* Class Vehicle represents a single car in company car park.
*/
public class Vehicle {
// IMPLEMENT ME, PLEASE!
private int mileage;
private final String VINCode, manufacturer;
public Vehicle(String VINCode, String manufacturer, int mileage){
this.VINCode = VINCode;
this.manufacturer = manufacturer;
this.mileage = mileage;
}
public void drive(int km){
mileage+=km;
}
public int getMileage() {
return mileage;
}
public String getVINCode() {
return VINCode;
}
public String getManufacturer() {
return manufacturer;
}
public String toString(){
return manufacturer + ", " + VINCode;
}
}
......@@ -2,8 +2,11 @@ package cz.cvut.fel.omo.trackingSystem;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import static org.junit.Assert.*;
......@@ -11,6 +14,59 @@ import static org.junit.Assert.*;
* Created by kuki on 22/09/2017.
*/
public class GPSTrackingSystemTest {
List<Vehicle> vehicles = new ArrayList<>();
GpsTrackingSystem test = new GpsTrackingSystem();
@Test
public void attachTrackingDevices_AttachesTrackingDevicesToCarsInList_AssertsTrue() {
test = new GpsTrackingSystem();
vehicles.add(Params.newCar());
String expect = "—– GPS Tracking system: Monthly report —–\n" +
"\n" +
"Currently active devices:\n" +
"\n" +
"This month traveled distance: 0 Km.\n";
String result = rederectconsoleoutputtostring();
System.out.println(expect);
System.out.println(result);
assertTrue(expect.equals(result.toString()));
test.attachTrackingDevices(vehicles);
expect = "—– GPS Tracking system: Monthly report —–\n" +
"\n" +
"Currently active devices:\n" +
"\n" +
"Tracker_0, attached to SIMP, 69\n"
+
"\n"
+
"This month traveled distance: 0 Km.\n";
}
@Test
public void generateMonthlyReport_PrintsOutAReport_AssertsTrue() {
List<Tracker> trackers = new ArrayList<>();
Tracker tracker = Params.newTracker();
trackers.add(tracker);
test = new GpsTrackingSystem(trackers);
vehicles.add(Params.newCar());
String expect = "—– GPS Tracking system: Monthly report —–\n" +
"\n" +
"Currently active devices:\n" +
"\n" +
"Tracker_666, attached to SIMP, 69\n" +
"\n" +
"This month traveled distance: 0 Km.\n";
assertEquals(expect,rederectconsoleoutputtostring());
}
// IMPLEMENT ME, PLEASE!
public String rederectconsoleoutputtostring(){
PrintStream old = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
test.generateMonthlyReport();
System.out.flush();
System.setOut(old);
return baos.toString();
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment