Skip to content
Snippets Groups Projects
Commit 8d91dd67 authored by jez04's avatar jez04
Browse files

initial

parent 9d204cdd
Branches
No related merge requests found
KeyboardKicker;255
CompilerCaptain;84
KeyboardKnight;176
CodeCommander;160
ProtocolPioneer;157
PixelPoet;45
SyntaxSamurai;67
AppArchitect;288
ByteNinja;104
RenderRuler;153
FunctionFreak;291
BitBuilder
DataDetective;276
SocialButterfly;210
WebWeaver;276
FilterFanatic;162
GigabyteGuru;172
StoryStylist;225
StoryStylist;37
WebWeaver;62
StreamSupreme;197
SocialScribe;36
ProgramProdigy;135
InstaGuru;235
JavaJester;93
/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */
\ No newline at end of file
src/main/resources/lab/fireball-transparent.gif

412 KiB

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="lab.GameController">
<bottom>
<HBox alignment="TOP_CENTER" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<Slider fx:id="angle" majorTickUnit="15.0" max="90.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minorTickCount="5" showTickLabels="true" showTickMarks="true" HBox.hgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#fire" style="-fx-background-color: RED;" text="Fire" textAlignment="CENTER">
<font>
<Font name="System Bold" size="24.0" />
</font>
<cursor>
<Cursor fx:constant="CROSSHAIR" />
</cursor>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
<Slider fx:id="speed" max="200.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="50.0" minorTickCount="5" showTickLabels="true" showTickMarks="true" value="50.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</bottom>
<center>
<Canvas fx:id="canvas" height="306.0" width="582.0" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</Canvas>
</center>
<top>
<Label fx:id="hits" text="Hit count: 0" textAlignment="CENTER" BorderPane.alignment="CENTER" />
</top>
</BorderPane>
src/main/resources/lab/ufo-small.gif

6.22 KiB

src/main/resources/lab/ufo.gif

36.2 KiB

