1111import com .crowdin .cli .properties .PropertiesWithFiles ;
1212import com .crowdin .cli .properties .NewPropertiesWithFilesUtilBuilder ;
1313import com .crowdin .cli .utils .Utils ;
14+ import com .crowdin .client .labels .model .Label ;
1415import com .crowdin .client .projectsgroups .model .Type ;
1516import org .junit .jupiter .api .Test ;
1617import org .junit .jupiter .params .ParameterizedTest ;
2223
2324import static org .junit .jupiter .api .Assertions .assertThrows ;
2425import static org .junit .jupiter .params .provider .Arguments .arguments ;
26+ import static org .mockito .ArgumentMatchers .eq ;
2527import static org .mockito .Mockito .mock ;
2628import static org .mockito .Mockito .verify ;
2729import static org .mockito .Mockito .verifyNoMoreInteractions ;
@@ -35,25 +37,25 @@ public class StringListActionTest {
3537
3638 @ ParameterizedTest
3739 @ MethodSource
38- public void testStringList (String file , String filter ) throws ResponseException {
40+ public void testStringList (String file , String filter ) {
3941 NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder
4042 .minimalBuiltPropertiesBean ("*" , Utils .PATH_SEPARATOR + "%original_file_name%-CR-%locale%" )
4143 .setBasePath (Utils .PATH_SEPARATOR );
4244 pb = pbBuilder .build ();
43- CrowdinProjectFull projectFull = ProjectBuilder .emptyProject (Long .parseLong (pb .getProjectId ()))
44- .addFile ("first.csv" , "csv" , 101L , null , null ).build ();
45+ CrowdinProjectFull projectFull = ProjectBuilder .emptyProject (Long .parseLong (pb .getProjectId ())). addBranches ( 3L , "main" )
46+ .addFile ("first.csv" , "csv" , 101L , null , 3L ).build ();
4547 projectFull .setType (Type .FILES_BASED );
46- when (client .downloadFullProject (null ))
48+ when (client .downloadFullProject ("main" ))
4749 .thenReturn (projectFull );
4850 when (client .listSourceString (101L , null , null , filter , null ))
4951 .thenReturn (Arrays .asList (SourceStringBuilder .standard ()
5052 .setProjectId (Long .parseLong (pb .getProjectId ()))
5153 .setIdentifiers (701L , "7-0-1" , "seven-o-one" , "7.0.1" , 101L ).build ()));
5254
53- action = new StringListAction (true , true , file , filter , null , null );
55+ action = new StringListAction (true , true , file , filter , "main" , null , null );
5456 action .act (Outputter .getDefault (), pb , client );
5557
56- verify (client ).downloadFullProject (null );
58+ verify (client ).downloadFullProject (eq ( "main" ) );
5759 verify (client ).listLabels ();
5860 if (file != null ) {
5961 verify (client ).listSourceString (101L , null , null , filter , null );
@@ -80,7 +82,7 @@ public void testGetProjectThrows() throws ResponseException {
8082 when (client .downloadFullProject (null ))
8183 .thenThrow (new RuntimeException ("Whoops" ));
8284
83- action = new StringListAction (true , true , null , null , null , null );
85+ action = new StringListAction (true , true , null , null , null , null , null );
8486 assertThrows (RuntimeException .class , () -> action .act (Outputter .getDefault (), pb , client ));
8587
8688 verify (client ).downloadFullProject (null );
@@ -98,7 +100,7 @@ public void testFileNotExistThrows() throws ResponseException {
98100 .thenReturn (ProjectBuilder .emptyProject (Long .parseLong (pb .getProjectId ()))
99101 .addFile ("first.csv" , "csv" , 101L , null , null ).build ());
100102
101- action = new StringListAction (true , true , "nonexistent.csv" , null , null , null );
103+ action = new StringListAction (true , true , "nonexistent.csv" , null , null , null , null );
102104 assertThrows (RuntimeException .class , () -> action .act (Outputter .getDefault (), pb , client ));
103105
104106 verify (client ).downloadFullProject (null );
@@ -122,12 +124,48 @@ public void testStringList_StringsBasedProject() {
122124 .setProjectId (Long .parseLong (pb .getProjectId ()))
123125 .setIdentifiers (701L , "7-0-1" , "seven-o-one" , "7.0.1" , 101L ).build ()));
124126
125- action = new StringListAction (true , true , null , null , null , null );
127+ action = new StringListAction (true , true , null , null , null , null , null );
126128 action .act (Outputter .getDefault (), pb , client );
127129
128130 verify (client ).downloadFullProject (null );
129131 verify (client ).listLabels ();
130132 verify (client ).listSourceString (null , null , null , null , null );
131133 verifyNoMoreInteractions (client );
132134 }
135+
136+ @ Test
137+ public void testStringListLabels () {
138+ NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder
139+ .minimalBuiltPropertiesBean ("*" , Utils .PATH_SEPARATOR + "%original_file_name%-CR-%locale%" )
140+ .setBasePath (Utils .PATH_SEPARATOR );
141+ pb = pbBuilder .build ();
142+ CrowdinProjectFull projectFull = ProjectBuilder .emptyProject (Long .parseLong (pb .getProjectId ())).addBranches (3L , "main" )
143+ .addFile ("first.csv" , "csv" , 101L , null , null ).build ();
144+ projectFull .setType (Type .FILES_BASED );
145+ Label label1 = new Label () {{
146+ setId (4L );
147+ setTitle ("l1" );
148+ }};
149+ Label label2 = new Label () {{
150+ setId (5L );
151+ setTitle ("l2" );
152+ }};
153+
154+ when (client .downloadFullProject (null ))
155+ .thenReturn (projectFull );
156+ when (client .listSourceString (101L , null , null , null , null ))
157+ .thenReturn (Arrays .asList (SourceStringBuilder .standard ()
158+ .setProjectId (Long .parseLong (pb .getProjectId ()))
159+ .setIdentifiers (701L , "7-0-1" , "seven-o-one" , "7.0.1" , 101L ).build ()));
160+ when (client .listLabels ()).thenReturn (Arrays .asList (label1 , label2 ));
161+
162+ action = new StringListAction (
163+ true , true , "first.csv" , null , null , Arrays .asList ("l1" , "l2" ), null );
164+ action .act (Outputter .getDefault (), pb , client );
165+
166+ verify (client ).downloadFullProject (null );
167+ verify (client ).listLabels ();
168+ verify (client ).listSourceString (101L , null , "4,5" , null , null );
169+ verifyNoMoreInteractions (client );
170+ }
133171}
0 commit comments