pax_global_header 0000666 0000000 0000000 00000000064 14052744030 0014511 g ustar 00root root 0000000 0000000 52 comment=cc28f18b601c3e010468b92bbb3497294a0faed7
2021-hw03-elements-master/ 0000775 0000000 0000000 00000000000 14052744030 0015323 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/.gitignore 0000664 0000000 0000000 00000002024 14052744030 0017311 0 ustar 00root root 0000000 0000000 # Created by .ignore support plugin (hsz.mobi)
### Java template
*.class
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml
## Directory-based project format:
.idea/
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
### 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
### NetBeans template
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/
# Vim
*.un~
# OS X .DS_Store
.DS_Store
2021-hw03-elements-master/.gitlab-ci.yml 0000664 0000000 0000000 00000000162 14052744030 0017756 0 ustar 00root root 0000000 0000000 image: maven:3-jdk-11
build:
script:
- mvn clean install -B -Dcheckstyle.fail=true
tags:
- shared-fi
2021-hw03-elements-master/README.md 0000664 0000000 0000000 00000012264 14052744030 0016607 0 ustar 00root root 0000000 0000000 Homework assignment no. 3 (BONUS), Elements
====================================
This is a bonus part of the assignment.
The base assignment of third homework can be found [in this repository](https://gitlab.fi.muni.cz/pb162/2021-hw03-csv)
**Publication date:** May 23, 2021
**Submission deadline:** June 9, 2021
General information
-------------------
In this assignment you will implement a very simple command line application which allows its user to query
[the periodic table](https://en.wikipedia.org/wiki/Periodic_table).
The implementation will use ``src/main/resources/elements.csv`` as its datasource.
The application should support the following command line options.
| CLI option (long) | CLI option (short) | Arguments | Description |
| ------ | ------ | ------ | ------ |
| --help | | | Print application usage |
| --name | | String | Finds element by name |
| --symbol | -s | String | Finds element by symbol |
| --number | -n | int | Finds element by atomic number |
| --year | -y | int | Finds elements by year |
For more details about the CLI see the section "Running the application" in this README as well as JUnit tests.
**Hint:** *You will need a CSV parser, and you have to write it yourself.*
**Hint:** *Add dependency on your CSV parser from hw03 to pom.xml*
### Evaluation
Beside functional correctness this assignment is focused on object-oriented design.
This means that the way you structure your program will be the main part of its evaluation.
On the other hand the given set of tests is not trying to provide an elaborate test coverage and incorrect behaviour in corner-cases should not have a large impact on the evaluation.
Note that all this is at your seminar teacher's discretion.
The maximum number of points for this assignment is **8**.
- **2 points** for passing the tests (attached tests do not guarantee a 100% correctness).
- **6 points** for correct and clean implementation (evaluated by your class teacher).
### Project structure
The structure of project provided as a base for your implementation should meet the following criteria.
1. Package ```cz.muni.fi.pb162.hw03``` contains classes and interfaces provided as part of the assignment.
- **Do not modify or add any classes or subpackages into this package.**
2. Package ```cz.muni.fi.pb162.hw03.app.impl``` should contain your implementation.
- **Anything outside this package will be ignored during evaluation.**
### Names in this document
Unless fully classified name is provided, all class names are relative to the package ```cz.muni.fi.pb162.hw03``` or ```cz.muni.fi.pb162.hw03.app.impl``` for classes implemented as part of your solution.
### Compiling the project
The project can be compiled and packaged in the same way you already know.
**Note:** *Before compiling this project you need to [install your CSV](https://gitlab.fi.muni.cz/pb162/2021-hw03-csv#compiling-the-project) parser project into your local maven repository.
```bash
$ mvn clean install
```
The only difference is, that unlike with seminar project, this time checks for missing documentation and style violation will produce an error.
You can temporarily disable this behavior when running this command.
```bash
$ mvn clean install -Dcheckstyle.fail=false
```
### Running the application
Build command mentioned above will produce a runnable jar file ``target/application.jar``.
The following are example usages of developed application.
```bash
# Search by atomic number
$ java -jar elements.jar -n 1
-------------------------------------------------------------------------------------------------------
| #| Symbol| Name| Standard State| Group Block| Year|
=======================================================================================================
| 1| H| Hydrogen| gas| nonmetal| 1766|
-------------------------------------------------------------------------------------------------------
# Search by year of discovery
$ java -jar elements.jar --year 2003
-------------------------------------------------------------------------------------------------------
| #| Symbol| Name| Standard State| Group Block| Year|
=======================================================================================================
| 113| Nh| Nihonium| | post-transition metal| 2003|
| 115| Mc| Moscovium| | post-transition metal| 2003|
-------------------------------------------------------------------------------------------------------
```
**Note:** *These are just example, refer to tests in order to identify all possible usages.*
### Submitting the assignment
The procedure to submit your solution may differ based on your seminar group. However generally it should be OK to submit ```target/homework02-2021-1.0-SNAPSHOT-sources.jar``` to the homework vault.
## Implementation
Generally speaking there are no mandatory requirements on the structure of your code as long as the command line interface of ```Appplication``` class works correctly.
2021-hw03-elements-master/pb162_codestyle.xml 0000664 0000000 0000000 00000007363 14052744030 0020763 0 ustar 00root root 0000000 0000000
2021-hw03-elements-master/pom.xml 0000775 0000000 0000000 00000014407 14052744030 0016651 0 ustar 00root root 0000000 0000000
4.0.0
cz.muni.fi.pb162
homework03-2021-elements
1.0-SNAPSHOT
11
11
UTF-8
true
2.17
2.4
5.6.2
3.9.0
3.19.0
1.78
1.2.0
com.beust
jcommander
${version.jcommander}
org.junit.jupiter
junit-jupiter
${version.junit}
test
org.assertj
assertj-core
${version.assertj}
test
org.mockito
mockito-core
${version.mockito}
test
org.mockito
mockito-inline
${version.mockito}
test
org.mockito
mockito-junit-jupiter
${version.mockito}
test
com.github.stefanbirkner
system-lambda
${version.system-labda}
test
org.apache.maven.plugins
maven-source-plugin
${version.plugin.source}
attach-sources
jar
org.apache.maven.plugins
maven-shade-plugin
3.2.2
package
shade
elements
true
cz.muni.fi.pb162.hw03.app.impl.Application
com.beust:jcommander
META-INF/*.MF
org.apache.maven.plugins
maven-surefire-plugin
2.22.2
false
org.apache.maven.plugins
maven-checkstyle-plugin
${version.plugin.checkstyle}
validate
validate
pb162_codestyle.xml
UTF-8
true
${checkstyle.fail}
warning
false
*/**/Demo
check
2021-hw03-elements-master/src/ 0000775 0000000 0000000 00000000000 14052744030 0016112 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/ 0000775 0000000 0000000 00000000000 14052744030 0017036 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/ 0000775 0000000 0000000 00000000000 14052744030 0017757 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/ 0000775 0000000 0000000 00000000000 14052744030 0020373 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/ 0000775 0000000 0000000 00000000000 14052744030 0021343 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/ 0000775 0000000 0000000 00000000000 14052744030 0021741 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/ 0000775 0000000 0000000 00000000000 14052744030 0022573 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/ 0000775 0000000 0000000 00000000000 14052744030 0023354 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/ 0000775 0000000 0000000 00000000000 14052744030 0024134 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/ElementLibrary.java 0000664 0000000 0000000 00000002025 14052744030 0027714 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app;
import cz.muni.fi.pb162.hw03.app.impl.Element;
import java.util.List;
import java.util.Optional;
/**
* Library of chemical elements
*/
public interface ElementLibrary {
/**
* Finds element by atomic number
*
* @param num atomic number
* @return element with given atomic number or empty {@link Optional}
*/
Optional findByAtomicNumber(int num);
/**
* Finds element by symbol
*
* @param symbol element's symbol
* @return element with given symbol or empty {@link Optional}
*/
Optional findBySymbol(String symbol);
/**
* Finds element by name
*
* @param name element's name
* @return element with given name or empty {@link Optional}
*/
Optional findByName(String name);
/**
* Finds elements discovered in given year
*
* @param year year of discovery
* @return list of elements discovered in given year
*/
List findByYear(int year);
}
2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/cmd/ 0000775 0000000 0000000 00000000000 14052744030 0024677 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/cmd/CommandLine.java 0000664 0000000 0000000 00000002150 14052744030 0027726 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.cmd;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
/**
* Command Line Interface
*/
public final class CommandLine {
private final JCommander commander;
/**
* Constructs new CLI instance
*
* @param application application object to be populated with arguments
*/
public CommandLine(Object application) {
commander = JCommander.newBuilder()
.addObject(application)
.build();
commander.setProgramName(application.getClass().getSimpleName());
}
/**
* Parses command line arguments (terminates on error)
*
* @param args command line arguments of the application
*/
public void parseArguments(String[] args) {
try {
commander.parse(args);
} catch (ParameterException ex) {
System.err.println("Error: " + ex.getMessage());
showUsage();
}
}
/**
* Shows usage of the application and terminates
*/
public void showUsage() {
commander.usage();
}
}
2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/impl/ 0000775 0000000 0000000 00000000000 14052744030 0025075 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/impl/Application.java 0000664 0000000 0000000 00000002024 14052744030 0030201 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.impl;
import com.beust.jcommander.Parameter;
import cz.muni.fi.pb162.hw03.app.cmd.CommandLine;
import java.io.IOException;
/**
* Application CLI
*/
@SuppressWarnings("FieldMayBeFinal")
public final class Application {
@Parameter(names = "--help", help = true)
private boolean showUsage = false;
/**
* Application entry point
*
* @param args command line arguments of the application
* @throws IOException on unrecoverable IO error
*/
public static void main(String[] args) throws IOException {
Application app = new Application();
CommandLine cli = new CommandLine(app);
cli.parseArguments(args);
if (app.showUsage) {
cli.showUsage();
} else {
app.run(cli);
}
}
/**
* Application runtime logic
*
* @param cli command line interface
*/
private void run(CommandLine cli) {
throw new UnsupportedOperationException("Implement this method!");
}
}
2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/impl/Element.java 0000664 0000000 0000000 00000002672 14052744030 0027340 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.impl;
/**
* Representation of element
*/
public final class Element {
private final int atomicNumber;
private final String symbol;
private final String name;
private final String standardState;
private final String groupBlock;
private final int yearDiscovered;
/**
* Constructs element instance
*
* @param atomicNumber Atomic number
* @param symbol Symbol
* @param name Name
* @param standardState Standard state of occurrence
* @param groupBlock Group block in periodic table
* @param yearDiscovered Year of discovery
*/
public Element(
int atomicNumber, String symbol, String name,
String standardState, String groupBlock, int yearDiscovered
) {
this.atomicNumber = atomicNumber;
this.symbol = symbol;
this.name = name;
this.standardState = standardState;
this.groupBlock = groupBlock;
this.yearDiscovered = yearDiscovered;
}
public int getAtomicNumber() {
return this.atomicNumber;
}
public String getSymbol() {
return this.symbol;
}
public String getName() {
return this.name;
}
public String getStandardState() {
return this.standardState;
}
public String getGroupBlock() {
return this.groupBlock;
}
public int getYearDiscovered() {
return this.yearDiscovered;
}
} 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/output/ 0000775 0000000 0000000 00000000000 14052744030 0025474 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/output/ElementFormatter.java 0000664 0000000 0000000 00000001152 14052744030 0031613 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.output;
import cz.muni.fi.pb162.hw03.app.impl.Element;
import java.util.Collection;
/**
* Formatting of Element instances as string
*/
public interface ElementFormatter {
/**
* Formats element as string
*
* @param element formatted element
* @return String representation of given element
*/
String format(Element element);
/**
* Formats collection of elements as string
*
* @param elements formatted elements
* @return String representation of given elements
*/
String format(Collection elements);
}
2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/output/Messages.java 0000664 0000000 0000000 00000000460 14052744030 0030106 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.output;
/**
* Error message constants
*/
public final class Messages {
public static final String SINGLE_FILTER_REQUIRED = "Single filter is required!";
public static final String NO_ELEMENT_FOUND = "No matching element found!";
private Messages() { }
}
2021-hw03-elements-master/src/main/java/cz/muni/fi/pb162/hw03/app/output/TableFormatter.java 0000664 0000000 0000000 00000004540 14052744030 0031255 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.output;
import cz.muni.fi.pb162.hw03.app.impl.Element;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
/**
* Formatting of {@link Element} instances as ASCI table
*/
public class TableFormatter implements ElementFormatter {
private static final String ROW_SEPARATOR = "-------------------------------------------------" +
"------------------------------------------------------";
private static final String HEAD_SEPARATOR = "=================================================" +
"======================================================";
@Override
public String format(Element element) {
return lines(head(), row(element), ROW_SEPARATOR);
}
@Override
public String format(Collection elements) {
List rows = elements.stream().map(this::row).collect(toList());
return lines(head(), lines(rows), ROW_SEPARATOR);
}
private String head() {
String row = row("#", "Symbol", "Name", "Standard State", "Group Block", "Year");
return lines(ROW_SEPARATOR, row, HEAD_SEPARATOR);
}
private String row(Element element) {
return row(
String.valueOf(element.getAtomicNumber()),
element.getSymbol(),
element.getName(),
element.getStandardState(),
element.getGroupBlock(),
String.valueOf(element.getYearDiscovered())
);
}
private String row(String... data) {
if (data.length != 6) {
throw new IllegalArgumentException("Incorrect number of values");
}
return "|" +
String.format("%10s", data[0]) + "|" +
String.format("%10s", data[1]) + "|" +
String.format("%20s", data[2]) + "|" +
String.format("%20s", data[3]) + "|" +
String.format("%25s", data[4]) + "|" +
String.format("%10s", data[5]) +
"|";
}
private String lines(String... lines) {
return lines(Arrays.asList(lines));
}
private String lines(Collection lines) {
return lines.stream()
.collect(joining(System.lineSeparator()));
}
}
2021-hw03-elements-master/src/main/resources/ 0000775 0000000 0000000 00000000000 14052744030 0021050 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/main/resources/elements.csv 0000664 0000000 0000000 00000011574 14052744030 0023411 0 ustar 00root root 0000000 0000000 atomicNumber, symbol, name, standardState, groupBlock, yearDiscovered
1, H , Hydrogen,gas,nonmetal,1766
2, He , Helium,gas,noble gas,1868
3, Li , Lithium,solid,alkali metal,1817
4, Be , Beryllium,solid,alkaline earth metal,1798
5, B , Boron,solid,metalloid,1807
6, C , Carbon,solid,nonmetal,-1
7, N , Nitrogen,gas,nonmetal,1772
8, O , Oxygen,gas,nonmetal,1774
9, F , Fluorine,gas,halogen,1670
10, Ne , Neon,gas,noble gas,1898
11, Na , Sodium,solid,alkali metal,1807
12, Mg , Magnesium,solid,alkaline earth metal,1808
13, Al , Aluminum,solid,metal,-1
14, Si , Silicon,solid,metalloid,1854
15, P , Phosphorus,solid,nonmetal,1669
16, S , Sulfur,solid,nonmetal,-1
17, Cl , Chlorine,gas,halogen,1774
18, Ar , Argon,gas,noble gas,1894
19, K , Potassium,solid,alkali metal,1807
20, Ca , Calcium,solid,alkaline earth metal,-1
21, Sc , Scandium,solid,transition metal,1876
22, Ti , Titanium,solid,transition metal,1791
23, V , Vanadium,solid,transition metal,1803
24, Cr , Chromium,solid,transition metal,-1
25, Mn , Manganese,solid,transition metal,1774
26, Fe , Iron,solid,transition metal,-1
27, Co , Cobalt,solid,transition metal,-1
28, Ni , Nickel,solid,transition metal,1751
29, Cu , Copper,solid,transition metal,-1
30, Zn , Zinc,solid,transition metal,1746
31, Ga , Gallium,solid,metal,1875
32, Ge , Germanium,solid,metalloid,1886
33, As , Arsenic,solid,metalloid,-1
34, Se , Selenium,solid,nonmetal,1817
35, Br , Bromine,liquid,halogen,1826
36, Kr , Krypton,gas,noble gas,1898
37, Rb , Rubidium,solid,alkali metal,1861
38, Sr , Strontium,solid,alkaline earth metal,1790
39, Y , Yttrium,solid,transition metal,1794
40, Zr , Zirconium,solid,transition metal,1789
41, Nb , Niobium,solid,transition metal,1801
42, Mo , Molybdenum,solid,transition metal,1778
43, Tc , Technetium,solid,transition metal,1937
44, Ru , Ruthenium,solid,transition metal,1827
45, Rh , Rhodium,solid,transition metal,1803
46, Pd , Palladium,solid,transition metal,1803
47, Ag , Silver,solid,transition metal,-1
48, Cd , Cadmium,solid,transition metal,1817
49, In , Indium,solid,metal,1863
50, Sn , Tin,solid,metal,-1
51, Sb , Antimony,solid,metalloid,-1
52, Te , Tellurium,solid,metalloid,1782
53, I , Iodine,solid,halogen,1811
54, Xe , Xenon,gas,noble gas,1898
55, Cs , Cesium,solid,alkali metal,1860
56, Ba , Barium,solid,alkaline earth metal,1808
57, La , Lanthanum,solid,lanthanoid,1839
58, Ce , Cerium,solid,lanthanoid,1803
59, Pr , Praseodymium,solid,lanthanoid,1885
60, Nd , Neodymium,solid,lanthanoid,1885
61, Pm , Promethium,solid,lanthanoid,1947
62, Sm , Samarium,solid,lanthanoid,1853
63, Eu , Europium,solid,lanthanoid,1901
64, Gd , Gadolinium,solid,lanthanoid,1880
65, Tb , Terbium,solid,lanthanoid,1843
66, Dy , Dysprosium,solid,lanthanoid,1886
67, Ho , Holmium,solid,lanthanoid,1878
68, Er , Erbium,solid,lanthanoid,1842
69, Tm , Thulium,solid,lanthanoid,1879
70, Yb , Ytterbium,solid,lanthanoid,1878
71, Lu , Lutetium,solid,lanthanoid,1907
72, Hf , Hafnium,solid,transition metal,1923
73, Ta , Tantalum,solid,transition metal,1802
74, W , Tungsten,solid,transition metal,1783
75, Re , Rhenium,solid,transition metal,1925
76, Os , Osmium,solid,transition metal,1803
77, Ir , Iridium,solid,transition metal,1803
78, Pt , Platinum,solid,transition metal,-1
79, Au , Gold,solid,transition metal,-1
80, Hg , Mercury,liquid,transition metal,-1
81, Tl , Thallium,solid,metal,1861
82, Pb , Lead,solid,metal,-1
83, Bi , Bismuth,solid,metal,-1
84, Po , Polonium,solid,metalloid,1898
85, At , Astatine,solid,halogen,1940
86, Rn , Radon,gas,noble gas,1900
87, Fr , Francium,solid,alkali metal,1939
88, Ra , Radium,solid,alkaline earth metal,1898
89, Ac , Actinium,solid,actinoid,1899
90, Th , Thorium,solid,actinoid,1828
91, Pa , Protactinium,solid,actinoid,1913
92, U , Uranium,solid,actinoid,1789
93, Np , Neptunium,solid,actinoid,1940
94, Pu , Plutonium,solid,actinoid,1940
95, Am , Americium,solid,actinoid,1944
96, Cm , Curium,solid,actinoid,1944
97, Bk , Berkelium,solid,actinoid,1949
98, Cf , Californium,solid,actinoid,1950
99, Es , Einsteinium,solid,actinoid,1952
100, Fm , Fermium,,actinoid,1952
101, Md , Mendelevium,,actinoid,1955
102, No , Nobelium,,actinoid,1957
103, Lr , Lawrencium,,transition metal,1961
104, Rf , Rutherfordium,,transition metal,1969
105, Db , Dubnium,,transition metal,1967
106, Sg , Seaborgium,,transition metal,1974
107, Bh , Bohrium,,transition metal,1976
108, Hs , Hassium,,transition metal,1984
109, Mt , Meitnerium,,transition metal,1982
110, Ds , Darmstadtium,,transition metal,1994
111, Rg , Roentgenium,,transition metal,1994
112, Cn , Copernicium,,transition metal,1996
113, Nh , Nihonium,,post-transition metal,2003
114, Fl , Flerovium,,post-transition metal,1998
115, Mc , Moscovium,,post-transition metal,2003
116, Lv , Livermorium,,post-transition metal,2000
117, Ts , Tennessine,,post-transition metal,2010
118, Og , Oganesson,,noble gas,2002
2021-hw03-elements-master/src/test/ 0000775 0000000 0000000 00000000000 14052744030 0017071 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/ 0000775 0000000 0000000 00000000000 14052744030 0020012 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/ 0000775 0000000 0000000 00000000000 14052744030 0020426 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/ 0000775 0000000 0000000 00000000000 14052744030 0021376 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/fi/ 0000775 0000000 0000000 00000000000 14052744030 0021774 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/fi/pb162/ 0000775 0000000 0000000 00000000000 14052744030 0022626 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/fi/pb162/hw03/ 0000775 0000000 0000000 00000000000 14052744030 0023407 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/fi/pb162/hw03/TestUtils.java 0000664 0000000 0000000 00000000517 14052744030 0026215 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class TestUtils {
private TestUtils() {
}
public static Path resourcePath(String path) throws URISyntaxException {
return Paths.get(TestUtils.class.getResource(path).toURI());
}
} 2021-hw03-elements-master/src/test/java/cz/muni/fi/pb162/hw03/app/ 0000775 0000000 0000000 00000000000 14052744030 0024167 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/fi/pb162/hw03/app/impl/ 0000775 0000000 0000000 00000000000 14052744030 0025130 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/java/cz/muni/fi/pb162/hw03/app/impl/ApplicationTest.java 0000664 0000000 0000000 00000010216 14052744030 0031076 0 ustar 00root root 0000000 0000000 package cz.muni.fi.pb162.hw03.app.impl;
import cz.muni.fi.pb162.hw03.app.output.Messages;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErrAndOutNormalized;
import static cz.muni.fi.pb162.hw03.app.output.Messages.NO_ELEMENT_FOUND;
@ExtendWith(SoftAssertionsExtension.class)
class ApplicationTest {
@InjectSoftAssertions
SoftAssertions softly;
static List elements = List.of(
new Element(1, "H", "Hydrogen", "gas", "nonmetal", 1766),
new Element(2, "He", "Helium", "gas", "noble gas", 1868),
new Element(3, "Li", "Lithium", "solid", "alkali metal", 1817),
new Element(113, "Nh", "Nihonium", "", "post-transition metal", 2003),
new Element(115, "Mc", "Moscovium", "", "post-transition metal", 2003)
);
@Test
void printsElementByName() throws Exception {
Element actual = executeAndCovert("--name", "Hydrogen");
softly.assertThat(actual).isEqualTo(elements.get(0));
}
@Test
void printsElementByAtomicNumber() throws Exception {
Element actualShort = executeAndCovert("-n", "1");
Element actualLong = executeAndCovert("--number", "1");
softly.assertThat(actualShort).isEqualTo(elements.get(0));
softly.assertThat(actualLong).isEqualTo(elements.get(0));
}
@Test
void printsErrorOnWhenElementNotFound() throws Exception {
String actual = execute("-n", "333");
softly.assertThat(actual).contains(NO_ELEMENT_FOUND);
}
@Test
void printsElementBySymbol() throws Exception {
Element actualShort = executeAndCovert("-s", "He");
Element actualLong = executeAndCovert("--symbol", "He");
softly.assertThat(actualShort).isEqualTo(elements.get(1));
softly.assertThat(actualLong).isEqualTo(elements.get(1));
}
@Test
void printsElementByYear() throws Exception {
List actualShort = executeAndCovertList("-y", "2003");
List actualLong = executeAndCovertList("--year", "2003");
softly.assertThat(actualShort).containsExactly(elements.get(3), elements.get(4));
softly.assertThat(actualLong).contains(elements.get(3), elements.get(4));
}
@Test
void printsErrorOnMultipleFilters() throws Exception {
String actual = execute("-n", "1", "-s", "H");
softly.assertThat(actual).contains(Messages.SINGLE_FILTER_REQUIRED);
}
private String execute(String... args) throws Exception {
return tapSystemErrAndOutNormalized(() -> {
List cmd = new ArrayList<>();
Collections.addAll(cmd, args);
Application.main(cmd.toArray(new String[0]));
});
}
private Element executeAndCovert(String... args) throws Exception {
String output = execute(args);
return elementsFromTable(output).findAny().get();
}
private List executeAndCovertList(String... args) throws Exception {
String output = execute(args);
return elementsFromTable(output).collect(Collectors.toList());
}
private Stream elementsFromTable(String table) {
return table.lines()
.skip(3)
.filter(l -> l.startsWith("|"))
.map(this::rowToElement);
}
private Element rowToElement(String row) {
List data = Arrays.stream(row.split("\\|"))
.skip(1)
.map(String::trim)
.collect(Collectors.toList());
return new Element(
Integer.parseInt(data.get(0)),
data.get(1),
data.get(2),
data.get(3),
data.get(4),
Integer.parseInt(data.get(5))
);
}
} 2021-hw03-elements-master/src/test/resources/ 0000775 0000000 0000000 00000000000 14052744030 0021103 5 ustar 00root root 0000000 0000000 2021-hw03-elements-master/src/test/resources/elements.csv 0000664 0000000 0000000 00000000427 14052744030 0023437 0 ustar 00root root 0000000 0000000 atomicNumber, symbol, name, standardState, groupBlock, yearDiscovered
1, H , Hydrogen,gas,nonmetal,1766
2, He , Helium,gas,noble gas,1868
3, Li , Lithium,solid,alkali metal,1817
113, Nh , Nihonium,,post-transition metal,2003
115, Mc , Moscovium,,post-transition metal,2003