test_class.declarator: symbolRepo
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private SymbolRepository symbolRepo;
test_class.type: SymbolRepository
test_class.var_name: symbolRepo
test_class.declarator: rateService
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private RateService rateService;
test_class.type: RateService
test_class.var_name: rateService
test_class.declarator: portofolioRepo
test_class.modifier: @Autowired
  	private
test_class.original_string: @Autowired
  	private PortofolioRepository portofolioRepo;
test_class.type: PortofolioRepository
test_class.var_name: portofolioRepo
test_class.file: trading-common/src/test/java/fr/ymanvieu/trading/common/portofolio/entity/PortofolioEntityTest.java
test_class.identifier: PortofolioEntityTest
test_case.body: @Test
  	public void testBuy_NoFund() throws Exception {
  		String login = "seller";
  		String assetCode = "BRE";
  		double quantity = 1;
  
  		PortofolioEntity portofolio = portofolioRepo.findByUserUsername(login);
  
  		assertThatExceptionOfType(OrderException.class)
  			.isThrownBy(() -> portofolio.buy(symbolRepo.findById(assetCode).get(), quantity, rateService))
  			.withMessageContaining("not_enough_fund");
  		
  	}
test_case.class_method_signature: PortofolioEntityTest.testBuy_NoFund()
test_case.full_signature: @Test public void testBuy_NoFund()
test_case.identifier: testBuy_NoFund
test_case.invocations: findByUserUsername withMessageContaining isThrownBy assertThatExceptionOfType buy get findById
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testBuy_NoFund()
focal_class.declarator: id
focal_class.modifier: @Id
  	@GeneratedValue(strategy = GenerationType.IDENTITY)
  	private
focal_class.original_string: @Id
  	@GeneratedValue(strategy = GenerationType.IDENTITY)
  	private int id;
focal_class.type: int
focal_class.var_name: id
focal_class.declarator: user
focal_class.modifier: @Getter
  	@Nonnull
  	@OneToOne
  	@JoinColumn(name = "user_id", unique = true, nullable = false)
  	private
focal_class.original_string: @Getter
  	@Nonnull
  	@OneToOne
  	@JoinColumn(name = "user_id", unique = true, nullable = false)
  	private UserEntity user;
focal_class.type: UserEntity
focal_class.var_name: user
focal_class.declarator: baseCurrency
focal_class.modifier: @Getter
  	@Nonnull
  	@ManyToOne
  	@JoinColumn(name = "base_currency_code", nullable = false)
  	private
focal_class.original_string: @Getter
  	@Nonnull
  	@ManyToOne
  	@JoinColumn(name = "base_currency_code", nullable = false)
  	private SymbolEntity baseCurrency;
focal_class.type: SymbolEntity
focal_class.var_name: baseCurrency
focal_class.declarator: amount
focal_class.modifier: @Getter
  	@Nonnull
  	@Column(precision = 20, scale = 10, nullable = false)
  	private
focal_class.original_string: @Getter
  	@Nonnull
  	@Column(precision = 20, scale = 10, nullable = false)
  	private BigDecimal amount;
focal_class.type: BigDecimal
focal_class.var_name: amount
focal_class.declarator: version
focal_class.modifier: @Version
  	private
focal_class.original_string: @Version
  	private long version;
focal_class.type: long
focal_class.var_name: version
focal_class.declarator: assets = new ArrayList<>()
focal_class.modifier: @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "portofolio")
  	private
focal_class.original_string: @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "portofolio")
  	private List<AssetEntity> assets = new ArrayList<>();
