Skip to content

Commit

Permalink
style: fix import ordering and other minor checkstyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbalakirev committed Dec 15, 2024
1 parent 137f65f commit 012736a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.corbado.exceptions;

import com.corbado.generated.invoker.ApiException;
import com.google.gson.Gson;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import com.corbado.generated.invoker.ApiException;
import com.google.gson.Gson;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/corbado/sdk/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.lang3.StringUtils;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
* Configuration class for setting up project parameters.
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/corbado/services/SessionService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.corbado.services;

import java.net.MalformedURLException;
import java.net.URL;
import java.security.interfaces.RSAPublicKey;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;

import com.auth0.jwk.InvalidPublicKeyException;
import com.auth0.jwk.Jwk;
import com.auth0.jwk.JwkException;
Expand All @@ -26,10 +19,14 @@
import com.corbado.exceptions.TokenValidationException;
import com.corbado.sdk.Config;
import com.corbado.utils.ValidationUtils;

import java.net.MalformedURLException;
import java.net.URL;
import java.security.interfaces.RSAPublicKey;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
* This class provides functionality for managing sessions, including validation and retrieval of
Expand Down Expand Up @@ -148,7 +145,8 @@ public UserEntity validateToken(final String sessionToken) throws TokenValidatio
final JWTVerifier verifier = JWT.require(algorithm).build();
decodedJwt = verifier.verify(sessionToken);
} catch (final InvalidPublicKeyException e) {
throw new TokenValidationException(ValidationErrorType.CODE_INVALID_PUBLIC_KEY, e.getMessage(), e);
throw new TokenValidationException(
ValidationErrorType.CODE_INVALID_PUBLIC_KEY, e.getMessage(), e);
} catch (final TokenExpiredException e) {
throw new TokenValidationException(ValidationErrorType.CODE_JWT_EXPIRED, e.getMessage(), e);

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/corbado/services/UserService.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.corbado.services;

import java.util.Objects;

import javax.annotation.Nullable;

import com.corbado.entities.UserEntity;
import com.corbado.exceptions.CorbadoServerException;
import com.corbado.generated.api.UsersApi;
import com.corbado.generated.invoker.ApiException;
import com.corbado.generated.model.UserCreateReq;
import com.corbado.generated.model.UserStatus;
import com.corbado.services.base.ApiService;

import java.util.Objects;
import javax.annotation.Nullable;
import lombok.NonNull;

/** Service for managing users. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.corbado.base.AbstractSdkTest;
import com.corbado.exceptions.CorbadoServerException;
import com.corbado.exceptions.StandardException;
Expand All @@ -18,9 +19,9 @@
import com.corbado.services.IdentifierService;
import com.corbado.util.TestUtils;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import lombok.extern.slf4j.Slf4j;

/** The Class UserServiceIT. */
@Slf4j
Expand Down Expand Up @@ -61,7 +62,7 @@ private void assertValidationErrorEquals(
* Sets the up class.
*
* @throws StandardException the standard exception
* @throws CorbadoServerException
* @throws CorbadoServerException the server side error
*/
@BeforeAll
public void setUpClass() throws StandardException, CorbadoServerException {
Expand Down Expand Up @@ -220,7 +221,7 @@ void test_updateIdentifier_ExpectSuccess()
/**
* Test list all emails by user id expect success.
*
* @throws CorbadoServerException
* @throws CorbadoServerException the server side error
*/
@Test
void test_listAllEmailsByUserId_expectSuccess() throws CorbadoServerException {
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/corbado/integration/UserServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.corbado.base.AbstractSdkTest;
import com.corbado.entities.UserEntity;
import com.corbado.exceptions.CorbadoServerException;
Expand Down Expand Up @@ -36,9 +37,9 @@ void test_InstantiateSdk_ExpectNotNull() {
}

/**
* Test case for user creation with validation error. *
* Test case for user creation with validation error.
*
* @throws CorbadoServerException
* @throws CorbadoServerException the standard exception
*/
@Test
void test_UserCreateBlankName_ExpectSuccess() throws CorbadoServerException {
Expand Down Expand Up @@ -72,7 +73,7 @@ void test_UserGet_ExpectNotFound() {
assertThrows(
CorbadoServerException.class,
() -> {
final UserEntity ret = this.fixture.get("usr-1234567890");
this.fixture.get("usr-1234567890");
});
assertNotNull(e);
assertEquals(400, e.getHttpStatusCode());
Expand Down Expand Up @@ -113,7 +114,7 @@ void test_Delete_ExpectUserWillNotBeFound() throws CorbadoServerException, Stand
assertThrows(
CorbadoServerException.class,
() -> {
final UserEntity ret = this.fixture.get(user.getUserID());
this.fixture.get(user.getUserID());
});
assertNotNull(e);
assertEquals(400, e.getHttpStatusCode());
Expand Down
76 changes: 16 additions & 60 deletions src/test/java/com/corbado/unit/SessionServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;

import com.auth0.jwk.Jwk;
import com.auth0.jwk.JwkException;
import com.auth0.jwk.JwkProvider;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.IncorrectClaimException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.corbado.entities.UserEntity;
import com.corbado.enums.exception.ValidationErrorType;
import com.corbado.exceptions.StandardException;
import com.corbado.exceptions.TokenValidationException;
import com.corbado.services.SessionService;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
Expand All @@ -24,7 +40,6 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -36,23 +51,6 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import com.auth0.jwk.Jwk;
import com.auth0.jwk.JwkException;
import com.auth0.jwk.JwkProvider;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.IncorrectClaimException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.corbado.entities.UserEntity;
import com.corbado.enums.exception.ValidationErrorType;
import com.corbado.exceptions.StandardException;
import com.corbado.exceptions.TokenValidationException;
import com.corbado.services.SessionService;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;

/** Unit Test for session service. */
@ExtendWith(MockitoExtension.class)
public class SessionServiceTest {
Expand Down Expand Up @@ -205,11 +203,6 @@ void test_getCurrentUser(
assertEquals(TEST_NAME, validationResult.getFullName());
assertEquals(TEST_USER_ID, validationResult.getUserID());
}
/**
* Inits the parameters test data.
*
* @return the stream
*/
}

// ------------------ Test data --------------------- //
Expand All @@ -227,13 +220,6 @@ static Stream<Object[]> initParametersTestData() {
new Object[] {"", "2", false},
// Test empty jwks_uri
new Object[] {"s", "", false});
/**
* Provide jwts.
*
* @return the list
* @throws InvalidKeySpecException the invalid key spec exception
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
}

/**
Expand Down Expand Up @@ -366,15 +352,6 @@ static List<Object[]> provideJwts() throws InvalidKeySpecException, NoSuchAlgori
});

return testData;
/**
* Read private key.
*
* @param privateKeyPath the private key path
* @return the RSA private key
* @throws IOException Signals that an I/O exception has occurred.
* @throws NoSuchAlgorithmException the no such algorithm exception
* @throws InvalidKeySpecException the invalid key spec exception
*/
}

// ------------------ Utility functions--------------------- //
Expand Down Expand Up @@ -402,16 +379,6 @@ private static RSAPrivateKey readPrivateKey(final String privateKeyPath)
final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
return (RSAPrivateKey) keyFactory.generatePrivate(keySpec);
/**
* Generate jwt.
*
* @param iss the iss
* @param exp the exp
* @param nbf the nbf
* @return the string
* @throws InvalidKeySpecException the invalid key spec exception
* @throws NoSuchAlgorithmException the no such algorithm exception
*/
}

/**
Expand Down Expand Up @@ -440,11 +407,6 @@ private static String generateJwt(
.withClaim("email", TEST_EMAIL)
.withClaim("phone_number", TEST_PHONE_NUMBER)
.sign(algorithm);
/**
* Creates the session service.
*
* @return the session service
*/
}

/**
Expand All @@ -458,12 +420,6 @@ private static SessionService createSessionService() {
10,
false,
TEST_PROJECT_ID); // URLs do not matter, url access is mocked
/**
* Read jwks.
*
* @return the json array
* @throws FileNotFoundException the file not found exception
*/
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/test/java/com/corbado/util/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.corbado.util;

import java.util.Random;

import org.apache.commons.lang3.StringUtils;

import com.corbado.entities.UserEntity;
import com.corbado.exceptions.CorbadoServerException;
import com.corbado.exceptions.StandardException;
import com.corbado.generated.model.UserCreateReq;
import com.corbado.generated.model.UserStatus;
import com.corbado.sdk.Config;
import com.corbado.sdk.CorbadoSdk;

import io.github.cdimascio.dotenv.Dotenv;
import java.util.Random;
import org.apache.commons.lang3.StringUtils;

/** The Class TestUtils. */
public class TestUtils {
Expand Down

0 comments on commit 012736a

Please sign in to comment.