Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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
4 votes
Accepted

Spring MVC controller

Is there a nice way to avoid this repetition/boilerplate? Yes, there is a cleaner way. Since you are using Spring, please check the annotation @ControllerAdvice ...
Antot's user avatar
  • 3,657
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
  • 8,927
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
4 votes

Preventing XSS attacks in a Spring MVC application controller

You can use OWASP's ESAPI jar json = ESAPI.encoder().canonicalize(json); json = ESAPI.encoder().encodeForHTML(json); Dependency : ...
vaquar khan's user avatar
3 votes

Transaction in spring boot

You can use Spring data CrudRepository which does a lot of things for you out of the box. Just create an interface and "map" it to the object you want to persist in the database, by writing the class ...
Urosh T.'s user avatar
  • 131
3 votes

Transaction in spring boot

Did you try to use google for this? You have multiple way to do this :P For example: @Transactional annotation on method. Or using XML file to wrap methods with ...
KirkoR's user avatar
  • 133
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
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
  • 266
2 votes
Accepted

Does this unit test cover all edge cases?

As far as I can see the @RequestParam annotation can have a defaultValue parameter - once that's used the method becomes a bit ...
ferada's user avatar
  • 11.1k
2 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,760
2 votes
Accepted

Spring MVC @ControllerAdvice exception handling

Your approach seems well written and structured code-wise. However I feel that there is room to improve the structure of the application and the separation of concerns among the classes thus producing ...
Panayiotis Poularakis's user avatar
2 votes
Accepted

Service Layer in Spring Data

Well if I'd review this I'd add the following: The Id field in Product could be renamed id to follow java convention Generally it's a good practice to have equals & hashcode methods overridden. ...
Mazen Melouk's user avatar
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
  • 4,822
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

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

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,067
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

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
  • 229
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

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

Spring Mvc RESTful app with MySQL

My Suggestions: @Produces can be replaced with produces attribute in @RequestMapping. For example: ...
Rashidi Zin's user avatar
1 vote
Accepted

Spring Mvc RESTful app with MySQL

My suggestions: 1. Documentation: Proper documentation is very helpful for you, the other development team and future developers that will ever work on this code base after you. Even if it's for ...
SSC's user avatar
  • 501
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
  • 131
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

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
  • 113

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