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.domain; 017 018import de.cuioss.test.generator.TypedGenerator; 019import de.cuioss.test.generator.internal.net.java.quickcheck.generator.PrimitiveGenerators; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import static de.cuioss.test.generator.Generators.fixedValues; 025 026/** 027 * Generates realistic email subject lines for testing purposes, particularly focused 028 * on healthcare-related communications. 029 * 030 * <p>Subject line components:</p> 031 * <ul> 032 * <li>Prefixes (0-3): "Re:", "Fw:", "Answ:", "Yep:"</li> 033 * <li>Content words (0-7): Healthcare-related terms like "Patient", "Document", "Hospital", etc.</li> 034 * </ul> 035 * 036 * <p>The generator creates subject lines by combining:</p> 037 * <ol> 038 * <li>Random number (0-3) of prefix elements</li> 039 * <li>Random number (0-7) of content words</li> 040 * <li>All elements are joined with spaces</li> 041 * </ol> 042 * 043 * <p><em>Example outputs:</em></p> 044 * <pre> 045 * "Re: Fw: Patient Document" 046 * "Hospital Doctor Referral" 047 * "Answ: Registration Physician" 048 * </pre> 049 * 050 * <p><em>Example usage:</em></p> 051 * <pre> 052 * var generator = new MailSubjectGenerator(); 053 * String subject = generator.next(); // Returns a randomly generated subject line 054 * </pre> 055 * 056 * @author Oliver Wolff 057 */ 058public class MailSubjectGenerator implements TypedGenerator<String> { 059 060 private final TypedGenerator<String> prefixes = fixedValues("Re:", "Fw:", "Answ:", "Yep:"); 061 private final TypedGenerator<String> contents = fixedValues("Hello", "Patient", "Document", "Record", "Yes", "No", 062 "unknown", "Disease", "Hospital", "Doctor", "Healthy", "Not seen", "Referral", "Message", "Injury", 063 "See Also", "Payment", "Registration", "Physician"); 064 065 @Override 066 public String next() { 067 final List<String> elements = new ArrayList<>(); 068 for (var i = 0; i < PrimitiveGenerators.integers(0, 3).next(); i++) { 069 elements.add(prefixes.next()); 070 } 071 for (var i = 0; i < PrimitiveGenerators.integers(0, 7).next(); i++) { 072 elements.add(contents.next()); 073 } 074 return String.join(" ", elements); 075 } 076 077}