Adds maven wrapper ; rework internal a bit ; Adds all tests for core

This commit is contained in:
Guillaume Tâche
2024-12-25 22:40:01 +01:00
parent 38056c43f7
commit 58fbbff7cb
99 changed files with 5028 additions and 1649 deletions

View File

@@ -0,0 +1,23 @@
package com.github.gtache.fxml.compiler;
/**
* Base field {@link InjectionType}s
*/
public enum ControllerFieldInjectionType implements InjectionType {
/**
* Inject using variable assignment
*/
ASSIGN,
/**
* Inject using a factory
*/
FACTORY,
/**
* Inject using reflection
*/
REFLECTION,
/**
* Inject using setters
*/
SETTERS
}

View File

@@ -0,0 +1,15 @@
package com.github.gtache.fxml.compiler;
/**
* Base controller {@link InjectionType}s
*/
public enum ControllerInjectionType implements InjectionType {
/**
* Inject the controller instance
*/
INSTANCE,
/**
* Inject a controller factory
*/
FACTORY
}

View File

@@ -0,0 +1,15 @@
package com.github.gtache.fxml.compiler;
/**
* Base methods {@link InjectionType}s
*/
public enum ControllerMethodsInjectionType implements InjectionType {
/**
* Inject using visible methods
*/
REFERENCE,
/**
* Inject using reflection
*/
REFLECTION,
}

View File

@@ -36,26 +36,26 @@ public interface GenerationParameters {
*
* @return The injection
*/
InjectionType controllerInjectionType();
ControllerInjectionType controllerInjectionType();
/**
* Returns the field injection to use
*
* @return The injection
*/
InjectionType fieldInjectionType();
ControllerFieldInjectionType fieldInjectionType();
/**
* Returns the method injection to use
*
* @return The injection
*/
InjectionType methodInjectionType();
ControllerMethodsInjectionType methodInjectionType();
/**
* Returns the resource injection to use
*
* @return The injection
*/
InjectionType resourceInjectionType();
ResourceBundleInjectionType resourceInjectionType();
}

View File

@@ -0,0 +1,27 @@
package com.github.gtache.fxml.compiler;
/**
* Base {@link InjectionType}s for resource bundles
*/
public enum ResourceBundleInjectionType implements InjectionType {
/**
* Resource bundle is injected in the constructor
*/
CONSTRUCTOR,
/**
* Resource bundle is injected as a function in the constructor
*/
CONSTRUCTOR_FUNCTION,
/**
* Resource bundle name is injected in the constructor
*/
CONSTRUCTOR_NAME,
/**
* Resource bundle is loaded using getBundle
*/
GET_BUNDLE,
/**
* Resource bundle is retrieved from controller using getter
*/
GETTER
}

View File

@@ -0,0 +1,53 @@
package com.github.gtache.fxml.compiler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class TestGenerationException {
private final String message;
private final Throwable throwable;
private final String throwableString;
TestGenerationException(@Mock final Throwable throwable) {
this.message = "message";
this.throwable = Objects.requireNonNull(throwable);
this.throwableString = "throwable";
}
@BeforeEach
void beforeEach() {
when(throwable.toString()).thenReturn(throwableString);
}
@Test
void testOnlyMessage() {
final var exception = new GenerationException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
}
@Test
void testOnlyCause() {
final var exception = new GenerationException(throwable);
assertEquals(throwableString, exception.getMessage());
assertEquals(throwable, exception.getCause());
}
@Test
void testMessageAndCause() {
final var exception = new GenerationException(message, throwable);
assertEquals(message, exception.getMessage());
assertEquals(throwable, exception.getCause());
}
}

View File

@@ -0,0 +1,53 @@
package com.github.gtache.fxml.compiler.parsing;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class TestParseException {
private final String message;
private final Throwable throwable;
private final String throwableString;
TestParseException(@Mock final Throwable throwable) {
this.message = "message";
this.throwable = Objects.requireNonNull(throwable);
this.throwableString = "throwable";
}
@BeforeEach
void beforeEach() {
when(throwable.toString()).thenReturn(throwableString);
}
@Test
void testOnlyMessage() {
final var exception = new ParseException(message);
assertEquals(message, exception.getMessage());
assertNull(exception.getCause());
}
@Test
void testOnlyCause() {
final var exception = new ParseException(throwable);
assertEquals(throwableString, exception.getMessage());
assertEquals(throwable, exception.getCause());
}
@Test
void testMessageAndCause() {
final var exception = new ParseException(message, throwable);
assertEquals(message, exception.getMessage());
assertEquals(throwable, exception.getCause());
}
}