-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Julien Boz <[email protected]>
- Loading branch information
Showing
6 changed files
with
183 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 44 additions & 11 deletions
55
src/main/java/ch/ifocusit/plantuml/classdiagram/model/Link.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,63 @@ | ||
package ch.ifocusit.plantuml.classdiagram.model; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
@SuppressWarnings("unused") | ||
public class Link { | ||
private String url; | ||
private String label; | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
private String tooltip; | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[[%s{%s}]]", url, label); | ||
public void setTooltip(String tooltip) { | ||
this.tooltip = tooltip; | ||
} | ||
|
||
public String render(LinkContext context) { | ||
if (LinkContext.CLASS.equals(context)) { | ||
if (StringUtils.isNotBlank(tooltip) && StringUtils.isNotBlank(url)) { | ||
return String.format("[[%s{%s}]]", url, tooltip); | ||
} | ||
if (StringUtils.isNotBlank(tooltip) && StringUtils.isBlank(url)) { | ||
return String.format("[[{%s}]]", tooltip); | ||
} | ||
if (StringUtils.isNotBlank(url)) { | ||
return String.format("[[%s]]", url); | ||
} | ||
return StringUtils.EMPTY; | ||
} | ||
if (StringUtils.isNotBlank(tooltip) && StringUtils.isNotBlank(url) && StringUtils.isNotBlank(label)) { | ||
return String.format("[[[%s{%s} %s]]]", url, tooltip, label); | ||
} | ||
if (StringUtils.isNotBlank(tooltip) && StringUtils.isNotBlank(url) && StringUtils.isBlank(label)) { | ||
return String.format("[[[%s{%s}]]]", url, tooltip); | ||
} | ||
if (StringUtils.isBlank(tooltip) && StringUtils.isNotBlank(url) && StringUtils.isNotBlank(label)) { | ||
return String.format("[[[%s %s]]]", url, label); | ||
} | ||
if (StringUtils.isNotBlank(tooltip) && StringUtils.isBlank(url) && StringUtils.isBlank(label)) { | ||
return String.format("[[[{%s}]]]", tooltip); | ||
} | ||
if (StringUtils.isNotBlank(url) && StringUtils.isBlank(tooltip) && StringUtils.isBlank(label)) { | ||
return String.format("[[[%s]]]", url); | ||
} | ||
if (StringUtils.isNotBlank(url) && StringUtils.isNotBlank(label) && StringUtils.isBlank(tooltip)) { | ||
return String.format("[[[%s %s]]]", url, label); | ||
} | ||
if (StringUtils.isNotBlank(tooltip) && StringUtils.isBlank(url)) { | ||
return String.format("[[[{%s}]]]", tooltip); | ||
} | ||
return StringUtils.EMPTY; | ||
} | ||
|
||
public enum LinkContext { | ||
CLASS, FIELD, METHOD | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/ch/ifocusit/plantuml/classdiagram/model/LinkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package ch.ifocusit.plantuml.classdiagram.model; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class LinkTest { | ||
|
||
public static final String URL = "https://link.com"; | ||
public static final String LABEL = "label"; | ||
public static final String TOOLTIP = "tooltip"; | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
",,,,", | ||
URL + ",,,[[" + URL + "]]", | ||
URL + "," + LABEL + ",,[[" + URL + "]]", | ||
URL + "," + LABEL + "," + TOOLTIP + ",[[" + URL + "{" + TOOLTIP + "}]]", | ||
",," + TOOLTIP + ",[[{" + TOOLTIP + "}]]", | ||
}) | ||
void render_class(String url, String label, String tooltip, String expected) { | ||
// given | ||
Link link = new Link(); | ||
link.setUrl(url); | ||
link.setLabel(label); | ||
link.setTooltip(tooltip); | ||
// when | ||
String actual = link.render(Link.LinkContext.CLASS); | ||
// then | ||
assertThat(actual).isEqualTo(expected == null ? StringUtils.EMPTY : expected); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
",,,,", | ||
URL + ",,,[[[" + URL + "]]]", | ||
"," + LABEL + ",,", | ||
",," + TOOLTIP + ",[[[{" + TOOLTIP + "}]]]", | ||
URL + "," + LABEL + ",,[[[" + URL + " " + LABEL + "]]]", | ||
URL + ",," + TOOLTIP + ",[[[" + URL + "{" + TOOLTIP + "}]]]", | ||
URL + "," + LABEL + "," + TOOLTIP + ",[[[" + URL + "{" + TOOLTIP + "} " + LABEL + "]]]", | ||
"," + LABEL + "," + TOOLTIP + ",[[[{" + TOOLTIP + "}]]]", | ||
}) | ||
void render_field(String url, String label, String tooltip, String expected) { | ||
// given | ||
Link link = new Link(); | ||
link.setUrl(url); | ||
link.setLabel(label); | ||
link.setTooltip(tooltip); | ||
// when | ||
String actual = link.render(Link.LinkContext.FIELD); | ||
// then | ||
assertThat(actual).isEqualTo(expected == null ? StringUtils.EMPTY : expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@startuml | ||
|
||
class "Car" [[https://link.com/car]] { | ||
brand : String [[[https://link.com/car/brand lien]]] | ||
model : String [[[https://link.com/car/model{Show all cars' models} Car models]]] | ||
drivers : Set<Driver> [[[https://link.com/car/drivers]]] | ||
price : Price [[[https://link.com/car/price{Show details}]]] | ||
wheels : Collection<Wheel> | ||
addDriver(Driver) : Car | ||
addWheel(Wheel) | ||
buyBy(Driver, BigDecimal, Devise) : Driver | ||
} | ||
|
||
class "Driver" [[https://link.com/driver{Taxi Driver}]] { | ||
name : String | ||
cars : List<Car> | ||
addCar(Car) | ||
buy(Car) | ||
} | ||
|
||
"Car" "*" <-> "*" "Driver" : drivers/cars | ||
|
||
@enduml |