Skip to content

Commit

Permalink
Use junit4 for parameterized tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkins committed Dec 20, 2023
1 parent 85fed85 commit 4870f74
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 90 deletions.
6 changes: 0 additions & 6 deletions ctera/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
<artifactId>joda-time</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ch.cyberduck.core.ctera;/*
* Copyright (c) 2002-2023 iterate GmbH. All rights reserved.
* https://cyberduck.io/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

import ch.cyberduck.core.Acl;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;

import java.util.Arrays;
import java.util.Collection;

import static ch.cyberduck.core.ctera.CteraCustomACL.*;
import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class CteraPermissionFeatureAclToPermissionTest {
@Parameterized.Parameters(name = "{0} {1} {2} {3}")
public static Collection<Object[]> data() {

return Arrays.asList(
new Object[][]{
{Acl.EMPTY, true, true, true},
{new Acl(new Acl.CanonicalUser(), writepermission), false, true, false},
{new Acl(new Acl.CanonicalUser(), readpermission), true, false, false},
{new Acl(new Acl.CanonicalUser(), executepermission), false, false, true},
{new Acl(new Acl.CanonicalUser(), deletepermission), false, false, false},
{new Acl(new Acl.CanonicalUser(), traversepermission), false, false, true},
{new Acl(new Acl.CanonicalUser(), Createfilepermission), false, false, false},
{new Acl(new Acl.CanonicalUser(), CreateDirectoriespermission), false, false, false}
}
);
}

@Parameter
public Acl acl;

@Parameter(1)
public boolean r;

@Parameter(2)
public boolean w;

@Parameter(3)
public boolean x;


@Test
public void testAclToPermission() {
assertEquals(r, aclToPermission(acl).isReadable());
assertEquals(w, aclToPermission(acl).isWritable());
assertEquals(x, aclToPermission(acl).isExecutable());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2023 iterate GmbH. All rights reserved.
*/

package ch.cyberduck.core.ctera;

import ch.cyberduck.core.Acl;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;

import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static ch.cyberduck.core.ctera.CteraCustomACL.*;
import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
class CteraPermissionFeatureCustomPropsToAclTest {

@Parameterized.Parameters(name = "{0} {1}")
public static Collection<Object[]> data() {

return Arrays.asList(
new Object[][]{
{Collections.emptyMap(), Acl.EMPTY},
{
(Map<String, String>) Stream.of(
new AbstractMap.SimpleEntry<>(readpermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(writepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(executepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(deletepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(traversepermission.getName(), "true"),
new AbstractMap.SimpleEntry<>(Createfilepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(CreateDirectoriespermission.getName(), "false")
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
new Acl(new Acl.CanonicalUser(), traversepermission)
},
{
(Map<String, String>) Stream.of(
new AbstractMap.SimpleEntry<>(readpermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(writepermission.getName(), "true"),
new AbstractMap.SimpleEntry<>(executepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(deletepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(traversepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(Createfilepermission.getName(), "false"),
new AbstractMap.SimpleEntry<>(CreateDirectoriespermission.getName(), "true")
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)),
new Acl(new Acl.CanonicalUser(), writepermission, CreateDirectoriespermission)
}
}
);
}

@Parameter
public Map<String, String> map;

@Parameter(1)
public Acl expected;


public void testCustomPropsToAcl(final Map<String, String> map, final Acl expected) {
assertEquals(expected, customPropsToAcl(map));

}
}

0 comments on commit 4870f74

Please sign in to comment.