<Configuration>
<Appenders>
<Console name="Console">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"></AppenderRef>
</Root>
</Loggers>
</Configuration>
package cz.vsb.fei.lab;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
/**
* Unit test for simple App.
*/
class AppTest {
/**
* Rigorous Test :-)
*/
@Test
void shouldAnswerWithTrue() {
assertTrue(true);
}
}
package jez04.structure.test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.reflections.Configuration;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;
import org.reflections.util.ConfigurationBuilder;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import cz.vsb.fei.lab.App;
import cz.vsb.fei.lab.Score;
import cz.vsb.fei.lab.ScoreNotLoaded;
class ClassStructureTest {
StructureHelper helper = new StructureHelper();
private static String className = "Score";
@Test
void gameControllerExistenceTest() {
helper.classExist("GameController");
void scoreExistenceTest() {
// helper.classExist(className);
Class<?> c = Score.class;//helper.getClass(className);
helper.hasProperty(c, "name", String.class, false);
helper.hasProperty(c, "points", int.class, false);
helper.hasMethod(c, "generate", Score.class);
}
@Test
void gameControllerFxmlTest() {
helper.classExist("GameController");
Class<?> c = helper.getClass("GameController");
helper.hasPropertyWithAnnotation(c, ".*", FXML.class);
}
@Test
void gameControllerActionMethodTest() {
helper.classExist("GameController");
Class<?> c = helper.getClass("GameController");
helper.hasMethodRegexp(c, ".*", void.class, ActionEvent.class);
void scoreNotLoadedExistenceTest() {
// helper.classExist(className);
Class<?> c = ScoreNotLoaded.class; //helper.getClass("cz.vsb.fei.lab.Score");
helper.hasProperty(c, "count", int.class, false);
helper.hasExtends(c, Exception.class);
}
@Test
void gameControllerLambdasTest() {
helper.classExist("GameController");
Class<?> c = helper.getClass("GameController");
long lamdaCount = helper.countMethodRegexp(c, "lambda\\$.*");
long innerClasscount = helper.countClassesRegexp(".*GameController\\$.*");
assertTrue(lamdaCount + innerClasscount >= 2,
"At least 2 inner classes or lamdas required for GameController but only "
+ (lamdaCount + innerClasscount) + " found.");
void generateScoresTest() {
App app = new App();
assertTrue(app.generateScores(10).size() == 10);
}
@Test
void hitListenerExistenceTest() {
helper.classExist("HitListener");
void loadScoresFromStreamTest() throws Exception {
App app = new App();
assertTrue(app.loadScoresFromStream(new InputStreamReader(App.class.getResourceAsStream("/bestScore-ok.csv"))).size() > 1);
}
@Test
void hitListenerEventMethodTest() {
helper.classExist("HitListener");
Class<?> c = helper.getClass("HitListener");
helper.hasMethod(c, "ufoDestroyed");
void loadScoresFromStreamExceptionTest() throws Exception {
App app = new App();
try {
app.loadScoresFromStream(new InputStreamReader(App.class.getResourceAsStream("/bestScores-err.csv"))).size();
fail("Exception not throwen");
} catch (Exception e) {
assertEquals(e.getClass(), ScoreNotLoaded.class, "Expected exception of type ScoreNotLoaded");
}
}
@Test
void sceneCollectionTest() {
helper.classExist("World");
Class<?> c = helper.getClass("World");
long collectionCount = Arrays.asList(c.getDeclaredFields()).stream()
.filter(f -> Collection.class.isAssignableFrom(f.getType())).count();
assertTrue(collectionCount >= 3, "lab.Scene require atleast 3 filed of type/subtype Collection, but only "
+ collectionCount + " found.");
void loadScoresTest() {
App app = new App();
app.loadScores();
}
@Test
void worldMethodAddTest() {
helper.classExist("World");
Class<?> c = helper.getClass("World");
helper.hasMethod(c, "add", void.class, helper.getClass("DrawableSimulable"));
;
void saveScoresTest() throws FileNotFoundException {
App app = new App();
app.saveScores(app.generateScores(10), "test.csv");
}
@Test
void worldMethodRemoveTest() {
helper.classExist("World");
Class<?> c = helper.getClass("World");
helper.hasMethod(c, "remove", void.class, helper.getClass("DrawableSimulable"));
;
}
@Test
void bulletAnimatedMethodAddTest() {
helper.classExist("BulletAnimated");
Class<?> c = helper.getClass("BulletAnimated");
Class<?> l = helper.getClass("HitListener");
helper.hasMethodRegexp(c, "add.*", List.of(void.class, boolean.class), l);
}
@Test
void bulletAnimatedMethodRemoveTest() {
helper.classExist("Ufo");
Class<?> c = helper.getClass("BulletAnimated");
Class<?> l = helper.getClass("HitListener");
helper.hasMethodRegexp(c, "remove.*", List.of(void.class, boolean.class), l);
}
@Test
void bulletAnimatedMethodFireTest() {
helper.classExist("BulletAnimated");
Class<?> c = helper.getClass("BulletAnimated");
assertTrue(helper.countMethodRegexp(c, "fire.*") > 0, "Method fire.* in LochNess not found.");
void saveScoresDirsTest() throws FileNotFoundException {
App app = new App();
app.saveScores(app.generateScores(10), "test/test.csv");
}
}
......@@ -19,7 +19,6 @@ import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -43,6 +42,21 @@ class StructureHelper {
assertTrue(allClasses.stream().anyMatch(c -> c.endsWith(name)), "Class/Interface " + name + " not found");
}
public Class<?> getClassDirectly(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream ps = new PrintStream(baos, true)) {
e.printStackTrace(ps);
} catch (Exception e2) {
Assertions.fail(e2.getMessage());
}
String stackTrace = baos.toString();
Assertions.fail("Class " + name + " not found.\n" + stackTrace);
return null;
}
}
public Class<?> getClass(String name) {
String className = allClasses.stream().filter(c -> c.endsWith(name)).findAny().orElse(null);
if (className == null) {
......@@ -122,32 +136,9 @@ class StructureHelper {
assertTrue(methods.stream().anyMatch(m -> m.getName().matches(methodNameRegexp)),
"No method " + methodNameRegexp);
assertTrue(
methods.stream().filter(
m ->
m.getName().matches(methodNameRegexp))
.filter(
m ->
m.getReturnType().equals(returnType))
.anyMatch(m ->
Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))),
"Method " + methodNameRegexp + " has no all parrams:"
+ Arrays.asList(params).stream().map(Class::getName).collect(Collectors.joining(", ")));
}
public void hasMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, Collection<Class<?>> returnTypeOnOf,
Class<?>... params) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().matches(methodNameRegexp)),
"No method " + methodNameRegexp);
assertTrue(
methods.stream().filter(
m ->
m.getName().matches(methodNameRegexp))
.filter(
m ->
returnTypeOnOf.contains(m.getReturnType()))
.anyMatch(m ->
Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))),
methods.stream().filter(m -> m.getName().matches(methodNameRegexp))
.filter(m -> m.getReturnType().equals(returnType))
.anyMatch(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))),
"Method " + methodNameRegexp + " has no all parrams:"
+ Arrays.asList(params).stream().map(Class::getName).collect(Collectors.joining(", ")));
}
......@@ -179,6 +170,11 @@ class StructureHelper {
"Class " + clazz.getName() + " not extends class " + parentName);
}
public void hasExtends(Class<?> clazz, Class<?> parent) {
assertTrue(clazz.getSuperclass().equals(parent),
"Class " + clazz.getName() + " not extends class " + parent.getCanonicalName());
}
public void hasMethod(Class<?> interfaceDef, String methodName) {
List<Method> methods = Arrays.asList(interfaceDef.getMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().contains(methodName)), "No method " + methodName);
......@@ -186,8 +182,8 @@ class StructureHelper {
public Set<String> getNameOfAllClasses() {
List<String> initClassesName = new ArrayList<>();
dynamicaliFoundSomeClass(initClassesName);
initClassesName.addAll(List.of("lab.Routines", "lab.App", "lab.DrawingThread"));
// dynamicaliFoundSomeClass(initClassesName);
initClassesName.addAll(List.of("cz.vsb.fei.lab.Score", "lab.Routines", "lab.App", "lab.DrawingThread"));
for (String className : initClassesName) {
try {
Class.forName(className);
......@@ -209,12 +205,12 @@ class StructureHelper {
.forPackages(p.getName());
Reflections reflections = new Reflections(conf);
allClasses.addAll(reflections.getAll(Scanners.SubTypes.filterResultsBy(c -> {
System.out.println(c);
System.out.println(">>> " + c);
return true;
})));
}
for (String string : allClasses) {
System.out.println(string);
System.out.println(":::" + string);
}
return allClasses;
}
......@@ -223,7 +219,10 @@ class StructureHelper {
URL myClassUrl = StructureHelper.class.getResource("ClassStructureTest.class");
myClassUrl.getFile();
try {
Path classRoot = Paths.get(myClassUrl.toURI()).getParent().getParent().getParent().getParent();
Path classRoot = Paths.get(myClassUrl.toURI());
while(!"test-classes".equals(classRoot.getFileName().toString()) && !"classes".equals(classRoot.getFileName().toString())) {
classRoot = classRoot.getParent();
}
if ("test-classes".equals(classRoot.getFileName().toString())) {
classRoot = classRoot.getParent().resolve("classes");
}
......
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