Skip to content

Commit

Permalink
formatting and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Sandor committed Dec 26, 2024
1 parent a443264 commit 1caf5c8
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 29 deletions.
6 changes: 3 additions & 3 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ application {
mainClass = 'dev.findfirst.FindFirstApplication'
}

bootRun
{
bootRun
{
String activeProfile = System.properties['spring.profiles.active']
if(activeProfile == null || activeProfile.isBlank()) {
if(activeProfile == null || activeProfile.isBlank()) {
systemProperty "spring.profiles.active", "dev";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public ResponseEntity<BookmarkDTO> addBookmark(@RequestBody AddBkmkReq req)
@PatchMapping("/bookmark")
public ResponseEntity<BookmarkDTO> updateBookmark(
@Valid @RequestBody UpdateBookmarkReq updateBookmarkReq) throws BookmarkNotFoundException {
return new ResponseEntity<>(bookmarkService.updateBookmark(updateBookmarkReq),
HttpStatus.OK);
return new ResponseEntity<>(bookmarkService.updateBookmark(updateBookmarkReq), HttpStatus.OK);
}

@DeleteMapping("/bookmark")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class GlobalExceptionHandler {
protected ResponseEntity<Map<String, String>> handleResponseStatusException(
ResponseStatusException ex) {
// Extract log message
String logMessage =
ex instanceof ErrorResponseException errorResponseException ? errorResponseException.getServerLogMessage()
: ex.getReason();
String logMessage = ex instanceof ErrorResponseException errorResponseException
? errorResponseException.getServerLogMessage()
: ex.getReason();
StackTraceElement[] stackTrace = ex.getStackTrace();
// Get the first relevant stack trace element (usually the point where the exception was thrown)
StackTraceElement origin = stackTrace.length > 0 ? stackTrace[0] : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public BookmarkDTO addBookmark(AddBkmkReq reqBkmk)
var screenshotUrlOpt = Optional.of("");
boolean shouldScrape = reqBkmk.scrapable();

// Can we scrape this?
if (reqBkmk.scrapable()) {
// Can we scrape this?
if (reqBkmk.scrapable()) {
shouldScrape = webCheckService.isScrapable(reqBkmk.url());
}

Expand All @@ -169,9 +169,9 @@ public BookmarkDTO addBookmark(AddBkmkReq reqBkmk)

var savedTags = new HashSet<BookmarkTag>();

var newBkmkJdbc =
new BookmarkJDBC(null, user.getUserId(), new Date(), user.getUsername(), user.getUsername(),
new Date(), title, reqBkmk.url(), screenshotUrlOpt.orElse(""), reqBkmk.scrapable(), savedTags);
var newBkmkJdbc = new BookmarkJDBC(null, user.getUserId(), new Date(), user.getUsername(),
user.getUsername(), new Date(), title, reqBkmk.url(), screenshotUrlOpt.orElse(""),
reqBkmk.scrapable(), savedTags);

var saved = bookmarkJDBCRepository.save(newBkmkJdbc);
for (var tag : tags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Token getPasswordToken(String pwdToken) {

public User getUserFromPasswordToken(String pwdToken) throws NoUserFoundException {
var userId = passwordTokenRepository.findByTokenVal(pwdToken).getUser().getId();
if (userId == null) {
if (userId == null) {
throw new NoUserFoundException();
}
return userRepo.findById(userId).orElseThrow(NoUserFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package dev.findfirst.core.model;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.util.List;

import org.junit.jupiter.api.Test;

class SearchBkmkByTagReqTest {
class SearchBkmkByTagReqTest {

@Test
void tagRequestsEqual() {
assertEquals(new SearchBkmkByTagReq(List.of("tech", "docs")), new SearchBkmkByTagReq(List.of("tech", "docs")));
assertNotEquals(new SearchBkmkByTagReq(List.of("tech", "docs")), new SearchBkmkByTagReq(List.of("tech")));
void tagRequestsEqual() {
assertEquals(new SearchBkmkByTagReq(List.of("tech", "docs")),
new SearchBkmkByTagReq(List.of("tech", "docs")));
assertNotEquals(new SearchBkmkByTagReq(List.of("tech", "docs")),
new SearchBkmkByTagReq(List.of("tech")));
assertNotEquals("String", new SearchBkmkByTagReq(List.of("tech", "docs")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@

import org.junit.jupiter.api.Test;

class SearchBkmkByTitleReqTest {
class SearchBkmkByTitleReqTest {

@Test
void titleRequestsEquality() {
assertEquals(new SearchBkmkByTitleReq(new String[]{"java", "spring"}), new SearchBkmkByTitleReq(new String[]{"java", "spring"}));
assertNotEquals(new SearchBkmkByTitleReq(new String[]{"java", "spring"}), new SearchBkmkByTitleReq(new String[]{"java"}));
assertNotEquals("String", new SearchBkmkByTitleReq(new String[]{"java", "spring"}));
void titleRequestsEquality() {
assertEquals(new SearchBkmkByTitleReq(new String[] {"java", "spring"}),
new SearchBkmkByTitleReq(new String[] {"java", "spring"}));
assertNotEquals(new SearchBkmkByTitleReq(new String[] {"java", "spring"}),
new SearchBkmkByTitleReq(new String[] {"java"}));
assertNotEquals("String", new SearchBkmkByTitleReq(new String[] {"java", "spring"}));
assertNotEquals(null, new SearchBkmkByTitleReq(new String[] {"java", "spring"}));
}

@Test
void hashCodeTest() {
var keywords = new String[]{"java", "spring"};
@Test
void hashCodeTest() {
var keywords = new String[] {"java", "spring"};
var searchReq = new SearchBkmkByTitleReq(keywords);
assertEquals(Arrays.hashCode(keywords), searchReq.hashCode());
}

@Test
void toStringTest() {
var keywords = new String[] {"java", "spring"};
var searchReq = new SearchBkmkByTitleReq(keywords);
assertEquals(Arrays.hashCode(keywords), searchReq.hashCode());
assertEquals(Arrays.toString(keywords), searchReq.toString());

}
}

0 comments on commit 1caf5c8

Please sign in to comment.