-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for DistributionReleaseAction (#662)
- Loading branch information
1 parent
3da23ec
commit f2852d3
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/test/java/com/crowdin/cli/commands/actions/DistributionReleaseActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.crowdin.cli.commands.actions; | ||
|
||
import com.crowdin.cli.client.ClientDistribution; | ||
import com.crowdin.cli.commands.NewAction; | ||
import com.crowdin.cli.commands.Outputter; | ||
import com.crowdin.cli.properties.NewPropertiesWithFilesUtilBuilder; | ||
import com.crowdin.cli.properties.ProjectProperties; | ||
import com.crowdin.cli.properties.PropertiesWithFiles; | ||
import com.crowdin.cli.utils.Utils; | ||
import com.crowdin.client.distributions.model.DistributionRelease; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class DistributionReleaseActionTest { | ||
private final static String HASH = "distribution"; | ||
private NewAction<ProjectProperties, ClientDistribution> action; | ||
|
||
@Test | ||
public void releaseDistributionTest_whenSuccess() { | ||
NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder | ||
.minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") | ||
.setBasePath(Utils.PATH_SEPARATOR); | ||
PropertiesWithFiles pb = pbBuilder.build(); | ||
ClientDistribution client = mock(ClientDistribution.class); | ||
DistributionRelease distributionRelease = new DistributionRelease(); | ||
distributionRelease.setStatus("success"); | ||
when(client.release(HASH)).thenReturn(distributionRelease); | ||
|
||
action = new DistributionReleaseAction(true, true, HASH); | ||
action.act(Outputter.getDefault(), pb, client); | ||
verify(client).release(HASH); | ||
} | ||
|
||
@Test | ||
public void releaseDistributionTest_whenFailed() { | ||
NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder | ||
.minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") | ||
.setBasePath(Utils.PATH_SEPARATOR); | ||
PropertiesWithFiles pb = pbBuilder.build(); | ||
ClientDistribution client = mock(ClientDistribution.class); | ||
DistributionRelease distributionRelease = new DistributionRelease(); | ||
distributionRelease.setStatus("failed"); | ||
when(client.release(any())).thenReturn(distributionRelease); | ||
when(client.getDistributionRelease(eq(HASH))).thenReturn(distributionRelease); | ||
|
||
action = new DistributionReleaseAction(true, true, HASH); | ||
assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); | ||
verify(client).release(HASH); | ||
verify(client).getDistributionRelease(HASH); | ||
} | ||
} |