mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 17:59:43 +02:00
Add Profile.withAliases() utility function
This commit is contained in:
parent
9677f1fd0b
commit
e481717421
2 changed files with 24 additions and 0 deletions
|
@ -50,6 +50,16 @@ data class Profile(
|
||||||
|
|
||||||
fun hasDescription() = description.isPresent
|
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.
|
* Convert the profile into a String for displaying.
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,6 +39,20 @@ public class ProfileTest {
|
||||||
assertEquals(Arrays.asList("Bar", "Baz"), profile.getAliases());
|
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
|
@Test
|
||||||
public void toStringNameOnly() {
|
public void toStringNameOnly() {
|
||||||
Profile profile = new Profile("default");
|
Profile profile = new Profile("default");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue