From developer-kit-java
Generates Mockito unit tests for Spring @Service classes. Mocks repositories/clients, verifies interactions, tests exceptions/stubs for isolated business logic without DB/APIs.
How this skill is triggered — by the user, by Claude, or both
Slash command
/developer-kit-java:unit-test-service-layerThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Provides patterns for unit testing `@Service` classes using Mockito. Mocks repository calls, verifies method invocations, tests exception scenarios, and stubs external API responses. Enables fast, isolated tests without Spring container or database.
Provides patterns for unit testing @Service classes using Mockito. Mocks repository calls, verifies method invocations, tests exception scenarios, and stubs external API responses. Enables fast, isolated tests without Spring container or database.
@Service classesFollow this workflow to test service layer with Mockito, including validation checkpoints:
Use @ExtendWith(MockitoExtension.class) to enable Mockito annotations.
@Mock and @InjectMocksUse @Mock for dependencies (repositories, clients) and @InjectMocks for the service under test.
Arrange: Create test data and configure mock return values using when().thenReturn().
Act: Execute the service method being tested.
Assert:
verify()Configure mocks to throw exceptions with when().thenThrow().
Validation checkpoint: Verify exception type and message
mvn test or gradle testmvn test jacoco:report@ExtendWith(MockitoExtension.class)
class UserServiceTest {
@Mock
private UserRepository userRepository;
@InjectMocks
private UserService userService;
@Test
void shouldReturnUserWhenFound() {
// Arrange
User expected = new User(1L, "Alice");
when(userRepository.findById(1L)).thenReturn(Optional.of(expected));
// Act
User result = userService.getUser(1L);
// Assert
assertThat(result.getName()).isEqualTo("Alice");
verify(userRepository).findById(1L);
}
@Test
void shouldThrowWhenUserNotFound() {
// Arrange
when(userRepository.findById(999L)).thenReturn(Optional.empty());
// Act & Assert
assertThatThrownBy(() -> userService.getUser(999L))
.isInstanceOf(UserNotFoundException.class);
}
}
@Test
void shouldSendEmailOnUserCreation() {
User newUser = new User(1L, "Alice", "[email protected]");
when(userRepository.save(any(User.class))).thenReturn(newUser);
enrichmentService.registerNewUser("Alice", "[email protected]");
verify(userRepository).save(any(User.class));
verify(emailService).sendWelcomeEmail("[email protected]");
}
For additional patterns (multiple dependencies, argument captors, async services, InOrder verification), see references/examples.md.
@ExtendWith(MockitoExtension.class) for JUnit 5 integrationexpectedUser, actualUser, captor@Spy; partial mocking is harder to understand and maintain.any(), eq()) cannot be mixed with actual values in the same stub.npx claudepluginhub giuseppe-trisciuoglio/developer-kit --plugin developer-kit-javaTest Java applications - JUnit 5, Mockito, integration testing, TDD patterns
Provides Spring Boot testing patterns for unit (Mockito), slice (@DataJpaTest/@WebMvcTest), integration (@SpringBootTest), and Testcontainers-based tests with JUnit 5. Use when writing @Test methods, @MockBean mocks, or test suites.
Generates JUnit 5 unit tests with Mockito and Testcontainers integration tests for Java services, repositories, controllers, and utilities. Auto-detects Maven/Gradle/Spring Boot setup from build files.