Commit f28aae8f authored by Karel Frajták's avatar Karel Frajták
Browse files

Merge branch 'master' into 'master'

Added tests for package 1 - archive

See merge request !8
parents d5dbf2a5 7394913a
Pipeline #3960 passed with stages
in 49 seconds
/.idea/
/build/
/dist/
/target/**/*.*
\ No newline at end of file
### Linux template
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Windows template
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
### Eclipse template
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
### Example user template template
### Example user template
# IntelliJ project files
.idea
*.iml
out
gen### NetBeans template
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/tasks.xml
.idea/**/dictionaries
.idea/**/shelf
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
cmake-build-release/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
image: maven:3.3.9-jdk-8
stages:
image: maven:3-jdk-8
variables:
MAVEN_OPTS: "-Djava.awt.headless=true -Dmaven.repo.local=./.m2/repository"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -T 1C"
cache:
paths:
- ./.m2/repository
# keep cache across branch
key: "$CI_BUILD_REF_NAME"
stages:
- build
- test
buildProject:
stage: build
script:
- "mvn clean compile package install $MAVEN_CLI_OPTS -DskipTests"
artifacts:
paths:
- target/site/jacoco/
unitTests:
stage: test
dependencies:
- buildProject
script:
- mvn test
- awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' target/site/jacoco/jacoco.csv
- "mvn validate test verify $MAVEN_CLI_OPTS"
- awk -F"," '{ instructions += $4 + $5; covered += $5 } END { print covered, "/", instructions, " instructions covered"; print 100*covered/instructions, "% covered" }' target/site/jacoco/jacoco.csv
artifacts:
paths:
- target/site/jacoco/
\ No newline at end of file
- target/site/jacoco/
[![pipeline status](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/pipeline.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master)
[![coverage report](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/coverage.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master)
\ No newline at end of file
[![coverage report](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/coverage.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master)
![Class diagram](classDiagram.png)
\ No newline at end of file
......@@ -9,7 +9,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.10.0</version>
<version>3.11.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
......@@ -28,7 +28,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<version>0.8.2</version>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
......
package cz.cvut.eshop;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import cz.cvut.eshop.archive.ItemPurchaseArchiveEntry;
import cz.cvut.eshop.archive.PurchasesArchive;
import cz.cvut.eshop.shop.Item;
import cz.cvut.eshop.shop.Order;
import cz.cvut.eshop.shop.ShoppingCart;
import cz.cvut.eshop.shop.StandardItem;
public class TestData {
private TestData() throws IllegalAccessException {
throw new IllegalAccessException("Single instance protection");
}
public static StandardItem createStandardItem() {
return new StandardItem(1, "testItem", 3.5f, "testCategory", 10);
}
public static PurchasesArchive createPurchaseArchive(Integer id, ItemPurchaseArchiveEntry orderArchive) {
HashMap<Integer, ItemPurchaseArchiveEntry> itemArchive = new HashMap<>(Collections.singletonMap(id, orderArchive));
return new PurchasesArchive(itemArchive, new ArrayList<>(1));
}
public static Order createOrder(Item... items) {
ShoppingCart shoppingCart;
if (items == null) {
shoppingCart = new ShoppingCart();
} else {
ArrayList<Item> cartItems = new ArrayList<>(Arrays.asList(items));
shoppingCart = new ShoppingCart(cartItems);
}
return new Order(shoppingCart);
}
}
\ No newline at end of file
package cz.cvut.eshop.archive;
import org.junit.Before;
import cz.cvut.eshop.TestData;
import cz.cvut.eshop.shop.Item;
abstract class AbstractArchiveTest {
Item item;
ItemPurchaseArchiveEntry itemArchive;
@Before
public void setUp() {
item = TestData.createStandardItem();
itemArchive = new ItemPurchaseArchiveEntry(item);
}
}
package cz.cvut.eshop.archive;
import org.junit.Assert;
import org.junit.Test;
public class ItemPurchaseArchiveEntryTest extends AbstractArchiveTest {
@Test
public void testGetCountHowManyTimesHasBeenSold() {
Assert.assertEquals("Incorrect sold count in empty archive", 1, itemArchive.getCountHowManyTimesHasBeenSold());
}
@Test
public void testGetRefItem() {
Assert.assertEquals("Constructor and getter items are different", item, itemArchive.getRefItem());
}
@Test
public void testIncreaseCountHowManyTimesHasBeenSoldZero() {
compareIncrement(0);
}
@Test
public void testIncreaseCountHowManyTimesHasBeenSoldPositive() {
compareIncrement(10);
}
@Test
public void testIncreaseCountHowManyTimesHasBeenSoldNegative() {
compareIncrement(-10);
}
private void compareIncrement(int difference) {
int soldCount = itemArchive.getCountHowManyTimesHasBeenSold();
itemArchive.increaseCountHowManyTimesHasBeenSold(difference);
Assert.assertEquals("Incorrect sold count for " + difference + " increment", soldCount + difference, itemArchive.getCountHowManyTimesHasBeenSold());
}
}
\ No newline at end of file
package cz.cvut.eshop.archive;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import cz.cvut.eshop.TestData;
import cz.cvut.eshop.shop.Order;
public class PurchasesArchiveTest extends AbstractArchiveTest {
private PurchasesArchive emptyArchive;
private PurchasesArchive notEmptyArchive;
private Order order;
@Override
@Before
public void setUp() {
super.setUp();
emptyArchive = new PurchasesArchive();
notEmptyArchive = TestData.createPurchaseArchive(item.getID(), itemArchive);
order = TestData.createOrder(item);
}
@Test
public void testPrintItemPurchaseStatistics() throws IOException {
PrintStream originalStdout = System.out;
try (ByteArrayOutputStream buffer = new ByteArrayOutputStream();
PrintStream newStdout = new PrintStream(new BufferedOutputStream(buffer), true)
) {
System.setOut(newStdout);
emptyArchive.printItemPurchaseStatistics();
Assert.assertTrue("Empty archive purchase statistic", buffer.size() > 0);
} finally {
System.setOut(originalStdout);
}
}
@Test(expected = NullPointerException.class)
public void testGetHowManyTimesHasBeenItemSoldNull() {
emptyArchive.getHowManyTimesHasBeenItemSold(null);
}
@Test
public void testGetHowManyTimesHasBeenItemSoldEmpty() {
int soldCount = emptyArchive.getHowManyTimesHasBeenItemSold(item);
Assert.assertEquals("Not present item sold multiple times", 0, soldCount);
}
@Test
public void testGetHowManyTimesHasBeenItemSold() {
int soldCount = notEmptyArchive.getHowManyTimesHasBeenItemSold(item);
Assert.assertEquals("Item sold incorrect number of times", itemArchive.getCountHowManyTimesHasBeenSold(), soldCount);
}
@Test(expected = NullPointerException.class)
public void testPutOrderToPurchasesArchiveNull() {
emptyArchive.putOrderToPurchasesArchive(null);
}
@Test
public void testPutOrderToPurchasesArchiveEmpty() {
emptyArchive.putOrderToPurchasesArchive(order);
int soldCount = emptyArchive.getHowManyTimesHasBeenItemSold(item);
Assert.assertEquals("Item sold multiple times in empty archive", 1, soldCount);
}
@Test
public void testPutOrderToPurchasesArchive() {
int previousSoldCount = notEmptyArchive.getHowManyTimesHasBeenItemSold(item);
notEmptyArchive.putOrderToPurchasesArchive(order);
int newSoldCount = notEmptyArchive.getHowManyTimesHasBeenItemSold(item);
Assert.assertEquals("Item sold incorrect number of times", previousSoldCount + 1, newSoldCount);
}
}
\ 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