Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Nov 13, 2024
1 parent 754a86e commit 700ee5f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.crowdin.cli.commands.actions;

import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.properties.PropertiesWithFiles;
import com.crowdin.client.applications.installations.model.ApplicationInstallation;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.mockito.Mockito.*;

public class AppListActionTest {

List<ApplicationInstallation> standardList = Arrays.asList(new ApplicationInstallation(), new ApplicationInstallation());
List<ApplicationInstallation> emptyList = Collections.emptyList();

Outputter out = Outputter.getDefault();
PropertiesWithFiles pb;

ProjectClient clientMock = mock(ProjectClient.class);
NewAction<ProjectProperties, ProjectClient> action;

@Test
public void test_standard() {
when(clientMock.listApplications())
.thenReturn(standardList);

action = new AppListAction(false);
action.act(out, pb, clientMock);

verify(clientMock).listApplications();
verifyNoMoreInteractions(clientMock);
}

@Test
public void test_plainView() {
when(clientMock.listApplications())
.thenReturn(standardList);

action = new AppListAction(true);
action.act(out, pb, clientMock);

verify(clientMock).listApplications();
verifyNoMoreInteractions(clientMock);
}

@Test
public void test_emptyList() {
when(clientMock.listApplications())
.thenReturn(emptyList);

action = new AppListAction(false);
action.act(out, pb, clientMock);

verify(clientMock).listApplications();
verifyNoMoreInteractions(clientMock);
}

@Test
public void test_emptyList_plainView() {
when(clientMock.listApplications())
.thenReturn(emptyList);

action = new AppListAction(true);
action.act(out, pb, clientMock);

verify(clientMock).listApplications();
verifyNoMoreInteractions(clientMock);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.crowdin.cli.commands.picocli;

import org.junit.jupiter.api.Test;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.verify;

public class AppListSubcommandTest extends PicocliTestUtils {

@Test
public void testAppList() {
this.execute(CommandNames.APP, CommandNames.LIST);
verify(actionsMock).listApps(anyBoolean());
this.check(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void mockActions() {
.thenReturn(actionMock);
when(actionsMock.branchEdit(any(), any(), any(), any(), anyBoolean(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.listApps(anyBoolean())).thenReturn(actionMock);
}

private void mockBuilders() {
Expand Down

0 comments on commit 700ee5f

Please sign in to comment.