Skip to content

Commit

Permalink
Add more UniqueAccountImpl code
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgrandt committed Jan 13, 2024
1 parent 4344cfd commit 6cc5ab6
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import com.ericgrandt.totaleconomy.common.data.CurrencyData;
import net.kyori.adventure.text.Component;
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.service.context.Context;
Expand All @@ -18,11 +20,18 @@ public class UniqueAccountImpl implements UniqueAccount {
private final UUID accountId;
private final Map<Currency, BigDecimal> balances;
private final BalanceData balanceData;

public UniqueAccountImpl(UUID accountId, Map<Currency, BigDecimal> balances, BalanceData balanceData) {
private final CurrencyData currencyData;

public UniqueAccountImpl(
UUID accountId,
Map<Currency, BigDecimal> balances,
BalanceData balanceData,
CurrencyData currencyData
) {
this.accountId = accountId;
this.balances = balances;
this.balanceData = balanceData;
this.currencyData = currencyData;
}

@Override
Expand Down Expand Up @@ -67,16 +76,17 @@ public BigDecimal balance(Currency currency, Cause cause) {

@Override
public Map<Currency, BigDecimal> balances(Set<Context> contexts) {
return null;
return balances;
}

@Override
public Map<Currency, BigDecimal> balances(Cause cause) {
return null;
return balances;
}

@Override
public TransactionResult setBalance(Currency currency, BigDecimal amount, Set<Context> contexts) {
// update map, get currencyId, call balanceData.updateBalance()
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.UUID;

import com.ericgrandt.totaleconomy.common.data.CurrencyData;
import com.ericgrandt.totaleconomy.common.data.dto.CurrencyDto;
import net.kyori.adventure.text.Component;
import org.junit.jupiter.api.Tag;
Expand All @@ -16,6 +17,8 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.service.economy.Currency;
import org.spongepowered.api.service.economy.transaction.TransactionResult;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -24,6 +27,9 @@ public class UniqueAccountImplTest {
@Mock
private BalanceData balanceDataMock;

@Mock
private CurrencyData currencyDataMock;

private final CurrencyDto currencyDto = new CurrencyDto(
1,
"Dollar",
Expand All @@ -40,7 +46,8 @@ public void displayName_ShouldReturnDisplayName() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -59,7 +66,8 @@ public void hasBalance_Contexts_WithBalanceForCurrency_ShouldReturnTrue() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -77,7 +85,8 @@ public void hasBalance_Contexts_WithNoBalanceForCurrency_ShouldReturnFalse() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -95,7 +104,8 @@ public void hasBalance_Cause_WithBalanceForCurrency_ShouldReturnTrue() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -113,7 +123,8 @@ public void hasBalance_Cause_WithNoBalanceForCurrency_ShouldReturnFalse() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -131,7 +142,8 @@ public void balance_Contexts_WithBalanceForCurrency_ShouldReturnBalance() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -150,7 +162,8 @@ public void balance_Contexts_WithNoBalanceForCurrency_ShouldReturnZero() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -169,7 +182,8 @@ public void balance_Cause_WithBalanceForCurrency_ShouldReturnBalance() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -188,7 +202,8 @@ public void balance_Cause_WithNoBalanceForCurrency_ShouldReturnZero() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -199,14 +214,81 @@ public void balance_Cause_WithNoBalanceForCurrency_ShouldReturnZero() {
assertEquals(expected, actual);
}

@Test
@Tag("Unit")
public void balance_Contexts_ShouldReturnHashMapOfBalances() {
// Arrange
CurrencyImpl currency = new CurrencyImpl(currencyDto);
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock,
currencyDataMock
);

// Act
Map<Currency, BigDecimal> actual = sut.balances(new HashSet<>());
Map<Currency, BigDecimal> expected = Map.of(currency, BigDecimal.valueOf(100));

// Assert
assertEquals(expected, actual);
}

@Test
@Tag("Unit")
public void balance_Cause_ShouldReturnHashMapOfBalances() {
// Arrange
CurrencyImpl currency = new CurrencyImpl(currencyDto);
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock,
currencyDataMock
);

// Act
Map<Currency, BigDecimal> actual = sut.balances((Cause) null);
Map<Currency, BigDecimal> expected = Map.of(currency, BigDecimal.valueOf(100));

// Assert
assertEquals(expected, actual);
}

@Test
@Tag("Unit")
public void setBalance_Contexts_WithBalance_ShouldSetBalance() {
// Arrange
CurrencyImpl currency = new CurrencyImpl(currencyDto);
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
Map.of(currency, BigDecimal.valueOf(100)),
balanceDataMock,
currencyDataMock
);

// Act
TransactionResult actual = sut.setBalance(currency, BigDecimal.TEN, new HashSet<>());
TransactionResult expected = null;

// Assert
assertEquals(expected, actual);
}

@Test
@Tag("Unit")
public void setBalance_Contexts_WithNoBalance_ShouldSetBalance() {

}

@Test
@Tag("Unit")
public void identifier_ShouldReturnStringIdentifier() {
// Arrange
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand All @@ -224,7 +306,8 @@ public void uniqueId_ShouldReturnUuid() {
UniqueAccountImpl sut = new UniqueAccountImpl(
UUID.fromString("00000000-0000-0000-0000-000000000000"),
new HashMap<>(),
balanceDataMock
balanceDataMock,
currencyDataMock
);

// Act
Expand Down

0 comments on commit 6cc5ab6

Please sign in to comment.