Skip to main content
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 ...
Timothy Truckle's user avatar
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 ...
Manuel's user avatar
  • 311
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 ...
gtiwari333's user avatar
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 ...
Alexander Ivanchenko's user avatar
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 ...
l0b0's user avatar
  • 9,117
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 ...
xpmatteo's user avatar
  • 276
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 ...
TorbenPutkonen's user avatar
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 ...
Shen's user avatar
  • 31
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 ...
i.bondarenko's user avatar
3 votes

Spring MVC dynamically adding form elements

Use interface List instead of concrete class for the fieldArrayList field. Make the ...
Ilya Lysenko's user avatar
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 ...
JvR's user avatar
  • 2,820
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 ...
Sergii Nevydanchuk's user avatar
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: ...
MadJlzz's user avatar
  • 123
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 ...
mtj's user avatar
  • 5,002
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 ...
Chris Cooper's user avatar
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 ...
H3AR7B3A7's user avatar
  • 239
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 ...
Harry Coder's user avatar
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 ...
gervais.b's user avatar
  • 2,147
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: ...
TorbenPutkonen's user avatar
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 ...
Miguel Alorda's user avatar
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 ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
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);
Pitto's user avatar
  • 829
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 ...
gervais.b's user avatar
  • 2,147
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 ...
sidgate's user avatar
  • 141
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). ...
Ankit Soni's user avatar
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 ...
Serhat Oz's user avatar
  • 126
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 ...
gervais.b's user avatar
  • 2,147
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 ...
steve wang's user avatar
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 ...
mtj's user avatar
  • 5,002
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 ...
Sardor Navruzov's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible