Skip to content

Commit

Permalink
feat(openchallenges): added unit tests to the image service (#2291)
Browse files Browse the repository at this point in the history
* added unit tests for api, model and exception

* update the unit tests

* fix typos in files for unit test

* move folder to correct top folder

* comment out failing test

* remove files

* update istest

* Update label of the Discord button (#2288)

* fix(openchallenges): upgrade legacy components (#2290)

* not-found page: upgrade MatCard

* org-profile page: remove unused tabs component

* github-button: upgrade MatButton

* _app-theme: upgrade legacy; fix fonts

* navbar: upgrade MatButton; fix colors and padding

* fix typography for buttons

* signup page: upgrade components

* add required `mat-label`

* update styles to account for changes

* user-button: upgrade MatButton, MatMenu

* update styles to account for changes

* upgrade component in commented code

* remove dependency on legacy-* in _app-theme

* add typography to discord button; add discord theme

* schematic: remove unused font; upgrade legacies

* fix(openchallenges): remove Sage from sponsor list (#2287)

* remove Sage from sponsor list

* apply section-title styling

* link out to ITCR website

* use more descriptive variable name

* chore(schematic): remove `schematic-app` and `schematic-api-client-angular` (#2293)

* Remove schematic-app and schematic-api-client-angular

* Update `tsconfig.base.json`

* feat(sage-monorepo): enable Format on Save for JSON and JSON with Comments (#2294)

* Format JSON on save

* Enable format on save for jsonc

* hide page size options on search pages (#2298)

* delete

* img hgt exception test

* final image height exception test

* update

* additional variable formatting

* updtate unittest

---------

Co-authored-by: Thomas Schaffter <[email protected]>
Co-authored-by: Verena Chung <[email protected]>
Co-authored-by: Rongrong Chai <[email protected]>
  • Loading branch information
4 people authored Nov 3, 2023
1 parent 6a1c101 commit e2bdab8
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.sagebionetworks.openchallenges.image.service.exception;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class ImageHeightNotSpecifiedExceptionTest {

@Test
public void ImageHeightNotSpecifiedException_ConstructorTypeShouldMatch() {
// Define the exception detail
String detail = "Image height is not specified";

// Create an instance of ImageHeightNotSpecifiedException
ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail);

// Verify the exception details
assertThat(ErrorConstants.IMAGE_HEIGHT_NOT_SPECIFIED.getType()).isEqualTo(exception.getType());
}

@Test
public void ImageHeightNotSpecifiedException_ConstructorTitle_Match() {
// Define the exception detail
String detail = "Image height is not specified";

// Create an instance of ImageHeightNotSpecifiedException
ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail);

// Verify the exception details
assertThat(ErrorConstants.IMAGE_HEIGHT_NOT_SPECIFIED.getTitle())
.isEqualTo(exception.getTitle());
}

@Test
public void ImageHeightNotSpecifiedException_ConstructorStatusMatch() {
// Define the exception detail
String detail = "Image height is not specified";

// Create an instance of ImageHeightNotSpecifiedException
ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail);

// Verify the exception details
assertThat(ErrorConstants.IMAGE_HEIGHT_NOT_SPECIFIED.getStatus())
.isEqualTo(exception.getStatus());
}

@Test
public void ImageHeightNotSpecifiedException_ConstructorDetailMatch() {
// Define the exception detail
String detail = "Image height is not specified";

// Create an instance of ImageHeightNotSpecifiedException
ImageHeightNotSpecifiedException exception = new ImageHeightNotSpecifiedException(detail);

// Verify the exception details
assertThat(exception.getDetail()).isEqualTo(detail);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.sagebionetworks.openchallenges.challenge.service.exception;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.sagebionetworks.openchallenges.image.service.exception.SimpleChallengeGlobalException;
import org.springframework.http.HttpStatus;

public class SimpleChallengeGlobalExceptionTest {

@Test
public void SimpleChallengeGlobalException_ConstructorDetailsShouldMatch() {
// Create an instance of SimpleChallengeGlobalException using the constructor with details
String details = "Something went wrong";
SimpleChallengeGlobalException exception = new SimpleChallengeGlobalException(details);

// Verify the exception details
assertThat(exception.getMessage()).isEqualTo(details);
}

@Test
public void SimpleChallengeGlobalException_ConstructorTypeShouldMatch() {
// Define the exception details
String type = "ExceptionType";
String title = "Exception Title";
HttpStatus status = HttpStatus.BAD_REQUEST;
String detail = "Exception detail message";

// Create an instance of SimpleChallengeGlobalException using the all-args constructor
SimpleChallengeGlobalException exception =
new SimpleChallengeGlobalException(type, title, status, detail);

// Verify the exception details
assertThat(exception.getType()).isEqualTo(type);
}

@Test
public void SimpleChallengeGlobalException_ConstructorTitleShouldMatch() {
// Define the exception details
String type = "ExceptionType";
String title = "Exception Title";
HttpStatus status = HttpStatus.BAD_REQUEST;
String detail = "Exception detail message";

// Create an instance of SimpleChallengeGlobalException using the all-args constructor
SimpleChallengeGlobalException exception =
new SimpleChallengeGlobalException(type, title, status, detail);

// Verify the exception details
assertThat(exception.getTitle()).isEqualTo(title);
}

@Test
public void SimpleChallengeGlobalException_ConstructorStatusShouldMatch() {
// Define the exception details
String type = "ExceptionType";
String title = "Exception Title";
HttpStatus status = HttpStatus.BAD_REQUEST;
String detail = "Exception detail message";

// Create an instance of SimpleChallengeGlobalException using the all-args constructor
SimpleChallengeGlobalException exception =
new SimpleChallengeGlobalException(type, title, status, detail);

// Verify the exception details
assertThat(exception.getStatus()).isEqualTo(status);
}
}

0 comments on commit e2bdab8

Please sign in to comment.