focal_class.type: List<AssetEntity>
focal_class.var_name: assets
focal_class.file: trading-common/src/main/java/fr/ymanvieu/trading/common/portofolio/entity/PortofolioEntity.java
focal_class.identifier: PortofolioEntity
focal_class.class_method_signature: PortofolioEntity.getAssets()
focal_class.full_signature: public List<AssetEntity> getAssets()
focal_class.identifier: getAssets
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<AssetEntity>
focal_class.signature: List<AssetEntity> getAssets()
focal_class.class_method_signature: PortofolioEntity.getAsset(String symbolCode)
focal_class.full_signature: public AssetEntity getAsset(String symbolCode)
focal_class.identifier: getAsset
focal_class.modifiers: public
focal_class.parameters: (String symbolCode)
focal_class.return: AssetEntity
focal_class.signature: AssetEntity getAsset(String symbolCode)
focal_class.class_method_signature: PortofolioEntity.getCurrencyFor(SymbolEntity symbol)
focal_class.full_signature: public SymbolEntity getCurrencyFor(SymbolEntity symbol)
focal_class.identifier: getCurrencyFor
focal_class.modifiers: public
focal_class.parameters: (SymbolEntity symbol)
focal_class.return: SymbolEntity
focal_class.signature: SymbolEntity getCurrencyFor(SymbolEntity symbol)
focal_class.class_method_signature: PortofolioEntity.getCurrencies()
focal_class.full_signature: public List<SymbolEntity> getCurrencies()
focal_class.identifier: getCurrencies
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: List<SymbolEntity>
focal_class.signature: List<SymbolEntity> getCurrencies()
focal_class.class_method_signature: PortofolioEntity.buy(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.full_signature: public Order buy(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.identifier: buy
focal_class.modifiers: public
focal_class.parameters: (SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.return: Order
focal_class.signature: Order buy(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.class_method_signature: PortofolioEntity.sell(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.full_signature: public Order sell(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.identifier: sell
focal_class.modifiers: public
focal_class.parameters: (SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.return: Order
focal_class.signature: Order sell(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_class.class_method_signature: PortofolioEntity.removeAsset(AssetEntity ownedAsset)
focal_class.full_signature: private void removeAsset(AssetEntity ownedAsset)
focal_class.identifier: removeAsset
focal_class.modifiers: private
focal_class.parameters: (AssetEntity ownedAsset)
focal_class.return: void
focal_class.signature: void removeAsset(AssetEntity ownedAsset)
focal_class.superclass: extends AuditableEntity
focal_method.body: public Order buy(SymbolEntity fromSymbol, double quantity, RateService rateService) throws OrderException {
  
  		Objects.requireNonNull(fromSymbol, "fromSymbol must be not null");
  
  		Preconditions.checkArgument(quantity > 0, "quantity must be positive: %s", getBaseCurrency());
  		Preconditions.checkArgument(!getBaseCurrency().equals(fromSymbol), "Cannot buy baseCurrency: %s", getBaseCurrency());
  
  		final SymbolEntity currency = getCurrencyFor(fromSymbol);
  
  		Rate q = rateService.getLatest(fromSymbol.getCode(), currency.getCode());
  
  		final BigDecimal currencyAmount;
  
  		if (currency.equals(getBaseCurrency())) {
  			currencyAmount = getAmount();
  		} else if (getAsset(currency.getCode()) != null) {
  			currencyAmount = getAsset(currency.getCode()).getQuantity();
  		} else {
  			currencyAmount = ZERO;
  		}
  
  		BigDecimal amountNeeded = q.getValue().multiply(BigDecimal.valueOf(quantity));
  
  		if (currencyAmount.compareTo(amountNeeded) < 0) {
  			throw OrderException.NOT_ENOUGH_FUND(fromSymbol.getCode(), quantity, currency.getCode(), currencyAmount.doubleValue(),
  					amountNeeded.doubleValue());
  		}
  
  		AssetEntity ownedAsset = getAsset(fromSymbol.getCode());
  
  		if (ownedAsset == null) {
  			ownedAsset = new AssetEntity(this, fromSymbol, ZERO, currency, ZERO);
  			assets.add(ownedAsset);
  		}
  
  		BigDecimal fundAfterPurchase = currencyAmount.subtract(amountNeeded);
  
  		if (currency.equals(getBaseCurrency())) {
  			this.amount = fundAfterPurchase;
  		} else {
  			AssetEntity currencyAsset = getAsset(currency.getCode());
  			currencyAsset.withdraw(amountNeeded);
  		}
  
  		ownedAsset.makeDeposit(BigDecimal.valueOf(quantity), amountNeeded);
  
  		return new Order(currency, amountNeeded.doubleValue(), fromSymbol, quantity);
  	}
focal_method.class_method_signature: PortofolioEntity.buy(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_method.full_signature: public Order buy(SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_method.identifier: buy
focal_method.invocations: requireNonNull checkArgument getBaseCurrency checkArgument equals getBaseCurrency getBaseCurrency getCurrencyFor getLatest getCode getCode equals getBaseCurrency getAmount getAsset getCode getQuantity getAsset getCode multiply getValue valueOf compareTo NOT_ENOUGH_FUND getCode getCode doubleValue doubleValue getAsset getCode add subtract equals getBaseCurrency getAsset getCode withdraw makeDeposit valueOf doubleValue
focal_method.modifiers: public
focal_method.parameters: (SymbolEntity fromSymbol, double quantity, RateService rateService)
focal_method.return: Order
focal_method.signature: Order buy(SymbolEntity fromSymbol, double quantity, RateService rateService)