Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ workspace
.metadata/*
.recommenders/*
.DS_Store
.tycho-consumer-pom.xml

### IntelliJ IDEA ###
.idea
Expand Down
11 changes: 10 additions & 1 deletion name.abuchen.portfolio.tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="com/google/common/collect/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/name.abuchen.portfolio.pdfbox3">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
3 changes: 2 additions & 1 deletion name.abuchen.portfolio.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Require-Bundle: org.junit,
name.abuchen.portfolio.junit,
org.mockito.mockito-core
Automatic-Module-Name: name.abuchen.portfolio.tests
Import-Package: com.google.common.collect
Import-Package: com.google.common.collect,
name.abuchen.portfolio.model
15 changes: 15 additions & 0 deletions name.abuchen.portfolio.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,19 @@
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.4.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.ClientTestUtilities;
Expand All @@ -22,6 +23,8 @@
@SuppressWarnings("nls")
public class ReadingHistoricClientFilesTest
{
private NegativeValue negativeValue = new NegativeValue();

@Parameters(name = "{index}: {0}")
public static Collection<Object[]> getFiles()
{
Expand All @@ -42,20 +45,23 @@ public ReadingHistoricClientFilesTest(String file, int versionOnDisk)
@Test
public void compare() throws IOException
{
Client xmlClient = ClientFactory.load(find(file + ".xml"), null, new NullProgressMonitor());
Client xmlClient = ClientFactory.load(negativeValue, find(file + ".xml"), null, new NullProgressMonitor());
String xml = ClientTestUtilities.toString(xmlClient);
assertThat(xmlClient.getFileVersionAfterRead(), is(versionOnDisk));

Client binaryClient = ClientFactory.load(find(file + ".binary.portfolio"), null, new NullProgressMonitor());
Client binaryClient = ClientFactory.load(negativeValue, find(file + ".binary.portfolio"), null,
new NullProgressMonitor());
String binary = ClientTestUtilities.toString(binaryClient);
assertThat(binaryClient.getFileVersionAfterRead(), is(versionOnDisk));

Client binaryEncryptedClient = ClientFactory.load(find(file + ".binary+pwd.portfolio"), "123456".toCharArray(),
Client binaryEncryptedClient = ClientFactory.load(negativeValue, find(file + ".binary+pwd.portfolio"),
"123456".toCharArray(),
new NullProgressMonitor());
String binaryEncrypted = ClientTestUtilities.toString(binaryEncryptedClient);
assertThat(binaryEncryptedClient.getFileVersionAfterRead(), is(versionOnDisk));

Client xmlEncrpytedClient = ClientFactory.load(find(file + ".xml+pwd.portfolio"), "123456".toCharArray(),
Client xmlEncrpytedClient = ClientFactory.load(negativeValue, find(file + ".xml+pwd.portfolio"),
"123456".toCharArray(),
new NullProgressMonitor());
String xmlEncrpyted = ClientTestUtilities.toString(xmlEncrpytedClient);
assertThat(xmlEncrpytedClient.getFileVersionAfterRead(), is(versionOnDisk));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@

import org.junit.Test;

import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.ClientTestUtilities;

@SuppressWarnings("nls")
public class XStreamReferencesTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testReadingWithReferencesAndWritingWithoutReferences() throws IOException
{
Client withReferences = ClientFactory
.load(XStreamReferencesTest.class.getResourceAsStream("client_with_relative_references.xml"));
.load(negativeValue, XStreamReferencesTest.class
.getResourceAsStream("client_with_relative_references.xml"));

// check that the first two securities have the same latest price object
// (is a reference in the XML file)
Expand All @@ -29,15 +33,17 @@ public void testReadingWithReferencesAndWritingWithoutReferences() throws IOExce
.getLatest(), is(true));

String xml = ClientTestUtilities.toString(withReferences);
Client without = ClientFactory.load(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
Client without = ClientFactory.load(negativeValue,
new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
assertThat(without.getSecurities().get(0).getLatest() == without.getSecurities().get(1).getLatest(), is(false));
}

@Test
public void testReadingWithIdReferencesAndWritingWithoutIdReferences() throws IOException
{
Client withReferences = ClientFactory
.load(XStreamReferencesTest.class.getResourceAsStream("client_with_id_references.xml"), true);
.load(negativeValue, XStreamReferencesTest.class
.getResourceAsStream("client_with_id_references.xml"), true);

// check that the first two securities have the same latest price object
// (is a reference with "id" attribute in the XML file)
Expand All @@ -46,7 +52,8 @@ public void testReadingWithIdReferencesAndWritingWithoutIdReferences() throws IO
.getLatest(), is(true));

String xml = ClientTestUtilities.toString(withReferences, true);
Client without = ClientFactory.load(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
Client without = ClientFactory.load(negativeValue,
new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
assertThat(without.getSecurities().get(0).getLatest() == without.getSecurities().get(1).getLatest(), is(false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;

import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.SaveFlag;
Expand All @@ -25,10 +26,12 @@
@SuppressWarnings("nls")
public class SecurityEventSourceMovedTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testXMLFormat() throws IOException
{
Client client = ClientFactory.load(
Client client = ClientFactory.load(negativeValue,
SecurityEventSourceMovedTest.class.getResourceAsStream("client_with_security_events.xml"));

assertEvents(client);
Expand All @@ -37,7 +40,7 @@ public void testXMLFormat() throws IOException
@Test
public void testBinaryFormat() throws IOException
{
Client client = ClientFactory.load(find("client_with_security_events.portfolio"), null,
Client client = ClientFactory.load(negativeValue, find("client_with_security_events.portfolio"), null,
new NullProgressMonitor());

assertEvents(client);
Expand All @@ -53,8 +56,9 @@ public void testBinaryFormat() throws IOException
}))
{
Path tempFile = Files.createTempFile("test", ".portfolio");
ClientFactory.saveAs(client, tempFile.toFile(), null, EnumSet.of(SaveFlag.BINARY, SaveFlag.COMPRESSED));
Client rereadClient = ClientFactory.load(tempFile.toFile(), null, new NullProgressMonitor());
ClientFactory.saveAs(negativeValue, client, tempFile.toFile(), null,
EnumSet.of(SaveFlag.BINARY, SaveFlag.COMPRESSED));
Client rereadClient = ClientFactory.load(negativeValue, tempFile.toFile(), null, new NullProgressMonitor());
assertEvents(rereadClient);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.Security;
Expand All @@ -26,11 +27,13 @@

public class Issue1498FifoCrossPortfolioTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException
{
Client client = ClientFactory
.load(Issue1498FifoCrossPortfolioTest.class.getResourceAsStream("Issue1498FifoCrossPortfolio.xml")); //$NON-NLS-1$
Client client = ClientFactory.load(negativeValue,
Issue1498FifoCrossPortfolioTest.class.getResourceAsStream("Issue1498FifoCrossPortfolio.xml")); //$NON-NLS-1$

Security lufthansa = client.getSecurities().get(0);
assertThat(lufthansa.getName(), is("Deutsche Lufthansa AG")); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Classification;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
Expand All @@ -19,10 +20,12 @@

public class Issue1817CapitalGainsOnFilteredClientIfSecurityIsTransferredTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException
{
Client client = ClientFactory.load(Issue371PurchaseValueWithTransfersTest.class
Client client = ClientFactory.load(negativeValue, Issue371PurchaseValueWithTransfersTest.class
.getResourceAsStream("Issue1817CapitalGainsOnFilteredClientIfSecurityIsTransferred.xml")); //$NON-NLS-1$

CurrencyConverter converter = new TestCurrencyConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.money.CurrencyConverter;
Expand All @@ -22,10 +23,13 @@

public class Issue1879DividendRateOfReturnPerYearWithSecurityInMultipleAccountsTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException
{
Client client = ClientFactory.load(Issue1879DividendRateOfReturnPerYearWithSecurityInMultipleAccountsTest.class
Client client = ClientFactory.load(negativeValue,
Issue1879DividendRateOfReturnPerYearWithSecurityInMultipleAccountsTest.class
.getResourceAsStream("Issue1879DividendRateOfReturnPerYearWithSecurityInMultipleAccounts.xml")); //$NON-NLS-1$

CurrencyConverter converter = new TestCurrencyConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.AccountTransaction;
import name.abuchen.portfolio.model.Classification;
import name.abuchen.portfolio.model.Client;
Expand Down Expand Up @@ -40,11 +41,12 @@ public class Issue1897AddFeesToDividendTransactionsTest
private static CurrencyConverter converter = new TestCurrencyConverter();
private static Interval period = Interval.of(LocalDate.parse("2020-11-01"), //$NON-NLS-1$
LocalDate.parse("2020-12-31")); //$NON-NLS-1$
private static NegativeValue negativeValue = new NegativeValue();

@BeforeClass
public static void setup() throws IOException
{
client = ClientFactory.load(Issue371PurchaseValueWithTransfersTest.class
client = ClientFactory.load(negativeValue, Issue371PurchaseValueWithTransfersTest.class
.getResourceAsStream("Issue1897AddFeesToDividendTransactions.xml")); //$NON-NLS-1$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.Security;
Expand All @@ -21,10 +22,12 @@

public class Issue1898TradeIRRwithPortfolioTransfersTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException, TradeCollectorException
{
Client client = ClientFactory.load(Issue1898TradeIRRwithPortfolioTransfersTest.class
Client client = ClientFactory.load(negativeValue, Issue1898TradeIRRwithPortfolioTransfersTest.class
.getResourceAsStream("Issue1898TradeIRRwithPortfolioTransfers.xml")); //$NON-NLS-1$

CurrencyConverter converter = new TestCurrencyConverter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.Security;
Expand All @@ -26,10 +27,12 @@

public class Issue1909FIFOCalculationOfSecurityPositionTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testDefaultSnapshot() throws IOException
{
Client client = ClientFactory.load(Issue1909FIFOCalculationOfSecurityPositionTest.class
Client client = ClientFactory.load(negativeValue, Issue1909FIFOCalculationOfSecurityPositionTest.class
.getResourceAsStream("Issue1909FIFOCalculationOfSecurityPosition.xml")); //$NON-NLS-1$

Security security = client.getSecurities().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.PortfolioTransaction;
Expand All @@ -28,10 +29,12 @@

public class Issue371PurchaseValueWithTransfersTest
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException
{
Client client = ClientFactory.load(Issue371PurchaseValueWithTransfersTest.class
Client client = ClientFactory.load(negativeValue, Issue371PurchaseValueWithTransfersTest.class
.getResourceAsStream("Issue371PurchaseValueWithTransfers.xml")); //$NON-NLS-1$

Security adidas = client.getSecurities().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.Test;

import name.abuchen.portfolio.junit.TestCurrencyConverter;
import name.abuchen.portfolio.math.NegativeValue;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.ClientFactory;
import name.abuchen.portfolio.model.Security;
Expand All @@ -25,10 +26,12 @@

public class Issue4446FIFOMultipleTransfers
{
private NegativeValue negativeValue = new NegativeValue();

@Test
public void testDefaultSnapshot() throws IOException, TradeCollectorException
{
Client client = ClientFactory.load(
Client client = ClientFactory.load(negativeValue,
Issue4446FIFOMultipleTransfers.class.getResourceAsStream("Issue4446FIFOMultipleTransfers.xml")); //$NON-NLS-1$

Security security = client.getSecurities().get(0);
Expand All @@ -51,7 +54,7 @@ public void testFIFOWithTransferAndSameDayPurchase() throws IOException, TradeCo
// scenario: first a purchase (with a time in the transaction) and then
// an outbound transfer (without time stamp) on the same day

Client client = ClientFactory.load(Issue4446FIFOMultipleTransfers.class
Client client = ClientFactory.load(negativeValue, Issue4446FIFOMultipleTransfers.class
.getResourceAsStream("Issue4446FIFOTransferWithSameDayPurchase.xml")); //$NON-NLS-1$

Security security = client.getSecurities().get(0);
Expand Down
Loading