renan freth

Greenhorn
+ Follow
since Mar 28, 2020
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by renan freth

Tim Holloway wrote:In practical terms, when you're working with a banking system it would be via doubl-entry accounting. A transfer would require 2 operations: 1) subtract amount to transfer from source. 2) add amount to transfer to destination.

To avoid losing (or doubling) money, these two operations would normally be part of a single Database Transaction.

So here's a pseudo-code you might use with Spring Data:


With Spring Data annotations, this could all be done automatically in a method marked @Transactional. and you wouldn't have to commit/rollback manually and the method would simply throw an InsufficientFundsException (which is a class that you subclass from Exception).



I am using MongoDB as the database. I don't think I have the ability to use Spring Data JPA annotations.
3 years ago

Campbell Ritchie wrote:Surely you would have a validation of the same rule for a withdrawal already.I hope you have been taught that it is error‑prone to use doubles for money because of their imprecision. It would be better to have the transfer as an instance method of an account.



Interesting. Thank you.
3 years ago
Another point I would like to mention is:

3 years ago

Paul Clapham wrote:Wouldn't a transfer between two accounts require two queries, one for each account?




Yes. How would I do this query on my service transfer method?
As I mentioned, I don't feel safe using @Query
3 years ago

Campbell Ritchie wrote:Please start by explaining the rule in plain English, maybe, “The amount transferred must not be more than the balance of the originating account.”



Exact.
Sorry for the ignorance because I'm using the google translator.
3 years ago

Campbell Ritchie wrote:What would you query for the recipient account? Would you simply verify its existence, or would you require permission from the account holder?




Just check its existence.
3 years ago
Hi, i'm a Java beginner and currently using a rule in the transfer method that executes a query in the repository, however I am not comfortable mixing query in the code and I would like to know if there is another way to validate what I am doing without using a query. Follow:



My class of service where the transfer method is implemented:

Note: I would like the transfer rule to be validated here.



I don't know how to create this rule so far.

Thanks in advance.
3 years ago

Junilu Lacar wrote:Ok, I mustered up enough courage to wade into that huge lambda expression and here are my first impressions:

1. It does nothing observable. The lists created on lines 5 & 6 are local to the lambda
2. This code could probably benefit from some Rename, Extract, and Compose refactoring.
3. Since you're attempting to test something that doesn't appear to have any externally observable behavior, I doubt that you understand what this piece of code does either. A good understanding of what any piece of code does is an important pre-requisite that's critical to successfully testing it.



So, I managed to create assertions for this case, but NullPointerException is returning me. When debugging, he showed me that the null point is returned on line 3, can you tell me why?
3 years ago
0


I have a DTO class where they have a mapping using functional foreach.

What is the best way to test them?

Follow the method below:



The test case I need is to compare whether the set is the same as the get.

I am new to unit testing and I will be very grateful for your help.
3 years ago

Campbell Ritchie wrote:Welcome to the Ranch

Please always tell us where such questions come from. Apart from the compiler error caused by missing quote marks, what does nda mean? Please avoid unexplained abbreviations. And what do you think the output would be when you correct the quotes? Would the code compile then?





Sorry ... I corrected the quotes.
This is a college question.
The "nda" means nothing to declare or none of the questions is right.

Which of the alternatives is correct.

Can you help me?
4 years ago
Hello,

I'm starting in Java and I'm in doubt on the question below:



a) Hello from do-while
   ----
   Hello from while

b) Hello from do-while
   ----

c) ----
   Hello from while

d) Compilation error: Exception in thread "main" java.lang.Error: Unresolved compilation problems

e) n.d.a


Can you help?
4 years ago