Incrementally implement new features in Java repositories from natural language descriptions. Use when adding functionality to existing Java codebases (Maven or Gradle projects). Takes a feature description as input and outputs modified repository with implementation code, corresponding JUnit tests, and verification that all tests pass. Supports method additions, new class creation, and method modifications with proper Java conventions.
Install with Tessl CLI
npx tessl i github:ArabelaTso/Skills-4-SE --skill incremental-java-programmer89
Does it follow best practices?
If you maintain this skill, you can automatically optimize it using the tessl CLI to improve its score:
npx tessl skill review --optimize ./path/to/skillValidation for skill structure
Implement new features in Java repositories by analyzing the codebase, generating implementation code, creating comprehensive tests, and ensuring all tests pass before completion.
Understand the Java project structure and build system:
Identify build system:
pom.xml in root directorybuild.gradle or build.gradle.ktsExamine project structure:
src/
├── main/
│ └── java/
│ └── com/example/project/
│ ├── model/
│ ├── service/
│ ├── controller/
│ └── util/
└── test/
└── java/
└── com/example/project/
├── model/
├── service/
└── controller/Extract key information:
pom.xml or build.gradleBreak down the natural language feature description into actionable components:
Identify feature type:
Extract requirements:
Example feature description:
"Add a method to calculate the total price of items in a shopping cart,
including tax. The tax rate should be configurable. If the cart is empty,
return 0. The method should throw an exception if the tax rate is negative."Parsed components:
ShoppingCartcalculateTotalWithTax(double taxRate)doubleIllegalArgumentException for negative tax rateFind where the implementation should be added:
For new classes:
src/main/java/[package-path]/For existing classes:
For modifications:
Write Java code following project conventions:
Code structure:
/**
* [Javadoc description of what the method does]
*
* @param paramName description of parameter
* @return description of return value
* @throws ExceptionType description of when exception is thrown
*/
public ReturnType methodName(ParamType paramName) {
// Input validation
if (invalidCondition) {
throw new IllegalArgumentException("Error message");
}
// Business logic
ReturnType result = performCalculation();
// Return result
return result;
}Best practices:
For new classes:
package com.example.project.service;
import java.util.List;
/**
* Service class for managing shopping cart operations.
*/
public class ShoppingCartService {
private final TaxCalculator taxCalculator;
public ShoppingCartService(TaxCalculator taxCalculator) {
this.taxCalculator = taxCalculator;
}
// Methods here
}Create comprehensive JUnit tests for the new functionality:
Test class structure:
package com.example.project.service;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import static org.junit.jupiter.api.Assertions.*;
class ShoppingCartServiceTest {
private ShoppingCartService service;
@BeforeEach
void setUp() {
service = new ShoppingCartService(new TaxCalculator());
}
@Test
@DisplayName("Should calculate total with tax correctly")
void testCalculateTotalWithTax() {
// Arrange
double subtotal = 100.0;
double taxRate = 0.08;
// Act
double result = service.calculateTotalWithTax(subtotal, taxRate);
// Assert
assertEquals(108.0, result, 0.01);
}
@Test
@DisplayName("Should throw exception for negative tax rate")
void testNegativeTaxRate() {
assertThrows(IllegalArgumentException.class, () -> {
service.calculateTotalWithTax(100.0, -0.05);
});
}
@Test
@DisplayName("Should return zero for empty cart")
void testEmptyCart() {
double result = service.calculateTotalWithTax(0.0, 0.08);
assertEquals(0.0, result, 0.01);
}
}Test coverage requirements:
Test naming conventions:
@DisplayName for readable test descriptionsModify existing tests if the feature changes existing behavior:
Identify affected tests:
Update test assertions:
// Before
assertEquals(100.0, cart.getTotal());
// After (if feature adds tax calculation)
assertEquals(108.0, cart.getTotalWithTax(0.08));Add new test cases:
Execute the test suite to ensure all tests pass:
For Maven projects:
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=ShoppingCartServiceTest
# Run with verbose output
mvn test -XFor Gradle projects:
# Run all tests
./gradlew test
# Run specific test class
./gradlew test --tests ShoppingCartServiceTest
# Run with detailed output
./gradlew test --infoVerify test results:
If tests fail:
Perform final checks before completion:
Code quality checks:
Integration checks:
Documentation checks:
Feature: "Add a method to validate email addresses"
Implementation:
/**
* Validates if the given string is a valid email address.
*
* @param email the email address to validate
* @return true if valid, false otherwise
* @throws IllegalArgumentException if email is null
*/
public boolean isValidEmail(String email) {
if (email == null) {
throw new IllegalArgumentException("Email cannot be null");
}
String emailRegex = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$";
return email.matches(emailRegex);
}Test:
@Test
void testValidEmail() {
assertTrue(validator.isValidEmail("user@example.com"));
}
@Test
void testInvalidEmail() {
assertFalse(validator.isValidEmail("invalid-email"));
}
@Test
void testNullEmail() {
assertThrows(IllegalArgumentException.class, () -> {
validator.isValidEmail(null);
});
}Feature: "Create a UserService class to manage user operations"
Implementation:
package com.example.project.service;
import com.example.project.model.User;
import com.example.project.repository.UserRepository;
import java.util.Optional;
/**
* Service class for managing user-related operations.
*/
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
/**
* Finds a user by their ID.
*
* @param userId the user ID
* @return Optional containing the user if found
*/
public Optional<User> findById(Long userId) {
if (userId == null || userId <= 0) {
throw new IllegalArgumentException("Invalid user ID");
}
return userRepository.findById(userId);
}
}Feature: "Update the calculateDiscount method to support percentage-based discounts"
Before:
public double calculateDiscount(double price) {
return price * 0.1; // Fixed 10% discount
}After:
public double calculateDiscount(double price, double discountRate) {
if (price < 0) {
throw new IllegalArgumentException("Price cannot be negative");
}
if (discountRate < 0 || discountRate > 1) {
throw new IllegalArgumentException("Discount rate must be between 0 and 1");
}
return price * discountRate;
}c1fb172
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.