18
votes
Accepted
Unit testing Video Service class
Welcome to code review and thanks for sharing your code.
When writing UnitTests keep in mind that they are documentation.
Test code has less restrictions for identifier names.
This means that method ...
8
votes
Unit testing Video Service class
The idea of the test class is ok: you want to test the service, mock the repository and you check on the outcome.
In the test, it would be nice to use the AAA (arrange/act/assert) pattern. In my ...
7
votes
Accepted
Stack Overflow clone
General Feedback
the package 'StackCanary' can follow Java standard naming. Ref: https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
You do not need to type Tag on ...
5
votes
Springboot - Authentication Service
SRP violation
Low-level logic for creating and persisting sessions, creating Profiles, generating IDs does not belong to this Service.
Spring Security
Consider ...
4
votes
Unit testing Video Service class
Some notes:
If you're using mocks you are pretty much by definition doing integration rather than unit testing, because mocks enable you to test how a piece of code integrates with something else ...
4
votes
Accepted
In Spring framework, should the controller let the client know that something went wrong by returning a response entity with the proper error code?
It depends on your context, but generally speaking it's good to return as much information as you can about the error to your caller. Unless it discloses security information (e.g., avoid returning ...
4
votes
Accepted
Return a 404 when a resource is not found in Spring Boot
Your URL path isn't very RESTlike. You have built the URL to describe an operation when a more common approach is to build the URL to describe a resource.
So instead of ...
3
votes
Springboot - Authentication Service
For a "fresher" it looks pretty good so far. Good method names, exception handling, and overall design choice.
The first thing improvement I noticed was some code was duplicated and could be ...
3
votes
Simple Banking application in Spring boot, JPA, REST where balance can be transferred among predefined accounts and transaction history retrievable
Your implementation is good. I would suggest following points to improve:
Use @GetMapping, @PostMapping and the others instead ...
3
votes
Spring MVC dynamically adding form elements
Use interface List instead of concrete class for the fieldArrayList
field.
Make the ...
3
votes
Throw exception in Spring when loading a file
My first idea was to load the file in the constructor of the class, but I do not know if that is a good practice for Spring.
It takes the lazy-loading out of the lazy-loader, but then you could ask ...
2
votes
Accepted
Spring Boot RESTful service as a backend and reactjs as frontend app
Ok, I think you move for nice code, but I would go for simplicity.
Create a simple Spring Web MVC application and manage dependencies through Maven.
I would go for spring boot - its much less ...
2
votes
CSV file download in Spring
First of all, please don't take what I am writting personnaly. Also, I am sure there would be something to argue with my proposals so feel free to tell me!
Let's begin with:
...
2
votes
Spring: Creating a Mutable Common Command Object or Controller Interceptor
I don't like the idea of modeling a common set of properties (or as you say "... for just about every API call..." probably a mostly common set of properties) as a superclass. IMO inheritance should ...
2
votes
Unit testing Video Service class
Testing strategy seems like it might be a bit out of scope for Code Review, but having historically also found this process a bit confusing, my suggestion would be to not explicitly test your ...
2
votes
A controller for a Game Service
I like to work with the request specific annotation. Also, you don't need @RequestMapping, unless you want to version your API with URL versioning or have some ...
2
votes
Spring boot: better way to handle response and exceptions
As you are using Spring Boot, the best way to handle you response is to add a RestControllerAdvice.
A few rules to follow :
Create custom ...
2
votes
Microservice in Springboot
Actually I did not reviewed your code as such (as warned by @Emma). But for an "architectural" perspective I see some improvements. However some are more personal guts than real good ...
2
votes
Using Factory Design Pattern in Rest Controller of Spring
If you are free to change the request mappings, you should make the distinguishion between "manga" and "conga" in a more restful manner by using the @PathVariable annotation:
...
1
vote
Accepted
Using Factory Design Pattern in Rest Controller of Spring
Welcome to CodeReview.
By the code you have shown, using the factory pattern may be overengineering. Unless you plan on adding more services, just use the ...
1
vote
Stack Overflow clone
I haven't done much Java development since I was a univeristy student 15 years ago so my assistance there will be limited. The bulk of this review will be on the JavaScript code.
Java
Comments
...
1
vote
Return a 404 when a resource is not found in Spring Boot
As often happens after sleeping on it I had a better solution:
.orElseThrow(ResourceNotFoundException::new);
1
vote
Accepted
Spring MVC login controller
The switch has a bad reputation and is usually seen as a code smell.
In your case, I would first propose to replace the strings by one enum so that you have ...
1
vote
Effective & Secure Method to populate Access Token for authorization header in Rest Template
You can have an interceptor on RestTemplate. It will be called for each request. You can have the access token logic within the ...
1
vote
Accepted
Spring Boot methods to add and remove relationships
You may extract the action part as a method parameter (I am using BiConsumer in this case).
...
1
vote
Accepted
Reporting sums of shopping carts
First of all i think making a view in your database which sums your needs will be better because generally sql engine sum operator's performance is way better than lopping values in programming ...
1
vote
Accepted
Refactor REST service with overcomplicated logic
Thanks for the classes. However I did not wait for them and just created some "stubs". Here is my answer:
When you have "a huge amount of nested logic" you should try to extract and distribute it ...
1
vote
Refactoring a class / map of query parameters that are passed between layers
It's cleaner and possible to create types of Parameter class, such as CarParameter, MotoParameter, and use Spring type conversion.
First your signature would become something like
...
1
vote
Maintaining session timeout globally in java spring configuration
Quite a number of points for this short piece of code:
As the properties file will probably not change at runtime, loading it every single time a session gets created is a total waste. See whether you ...
1
vote
Inserting 100000 records to MySQL takes too much time
Using batch-inserting is one of the methods to decrease a saving time, but still not enough to handle 100k records in 5 or less seconds due to ORM internal mechanism. I suggest you to look into your ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
spring-mvc × 37java × 36
spring × 24
rest × 7
error-handling × 5
javascript × 3
security × 3
mysql × 2
controller × 2
hibernate × 2
groovy × 2
jpa × 2
performance × 1
object-oriented × 1
jquery × 1
html × 1
sql × 1
design-patterns × 1
datetime × 1
unit-testing × 1
css × 1
comparative-review × 1
csv × 1
api × 1
react.js × 1