-
Notifications
You must be signed in to change notification settings - Fork 709
added widget for the dashboard and columns for the information of dividends #3927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kimmerin
wants to merge
14
commits into
portfolio-performance:master
Choose a base branch
from
kimmerin:dividend_widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a796f3c
added widget for the dashboard and columns for the information of
kimmerin 4e10694
use BeforeClass and AfterClass to make sure we've "selected" German
kimmerin de457f1
Previous change had no effect on the tests on the GitHub-Server, so
kimmerin 2cc9567
fixed missed test that still used the hard coded text
kimmerin 9f867ac
Update name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/…
kimmerin f7a5703
Update name.abuchen.portfolio.ui/src/name/abuchen/portfolio/ui/views/…
kimmerin 9aecbfc
use more readable column-identifiers, reformatted source to make the CI
kimmerin 40e059d
added other languages, courtesy of deepl.com
kimmerin f4e563d
show list of date types instead of single entries if ex-date and payment
kimmerin cde3a5b
Merge branch 'master' into dividend_widget
kimmerin efc3016
Merge branch 'portfolio-performance:master' into dividend_widget
kimmerin ef35837
Redesign of the widget to allow more entries to be shown. Show ellipses
kimmerin 9eda5c0
don't hide monetary values (that are only the dividend per share and
kimmerin 15400b2
removed unused parameter, use helper method for sorting. Portfolio view
kimmerin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
294 changes: 294 additions & 0 deletions
294
...tfolio.ui.tests/src/name/abuchen/portfolio/ui/views/dashboard/DividendListWidgetTest.java
This file contains hidden or 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,294 @@ | ||
| package name.abuchen.portfolio.ui.views.dashboard; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.hamcrest.Matchers.nullValue; | ||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| import name.abuchen.portfolio.model.Security; | ||
| import name.abuchen.portfolio.model.SecurityEvent; | ||
| import name.abuchen.portfolio.model.SecurityEvent.DividendEvent; | ||
| import name.abuchen.portfolio.money.Money; | ||
| import name.abuchen.portfolio.ui.Messages; | ||
| import name.abuchen.portfolio.ui.views.dashboard.DividendListWidget.DateEndRange; | ||
| import name.abuchen.portfolio.ui.views.dashboard.DividendListWidget.DateStartRange; | ||
| import name.abuchen.portfolio.ui.views.dashboard.DividendListWidget.DateType; | ||
| import name.abuchen.portfolio.ui.views.dashboard.DividendListWidget.DividendItem; | ||
|
|
||
| @SuppressWarnings("nls") | ||
| public class DividendListWidgetTest | ||
| { | ||
| private static Locale defaultLocale; | ||
|
|
||
| private Security sec1; | ||
| private Security sec2; | ||
| private DividendEvent de1_1; | ||
| private DividendEvent de1_2; | ||
| private SecurityEvent de1_3; | ||
| private DividendEvent de1_4; | ||
| private DividendEvent de1_5; | ||
| private DividendEvent de2_1; | ||
| private DividendEvent de2_2; | ||
| private SecurityEvent de2_3; | ||
| private DividendEvent de2_4; | ||
|
|
||
| @BeforeClass | ||
| public static void setupLocale() | ||
| { | ||
| defaultLocale = Locale.getDefault(); | ||
| Locale.setDefault(Locale.GERMANY); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void resetLocale() | ||
| { | ||
| Locale.setDefault(defaultLocale); | ||
| } | ||
|
|
||
| @Before | ||
| public void setupTestData() | ||
| { | ||
| sec1 = new Security("Security 1", "EUR"); | ||
| de1_1 = new DividendEvent(LocalDate.of(2024, 4, 9), LocalDate.of(2024, 4, 12), Money.of("EUR", 55), "source"); | ||
| de1_2 = new DividendEvent(LocalDate.of(2024, 7, 14), LocalDate.of(2024, 8, 11), Money.of("EUR", 22), "source"); | ||
| de1_3 = new SecurityEvent(LocalDate.of(2024, 2, 3), SecurityEvent.Type.NOTE, "some note"); | ||
| de1_4 = new DividendEvent(LocalDate.of(2024, 2, 4), LocalDate.of(2024, 3, 5), Money.of("EUR", 33), "source"); | ||
| de1_5 = new DividendEvent(LocalDate.of(2024, 8, 1), LocalDate.of(2024, 8, 1), Money.of("EUR", 33), "source"); | ||
| sec1.addEvent(de1_1); | ||
| sec1.addEvent(de1_2); | ||
| sec1.addEvent(de1_3); | ||
| sec1.addEvent(de1_4); | ||
|
|
||
| sec2 = new Security("Security 2", "EUR"); | ||
| de2_1 = new DividendEvent(LocalDate.of(2024, 4, 5), LocalDate.of(2024, 4, 9), Money.of("USD", 55), "source"); | ||
| de2_2 = new DividendEvent(LocalDate.of(2024, 7, 14), LocalDate.of(2024, 7, 15), Money.of("USD", 122), "source"); | ||
| de2_3 = new SecurityEvent(LocalDate.of(2024, 8, 25), SecurityEvent.Type.STOCK_SPLIT, "some stock split"); | ||
| de2_4 = new DividendEvent(LocalDate.of(2024, 2, 5), LocalDate.of(2024, 3, 5), Money.of("USD", 1333), "source"); | ||
| sec2.addEvent(de2_1); | ||
| sec2.addEvent(de2_2); | ||
| sec2.addEvent(de2_3); | ||
| sec2.addEvent(de2_4); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testDividendItemInstantiation() | ||
| { | ||
| DividendItem di; | ||
|
|
||
| di = new DividendItem(DateType.EX_DIVIDEND_DATE, sec1, de1_1); | ||
| assertThat(di.getSecurity(), is(sec1)); | ||
| assertThat(di.getFirstType(), is(DateType.EX_DIVIDEND_DATE)); | ||
| assertThat(di.div, is(de1_1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDateStartRange() | ||
| { | ||
| assertEquals("FROM_TODAY,FROM_ONE_WEEK,FROM_ONE_MONTH,FROM_QUARTER", // | ||
| Arrays.stream(DateStartRange.values()) | ||
| .map(DateStartRange::name).collect(Collectors.joining(","))); | ||
|
|
||
| LocalDate now = LocalDate.of(2024, 4, 8); | ||
| assertThat(DateStartRange.FROM_TODAY.getDate(now), is(now)); | ||
| assertThat(DateStartRange.FROM_ONE_WEEK.getDate(now), is(LocalDate.of(2024, 4, 1))); | ||
| assertThat(DateStartRange.FROM_ONE_MONTH.getDate(now), is(LocalDate.of(2024, 3, 8))); | ||
| assertThat(DateStartRange.FROM_QUARTER.getDate(now), is(LocalDate.of(2024, 1, 8))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDateEndRange() | ||
| { | ||
| assertEquals("UNTIL_ALL,UNTIL_EOY,UNTIL_ONE_MONTH,UNTIL_ONE_WEEK,UNTIL_TODAY", // | ||
| Arrays.stream(DateEndRange.values()).map(DateEndRange::name).collect(Collectors.joining(","))); | ||
|
|
||
| LocalDate now = LocalDate.of(2024, 4, 8); | ||
| assertThat(DateEndRange.UNTIL_TODAY.getDate(now), is(now)); | ||
| assertThat(DateEndRange.UNTIL_ONE_WEEK.getDate(now), is(LocalDate.of(2024, 4, 15))); | ||
| assertThat(DateEndRange.UNTIL_ONE_MONTH.getDate(now), is(LocalDate.of(2024, 5, 8))); | ||
| assertThat(DateEndRange.UNTIL_EOY.getDate(now), is(LocalDate.of(2024, 12, 31))); | ||
| assertThat(DateEndRange.UNTIL_ALL.getDate(now), nullValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDateType() | ||
| { | ||
| assertEquals("ALL_DATES,EX_DIVIDEND_DATE,PAYMENT_DATE", // | ||
| Arrays.stream(DateType.values()).map(DateType::name).collect(Collectors.joining(","))); | ||
|
|
||
| assertThat(DateType.ALL_DATES.getDate(de1_1), nullValue()); | ||
| assertThat(DateType.EX_DIVIDEND_DATE.getDate(de1_1), is(de1_1.getDate())); | ||
| assertThat(DateType.PAYMENT_DATE.getDate(de1_1), is(de1_1.getPaymentDate())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetUpdateTask() throws Exception | ||
| { | ||
| LocalDate testnow = LocalDate.now(); | ||
| AbstractSecurityListWidget<DividendItem> widget = new DividendListWidget() | ||
| { | ||
| @Override | ||
| public List<DividendItem> getUpdateTask(LocalDate now) | ||
| { | ||
| assertThat(now, is(testnow)); | ||
| return null; | ||
| } | ||
| }; | ||
| assertThat(widget.getUpdateTask().get(), nullValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetUpdateTaskNow() | ||
| { | ||
| List<DividendItem> list; | ||
| AtomicReference<DateStartRange> dateStart = new AtomicReference<>(DateStartRange.FROM_TODAY); | ||
| AtomicReference<DateEndRange> dateEnd = new AtomicReference<>(DateEndRange.UNTIL_TODAY); | ||
| AtomicReference<DateType> dateType = new AtomicReference<>(DateType.ALL_DATES); | ||
| AtomicBoolean showSecurities = new AtomicBoolean(true); | ||
|
|
||
| DividendListWidget widget = new DividendListWidget() | ||
| { | ||
| @Override | ||
| DateStartRange getStartRangeValue() | ||
| { | ||
| return dateStart.get(); | ||
| } | ||
|
|
||
| @Override | ||
| DateEndRange getEndRangeValue() | ||
| { | ||
| return dateEnd.get(); | ||
| } | ||
|
|
||
| @Override | ||
| DateType getDateTypeValue() | ||
| { | ||
| return dateType.get(); | ||
| } | ||
|
|
||
| @Override | ||
| List<Security> getSecurities() | ||
| { | ||
| return Arrays.asList(sec1, sec2); | ||
| } | ||
|
|
||
| @Override | ||
| ClientFilterConfig getClientFilterConfig() | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| Set<Security> getSecuritiesToShow(ClientFilterConfig clientFilter) | ||
| { | ||
| if (showSecurities.get()) | ||
| { | ||
| HashSet<Security> ret = new HashSet<>(); | ||
| ret.addAll(getSecurities()); | ||
| return ret; | ||
| } | ||
| return Collections.emptySet(); | ||
| } | ||
| }; | ||
|
|
||
| LocalDate now = LocalDate.of(2024, 4, 9); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-04-09 Security 1 EUR 0,55 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "Security 2 USD 0,55 [" + Messages.ColumnPaymentDate + "]", getListAsString(list)); | ||
|
|
||
| now = LocalDate.of(2024, 4, 8); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("", getListAsString(list)); | ||
|
|
||
| dateStart.set(DateStartRange.FROM_QUARTER); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-02-04 Security 1 EUR 0,33 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-02-05 Security 2 USD 13,33 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-03-05 Security 1 EUR 0,33 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "Security 2 USD 13,33 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-04-05 Security 2 USD 0,55 [" + Messages.ColumnExDate + "]", getListAsString(list)); | ||
|
|
||
| dateEnd.set(DateEndRange.UNTIL_EOY); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-02-04 Security 1 EUR 0,33 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-02-05 Security 2 USD 13,33 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-03-05 Security 1 EUR 0,33 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "Security 2 USD 13,33 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-04-05 Security 2 USD 0,55 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-04-09 Security 1 EUR 0,55 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "Security 2 USD 0,55 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-04-12 Security 1 EUR 0,55 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-07-14 Security 1 EUR 0,22 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "Security 2 USD 1,22 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-07-15 Security 2 USD 1,22 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-08-11 Security 1 EUR 0,22 [" + Messages.ColumnPaymentDate + "]", getListAsString(list)); | ||
|
|
||
| dateType.set(DateType.EX_DIVIDEND_DATE); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-02-04 Security 1 EUR 0,33 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-02-05 Security 2 USD 13,33 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-04-05 Security 2 USD 0,55 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-04-09 Security 1 EUR 0,55 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "2024-07-14 Security 1 EUR 0,22 [" + Messages.ColumnExDate + "]\r\n" // | ||
| + "Security 2 USD 1,22 [" + Messages.ColumnExDate + "]", getListAsString(list)); | ||
|
|
||
| dateType.set(DateType.PAYMENT_DATE); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-03-05 Security 1 EUR 0,33 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "Security 2 USD 13,33 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-04-09 Security 2 USD 0,55 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-04-12 Security 1 EUR 0,55 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-07-15 Security 2 USD 1,22 [" + Messages.ColumnPaymentDate + "]\r\n" // | ||
| + "2024-08-11 Security 1 EUR 0,22 [" + Messages.ColumnPaymentDate + "]", getListAsString(list)); | ||
|
|
||
| sec1.getEvents().clear(); | ||
| sec2.getEvents().clear(); | ||
| sec1.addEvent(de1_5); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-08-01 Security 1 EUR 0,33 [" + Messages.ColumnPaymentDate + "]", getListAsString(list)); | ||
| dateType.set(DateType.EX_DIVIDEND_DATE); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-08-01 Security 1 EUR 0,33 [" + Messages.ColumnExDate + "]", getListAsString(list)); | ||
| dateType.set(DateType.ALL_DATES); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("2024-08-01 Security 1 EUR 0,33 [" + Messages.ColumnExDate + ", " + Messages.ColumnPaymentDate | ||
| + "]", getListAsString(list)); | ||
|
|
||
| showSecurities.set(false); | ||
| list = widget.getUpdateTask(now); | ||
| assertEquals("", getListAsString(list)); | ||
| } | ||
|
|
||
| private String getListAsString(List<DividendItem> list) | ||
| { | ||
| return list.stream() // | ||
| .map(entry -> { | ||
| StringBuilder sb = new StringBuilder(); | ||
| if (entry.hasNewDate) | ||
| { | ||
| sb.append(entry.getFirstType().getDate(entry.div).toString() + " "); | ||
| } | ||
| sb.append(entry.getSecurity().getName() + " "); | ||
| sb.append(entry.div.getAmount() + " "); | ||
| sb.append(entry.types); | ||
| return sb.toString(); | ||
| }) // | ||
| .collect(Collectors.joining("\r\n")); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.