Add Profile.withAliases() utility function

This commit is contained in:
Paul Schaub 2025-05-30 12:48:24 +02:00
parent 9677f1fd0b
commit e481717421
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 24 additions and 0 deletions

View file

@ -50,6 +50,16 @@ data class Profile(
fun hasDescription() = description.isPresent
/**
* Return a copy of this [Profile] with the aliases set to the given strings.
*
* @param alias one or more alias names
* @return profile with aliases
*/
fun withAliases(vararg alias: String): Profile {
return Profile(name, description, alias.toList())
}
/**
* Convert the profile into a String for displaying.
*

View file

@ -39,6 +39,20 @@ public class ProfileTest {
assertEquals(Arrays.asList("Bar", "Baz"), profile.getAliases());
}
@Test
public void changeAliasesWithWithAliases() {
Profile p = new Profile("Foo", "Bar any Baz", Arrays.asList("tinitus", "particle"));
p = p.withAliases("fnord", "qbit");
assertEquals("Foo", p.getName());
assertEquals("Bar any Baz", p.getDescription().get());
assertTrue(p.getAliases().contains("fnord"));
assertTrue(p.getAliases().contains("qbit"));
assertFalse(p.getAliases().contains("tinitus"));
assertFalse(p.getAliases().contains("particle"));
}
@Test
public void toStringNameOnly() {
Profile profile = new Profile("default");