mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-08 17:59:43 +02:00
Fix profile constructors
This commit is contained in:
parent
e5cb58468b
commit
9677f1fd0b
2 changed files with 5 additions and 5 deletions
|
@ -33,8 +33,9 @@ data class Profile(
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(
|
constructor(
|
||||||
name: String,
|
name: String,
|
||||||
description: String? = null
|
description: String? = null,
|
||||||
) : this(name, Optional.ofNullable(description?.trim()?.ifBlank { null }))
|
aliases: List<String> = listOf()
|
||||||
|
) : this(name, Optional.ofNullable(description?.trim()?.ifBlank { null }), aliases)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(name.trim().isNotBlank()) { "Name cannot be empty." }
|
require(name.trim().isNotBlank()) { "Name cannot be empty." }
|
||||||
|
@ -85,10 +86,10 @@ data class Profile(
|
||||||
description.substring(
|
description.substring(
|
||||||
description.indexOf("(aliases: ") + 10, description.indexOf(")"))
|
description.indexOf("(aliases: ") + 10, description.indexOf(")"))
|
||||||
description = description.substring(0, description.indexOf("(aliases: ")).trim()
|
description = description.substring(0, description.indexOf("(aliases: ")).trim()
|
||||||
Profile(name, Optional.of(description), aliases.split(", ").toList())
|
Profile(name, description, aliases.split(", ").toList())
|
||||||
} else {
|
} else {
|
||||||
if (description.isNotBlank()) {
|
if (description.isNotBlank()) {
|
||||||
Profile(name, Optional.of(description))
|
Profile(name, description)
|
||||||
} else {
|
} else {
|
||||||
Profile(name)
|
Profile(name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ public class ProfileTest {
|
||||||
assertEquals("Foo: Something something (aliases: Bar, Baz)", profile.toString());
|
assertEquals("Foo: Something something (aliases: Bar, Baz)", profile.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseWithAliases() {
|
public void parseWithAliases() {
|
||||||
Profile profile = Profile.parse("Foo: Something something (aliases: Bar, Baz)");
|
Profile profile = Profile.parse("Foo: Something something (aliases: Bar, Baz)");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue