Commit 788a3c3a authored by Marek Šabo's avatar Marek Šabo
Browse files

Initial Hello world working project

parents
# Created by .ignore support plugin (hsz.mobi)
### Java template
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# 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/
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## 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
### Eclipse template
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
# Eclipse Core
.project
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# JDT-specific (Eclipse Java Development Tools)
.classpath
# Java annotation processor (APT)
.factorypath
# PDT-specific
.buildpath
# sbteclipse plugin
.target
# TeXlipse plugin
.texlipse
### NetBeans template
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
.nb-gradle/
# Vim
*.un~
# OS X .DS_Store
.DS_Store
# project files
polygon-out.txt
polygon.bin
image: maven:3.5-jdk-10
build:
script:
- mvn clean install -B -Dcheckstyle.fail=true
tags:
- shared-fi
PB162 Java
=============
At the left upper part you can see the list of branches with the assignments.
You can find all necessary information [here](https://gitlab.fi.muni.cz/pb162/pb162-course-info/wikis/home).
**Private information for teachers is [here](https://gitlab.fi.muni.cz/pb162/pb162-teachers-info/wikis/home)**.
# Current branch `master`
This branch consist of working _Hello world_ project with the passing tests. Try it!
\ No newline at end of file
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<!--<property name="fileExtensions" value="java, xml, properties"/>-->
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter"/>
<module name="TreeWalker">
<!-- Checks for Javadoc comments. -->
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
</module>
<module name="JavadocType">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle">
<property name="scope" value="public"/>
<property name="checkFirstSentence" value="false"/>
</module>
<module name="WriteTag">
<property name="tag" value="@author"/>
<property name="tagFormat" value="..* ..*"/>
<!-- What to do if the tag does not exists? -->
<property name="severity" value="error"/>
<!-- What to do if the tag exists? -->
<property name="tagSeverity" value="ignore"/>
</module>
<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<!-- Checks for imports -->
<!-- See http://checkstyle.sf.net/config_import.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="MethodLength">
<property name="max" value="30"/>
<property name="countEmpty" value="false"/>
</module>
<module name="ParameterNumber"/>
<!-- Modifier Checks -->
<!-- See http://checkstyle.sf.net/config_modifier.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="LeftCurly">
<property name="option" value="eol"/>
</module>
<module name="NeedBraces">
<property name="allowSingleLineStatement" value="true"/>
</module>
<module name="RightCurly"/>
<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<!-- Checks for class design -->
<!-- See http://checkstyle.sf.net/config_design.html -->
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>
<!-- Miscellaneous other checks. -->
<!-- See http://checkstyle.sf.net/config_misc.html -->
<module name="ArrayTypeStyle"/>
</module>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>cz.muni.fi.pb162</groupId>
<artifactId>seminar-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.maven.plugin.checkstyle>2.17</version.maven.plugin.checkstyle>
<version.plugin.checkstyle>8.5</version.plugin.checkstyle>
<version.plugin.source>2.4</version.plugin.source>
<version.junit>4.12</version.junit>
<version.assertj>3.8.0</version.assertj>
<checkstyle.fail>false</checkstyle.fail>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${version.assertj}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Include sources into JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${version.plugin.source}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Check code style -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${version.maven.plugin.checkstyle}</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>pb162_codestyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failOnViolation>${checkstyle.fail}</failOnViolation>
<violationSeverity>warning</violationSeverity>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
<excludes>*/**/Draw*</excludes>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<!-- Overriding outdated default checkstyle to avoid bugs,
see https://github.com/checkstyle/checkstyle/issues/5296 -->
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${version.plugin.checkstyle}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
package cz.muni.fi.pb162.project;
/**
* Class for running main method.
*
* @author TODO: put your name here
*/
public class Demo {
/**
* Runs the code.
*
* @param args command line arguments, will be ignored
*/
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
package cz.muni.fi.pb162.project.demo;
import cz.muni.fi.pb162.project.Demo;
import cz.muni.fi.pb162.project.helper.OutputTester;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Testing print output of Demo class.
*
* @author Marek Sabo
*/
public class DemoTest {
private static final String EXPECTED_OUTPUT = "Hello world!" + System.lineSeparator();
@Test
public void testMainOutput() {
assertThat(actualOutput()).isEqualTo(EXPECTED_OUTPUT);
}
@SuppressWarnings("AccessStaticViaInstance")
private String actualOutput() {
OutputTester ot = new OutputTester();
ot.captureOutput();
new Demo().main(null);
ot.releaseOutput();
return ot.getOutput();
}
}
package cz.muni.fi.pb162.project.helper;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
/**
* @author Radek Oslejsek, Petr Adamek, Marek Sabo
*/
public class BasicRulesTester extends Assert {
public static void attributesFinal(Class clazz) {
Field[] attributes = BasicRulesTester.getFields(clazz);
for (Field field : attributes) {
assertTrue("Attributes should be final", Modifier.isFinal(field.getModifiers()));
}
}
public static void attributesAmount(Class clazz, int expected) {
long notConstantAttributes = Arrays.stream(clazz.getDeclaredFields())
.filter(x -> !isConstant(x.getModifiers()))
.count();
Assertions.assertThat(notConstantAttributes)
.as("Too many non-constant attributes: %s", notConstantAttributes)
.isLessThanOrEqualTo(expected);
}
public static void methodsAmount(Class clazz, int expected) {
long nonPrivateMethods = Arrays.stream(clazz.getDeclaredMethods())
.filter(x -> !isPrivate(x.getModifiers()))
.count();
Assertions.assertThat(nonPrivateMethods)
.as("Too many non-private methods: %s", nonPrivateMethods)
.isLessThanOrEqualTo(expected);
}
/**
* Tests class inheritance ancestor.
*
* @param ancestor ancestor class
* @param checkedClass class to be checked
*/
public static void testAncestor(Class ancestor, Class checkedClass) {
assertEquals("Class " + checkedClass + " should inherit from class " + ancestor,
ancestor, checkedClass.getSuperclass());
}
private static Field[] getFields(Class clazz) {
return Arrays.stream(clazz.getDeclaredFields())
.filter(field -> !field.isSynthetic())
.toArray(Field[]::new);
}
private static boolean isConstant(int mod) {
return Modifier.isStatic(mod) && Modifier.isFinal(mod);
}
private static boolean isPrivate(int mod) {
return Modifier.isPrivate(mod);
}
}
package cz.muni.fi.pb162.project.helper;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* @author Radek Oslejsek, Marek Sabo
*/
public class OutputTester {
private OutputStream os;
private PrintStream tempOutput;
private PrintStream origOutput;
/**
* Constructor
*/
public OutputTester() {
os = new ByteArrayOutputStream();
tempOutput = new PrintStream(os);
}
/**
* Capture stdout and temporarily replace it with controlled output stream
*/
public void captureOutput() {
origOutput = System.out;
System.setOut(tempOutput);
}
/**
* Release the captured stdout
*/
public void releaseOutput() {
System.setOut(origOutput);
}
/**
* Returns output.
*
* @return output string
*/
public String getOutput() {
return os.toString();
}
}
Supports Markdown
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