Skip to content

Commit

Permalink
Fix Smell
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed Jan 16, 2024
1 parent 85966c4 commit 0687ffa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/test/java/com/github/brenoepics/at4j/core/AzureApiImplTest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.github.brenoepics.at4j.core;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import com.github.brenoepics.at4j.data.Translation;
import com.github.brenoepics.at4j.data.request.TranslateParams;
import com.github.brenoepics.at4j.data.response.TranslationResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import java.util.Collections;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

class AzureApiImplTest {
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

class AzureApiImplTest<T> {

private AzureApiImpl azureApi;
@Mock
private AzureApiImpl<T> azureApi;
private TranslateParams translateParams;

@BeforeEach
public void setup() {
azureApi = Mockito.mock(AzureApiImpl.class);
translateParams =
new TranslateParams("Hello", Collections.singleton("pt")).setSourceLanguage("en");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import okhttp3.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand Down Expand Up @@ -123,9 +124,15 @@ void handleResponseDoesNotUpdateBucketInformationWhenResponseCodeIs429AndViaHead

@Test
void handleCurrentRequestThrowsException() throws AzureException, IOException {
when(request.executeBlocking()).thenThrow(new RuntimeException());
// Arrange
RuntimeException expectedException = new RuntimeException();
when(request.executeBlocking()).thenThrow(expectedException);

assertThrows(RuntimeException.class, () -> rateLimitManager.handleCurrentRequest(result, request, bucket, System.currentTimeMillis()));
// Act
Executable executable = () -> rateLimitManager.handleCurrentRequest(result, request, bucket, System.currentTimeMillis());

// Assert
assertThrows(RuntimeException.class, executable);
}


Expand Down

0 comments on commit 0687ffa

Please sign in to comment.