001/* 002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.test.generator.impl; 017 018import de.cuioss.test.generator.Generators; 019import de.cuioss.test.generator.TypedGenerator; 020 021import java.time.LocalTime; 022 023/** 024 * Generates {@link LocalTime} instances covering all possible times within a day. 025 * The generator creates times with second precision, evenly distributed across 026 * the full 24-hour period. 027 * 028 * <p>Features:</p> 029 * <ul> 030 * <li>Generates times from 00:00:00 to 23:59:59</li> 031 * <li>Uses second-level precision</li> 032 * <li>Even distribution across all possible seconds of the day</li> 033 * <li>Thread-safe implementation</li> 034 * </ul> 035 * 036 * <p><em>Example usage:</em></p> 037 * <pre> 038 * {@code 039 * // Create a generator 040 * var generator = new LocalTimeGenerator(); 041 * 042 * // Generate single values 043 * LocalTime time = generator.next(); 044 * 045 * // Generate collections 046 * var collectionGen = new CollectionGenerator<>(generator); 047 * List<LocalTime> times = collectionGen.list(5); // List of 5 times 048 * } 049 * </pre> 050 * 051 * <p>This generator is particularly useful for testing:</p> 052 * <ul> 053 * <li>Time formatting and parsing</li> 054 * <li>Time-based calculations</li> 055 * <li>Time range validations</li> 056 * <li>24-hour format handling</li> 057 * </ul> 058 * 059 * @author Eugen Fischer 060 * @see LocalTime 061 * @see Generators#integers(int, int) 062 */ 063public class LocalTimeGenerator implements TypedGenerator<LocalTime> { 064 065 private static final Integer SECONDS_PER_DAY = 24 * 60 * 60; 066 067 @Override 068 public LocalTime next() { 069 return LocalTime.ofSecondOfDay(Generators.integers(0, SECONDS_PER_DAY - 1).next().longValue()); 070 } 071 072 @Override 073 public Class<LocalTime> getType() { 074 return LocalTime.class; 075 } 076 077}