원클릭으로
junit-testing
// JUnit 6 testing patterns for Xeres including Mockito with constructor injection, test fixtures via *Fakes.java classes, and AssertJ assertions.
// JUnit 6 testing patterns for Xeres including Mockito with constructor injection, test fixtures via *Fakes.java classes, and AssertJ assertions.
| name | junit-testing |
| description | JUnit 6 testing patterns for Xeres including Mockito with constructor injection, test fixtures via *Fakes.java classes, and AssertJ assertions. |
src/test/java/ mirrors main source structure*Test.java suffix
@ExtendWith(MockitoExtension.class)
class ContactServiceTest
{
@Mock
private ProfileService profileService;
@InjectMocks
private ContactService contactService;
@Test
void getContacts_ShouldReturnCombinedList()
{
when(profileService.getProfiles()).thenReturn(List.of());
var result = contactService.getContacts();
assertTrue(result.isEmpty());
}
}
@InjectMocks)@Mock creates a mock, @Spy creates a partial mockwhen(...).thenReturn(...) for stubbingverify(...).method() for interaction testingassertTrue(...) but it's also possible to use assertJ for more complex casesUse *Fakes.java in common/src/testFixtures/java/io/xeres/:
public final class ProfileFakes
{
private ProfileFakes()
{
throw new UnsupportedOperationException("Utility class");
}
public static Profile createProfile()
{
return createProfile(1L, "Test Profile");
}
public static Profile createProfile(long id, String name)
{
var profile = new Profile();
profile.setId(id);
profile.setName(name);
return profile;
}
public static Profile createOwnProfile()
{
var profile = createProfile();
profile.setOwn(true);
return profile;
}
}
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;
assertNotNull(result);
assertEquals("Test",result.getName);
assertThat(list).
hasSize(2).
contains(profile1, profile2);
assertThatThrownBy(() ->service.
save(null))
.
isInstanceOf(IllegalArgumentException .class);
@Test
void save_WithNullProfile_ShouldThrow()
{
assertThatThrownBy(() -> contactService.save(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("Profile must not be null");
}
ui-testing skill for JavaFX controller testingarchunit-rules skill for testing architecture rulesArchUnit architecture rules enforced in Xeres including common module rules (logging, utility classes), app module rules (no field injection, RsService naming), and UI module rules (WindowController naming).
Cryptography patterns for Xeres including PGP operations, key generation, and hash functions with best practices.
DTO and mapper patterns for Xeres using Java records, canonical constructors with validation, and static mapper utility classes.
Flyway SQL migration patterns for Xeres including naming conventions, H2 database patterns, enum types, foreign keys, and best practices.
Gradle build configuration for Xeres including build commands, version management, module structure, and key plugins.
Code style, naming conventions, license headers, and patterns for Xeres Java project. Covers Allman braces, utility classes, package structure, and field injection rules.