Java 类org.junit.jupiter.params.provider.CsvSource 实例源码

项目:shuffleboard    文件:NetworkTableUtilsTest.java   
@ParameterizedTest
@CsvSource({"false, /key",
               "false, /metadata",
               "false, /~metadata",
               "false, /metadata~",
               "true, /~metadata~",
               "false, /METADATA",
               "false, /~METADATA",
               "false, /METADATA~",
               "true, /~METADATA~",
               "true, /.metadata",
               "true, /~METADATA~/someOtherValue",
               "true, /.metadata/someOtherValue",
               "false, /my.key.with.dots",
               "false, /my~key~with~tildes~",
               "false, /~my~keywithtildes",
               "false, /~metadata~with~tildes~"})
public void isMetaDataTest(boolean expectedResult, String key) {
  assertEquals(expectedResult, NetworkTableUtils.isMetadata(key));
}
项目:pbt-junit-quickcheck    文件:PrimeFactorCalculatorShould.java   
@ParameterizedTest(name = "{0} should be prime? {1}")
@CsvSource({
        "1, false",
        "2, true",
        "3, true",
        "4, false",
        "5, true",
        "6, false",
        "7, true",
        "8, false",
        "9, false",
        "10, false",
        "2147483647, true" })
public void findPrimeNumbers(long n, boolean isPrime)
{
    assertThat(sut.isPrime(n)).isEqualTo(isPrime);
}
项目:Karus-Commons    文件:TaskTest.java   
@ParameterizedTest
@CsvSource({"true, true, true, 1, 1, 0", "true, true, false, 1, 0, 0", "true, false, true, 0, 0, 1", "false, true, true, 0, 0, 1"})
void process(boolean origin, boolean target, boolean orientate, int times, int orientateTimes, int done) {
    doNothing().when(task).orientate();
    doNothing().when(task).render();
    doReturn(origin).when(this.origin).validate();
    doReturn(target).when(this.target).validate();

    task.orientate = orientate;

    task.process();

    verify(this.origin, times(times)).update();
    verify(this.target, times(times)).update();
    verify(task, times(orientateTimes)).orientate();
    verify(task, times(times)).render();
    verify(runnable, times(done)).run();
}
项目:Karus-Commons    文件:WaveTest.java   
@ParameterizedTest
@CsvSource({"1, 0", "0, 1"})
void render(int steps, int times) {
    context.steps = steps;
    doNothing().when(wave).process(origin);

    Vector water = new Vector(0, 0, 1);
    Vector cloud = new Vector(0, 0, 2);

    wave.waters.add(water);
    wave.clouds.add(cloud);


    wave.render(context, origin, target, offset);

    verify(wave, times(times)).process(origin);
    verify(context).render(PARTICLES, origin, water);
    verify(context).render(COLOURED, origin, cloud);
}
项目:keystore-explorer    文件:VersionTest.java   
@ParameterizedTest
@CsvSource({
    "01,        1, 0, 0",
    "1,         1, 0, 0",
    "1.0,       1, 0, 0",
    "1.0.0,     1, 0, 0",
    "1.2,       1, 2, 0",
    "1.2.3,     1, 2, 3",
    "1.2.3,     1, 2, 3",
    "1.2.3.4,   1, 2, 3",
})
public void testMajorMinorVersion(String versionString, int major, int minor, int bugfix) {
    assertEquals(major, new Version(versionString).getMajor());
    assertEquals(minor, new Version(versionString).getMinor());
    assertEquals(bugfix, new Version(versionString).getBugfix());
}
项目:keystore-explorer    文件:VersionTest.java   
@ParameterizedTest
@CsvSource({
    "01,        1,      0",
    "1,         1,      0",
    "1.0,       1,      0",
    "1.0.0,     1,      0",
    "1.0,       1.0,    0",
    "1.0.0,     1.0.0,  0",
    "1.2,       1,      1",
    "1.2,       1.3,    -1",
    "1.2.3,     1,      1",
    "1.2.3.4,   1,      1",
    "1.3.1,     1.3,    1",
    "1.2.3,     1.3,    -1",
    "1.2.3.4,   1.3,    -1",
    "1.3.1,     1.3.2,  -1",
    "1.3.2,     1.3.2.1,-1",
    "9.9.9.9,   10.0.0, -1",
    "9.20.20,   10.0.0, -1",
})
public void testCompare(String version1, String version2, int resultSignum) {
    assertEquals(Integer.signum(new Version(version1).compareTo(new Version(version2))), resultSignum);
}
项目:keystore-explorer    文件:JavaVersionTest.java   
@ParameterizedTest
@CsvSource({
    "JRE_VERSION_9,   JRE_VERSION_160, true",
    "JRE_VERSION_9,   JRE_VERSION_170, true",
    "JRE_VERSION_9,   JRE_VERSION_180, true",
    "JRE_VERSION_9,   JRE_VERSION_9,   true",
    "JRE_VERSION_180, JRE_VERSION_160, true",
    "JRE_VERSION_180, JRE_VERSION_170, true",
    "JRE_VERSION_180, JRE_VERSION_180, true",
    "JRE_VERSION_170, JRE_VERSION_160, true",
    "JRE_VERSION_170, JRE_VERSION_170, true",
    "JRE_VERSION_180, JRE_VERSION_9,   false",
    "JRE_VERSION_170, JRE_VERSION_180, false",
    "JRE_VERSION_170, JRE_VERSION_9,   false",
})
public void isAtLeast(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version1,
        @ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version2, boolean result) {
    assertEquals(version1.isAtLeast(version2), result);
}
项目:keystore-explorer    文件:JavaVersionTest.java   
@ParameterizedTest
@CsvSource({
    "JRE_VERSION_160, JRE_VERSION_170, true",
    "JRE_VERSION_170, JRE_VERSION_180, true",
    "JRE_VERSION_180, JRE_VERSION_9,   true",
    "JRE_VERSION_9,   JRE_VERSION_180, false",
    "JRE_VERSION_170, JRE_VERSION_160, false",
    "JRE_VERSION_170, JRE_VERSION_170, false",
    "JRE_VERSION_180, JRE_VERSION_160, false",
    "JRE_VERSION_180, JRE_VERSION_170, false",
    "JRE_VERSION_180, JRE_VERSION_180, false",
})
public void isBelow(@ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version1,
        @ConvertWith(JavaVersionConstantArgumentConverter.class) JavaVersion version2, boolean result) {
    assertEquals(version1.isBelow(version2), result);
}
项目:keystore-explorer    文件:SpkacTest.java   
@ParameterizedTest
@CsvSource({
    "MD2_RSA",
    "MD5_RSA",
    "RIPEMD128_RSA",
    "RIPEMD160_RSA",
    "RIPEMD256_RSA",
    "SHA1_RSA",
    "SHA224_RSA",
    "SHA256_RSA",
    "SHA384_RSA",
    "SHA512_RSA",
    "SHA1_DSA",
    "SHA224_DSA",
    "SHA256_DSA",
})
public void ripemd160RsaSpkac(SignatureType signatureAlgorithm) throws Exception {

    if (signatureAlgorithm.name().endsWith("_RSA")) {
        doTestSpkac(rsaKeyPair, signatureAlgorithm);
    } else {
        doTestSpkac(dsaKeyPair, signatureAlgorithm);
    }
}
项目:keystore-explorer    文件:DigestUtilTest.java   
@ParameterizedTest
@CsvSource({
    "MD2",
    "MD4",
    "MD5",
    "SHA1",
    "SHA224",
    "SHA256",
    "SHA384",
    "SHA512",
    "RIPEMD128",
    "RIPEMD160",
    "RIPEMD256",
})
public void testMessageDigests(DigestType digestType) throws Exception {
    String digest = DigestUtil.getFriendlyMessageDigest(MESSAGE.getBytes(), digestType);
    assertTrue(!digest.equals(MESSAGE));
}
项目:keystore-explorer    文件:KeyPairUtilTest.java   
@ParameterizedTest
@CsvSource({
    "DSA, 512",
    "DSA, 1024",
    "RSA, 512",
    "RSA, 1024",
    "RSA, 2048",
    //"RSA, 3072", takes too long
    //"RSA, 4096", takes too long
})
public void doTests(KeyPairType keyPairType, Integer keySize) throws Exception {
    KeyPair keyPair = KeyPairUtil.generateKeyPair(keyPairType, keySize, new BouncyCastleProvider());

    PrivateKey privateKey = keyPair.getPrivate();
    KeyInfo privateKeyInfo = KeyPairUtil.getKeyInfo(privateKey);
    assertEquals(keyPairType.toString(), privateKeyInfo.getAlgorithm());
    assertEquals(keySize, privateKeyInfo.getSize());

    PublicKey publicKey = keyPair.getPublic();
    KeyInfo publicKeyInfo = KeyPairUtil.getKeyInfo(publicKey);
    assertEquals(keyPairType.toString(), publicKeyInfo.getAlgorithm());
    assertEquals(keySize, publicKeyInfo.getSize());

    assertTrue(KeyPairUtil.validKeyPair(privateKey, publicKey));
}
项目:mastering-junit5    文件:CustomNamesParameterizedTest.java   
@DisplayName("Display name of test container")
@ParameterizedTest(name = "[{index}] first argument=\"{0}\", second argument={1}")
@CsvSource({ "mastering, 1", "parameterized, 2", "tests, 3" })
void testWithCustomDisplayNames(String first, int second) {
    System.out.println(
            "Testing with parameters: " + first + " and " + second);
}
项目:mastering-junit5    文件:CsvSourceParameterizedTest.java   
@ParameterizedTest
@CsvSource({ "hello, 1", "world, 2", "'happy, testing', 3" })
void testWithCsvSource(String first, int second) {
    System.out.println("Parameterized test with (String) " + first
            + " and (int) " + second);

    assertNotNull(first);
    assertNotEquals(0, second);
}
项目:traute    文件:LoggingTest.java   
@ParameterizedTest
@CsvSource(value = { "true", "false" })
public void verboseMode_instrumentation(boolean verbose) {
    settingsBuilder.withVerboseMode(verbose);
    String testSource = String.format(
            "package %s;\n" +
            "\n" +
            "import %s;\n" +
            "\n" +
            "public class %s {\n" +
            "\n" +
            "  @NotNull\n" +
            "  public Integer test(@NotNull Integer i1, @NotNull Integer i2) {\n" +
            "    return i1 + i2;\n" +
            "  }\n" +
            "\n" +
            "  @NotNull\n" +
            "  private Integer negative(@NotNull Integer i) {\n" +
            "      return -1 * i;\n" +
            "  }\n" +
            "\n" +
            "  public static void main(String[] args) {\n" +
            "    new Test().test(1, 2);\n" +
            "  }\n" +
            "}", PACKAGE, NotNull.class.getName(), CLASS_NAME);

    String[] targetParameterNames = {"i1", "i2", "i"};
    for (String name : targetParameterNames) {
        expectCompilationResult.withText(String.format("added a null-check for argument '%s'", name), verbose);
    }

    String methodPrefix = PACKAGE + "." + CLASS_NAME + ".";
    String[] targetMethods = {methodPrefix + "test()", methodPrefix + "negative()"};
    for (String method : targetMethods) {
        expectCompilationResult.withText("added a null-check for 'return' expression in method " + method,
                                         verbose);
    }

    doTest(testSource);
}
项目:traute    文件:MethodParameterTest.java   
@ParameterizedTest
@CsvSource(delimiter = ':', value = {
        "null, 1:i1:0", "1, null:i2:0"
})
public void multipleArguments(@NotNull String callArguments, @NotNull String parameterName) {
    String testSource = prepareParameterTestSource(
            NotNull.class.getName(),
            String.format("public void %s(@NotNull Integer i1,\n                   @NotNull Integer i2) {}",
                          METHOD_NAME),
            callArguments
    );
    expectNpeFromParameterCheck(testSource, parameterName, expectRunResult);
    doTest(testSource);
}
项目:shuffleboard    文件:NumberFieldTest.java   
@ParameterizedTest
@CsvSource({"0.0, a0.0",
               "0.0, 0.0b",
               "0.0, a0.0b",
               "0.0, 0.......0",
               "0.0, 0.0."})
public void invalidNumberTest(String expectedResult, String test) {
  interact(numberField::clear);
  clickOn(".text-field").write(test);

  assertEquals(expectedResult, numberField.getText());
}
项目:selenium-jupiter    文件:SelenoidConfigTest.java   
@ParameterizedTest
@CsvSource({ "3.6, 4.0, 47.0", "46.0, 47.0, 47.0", "46, 47.0, 47" })
void testNextVersion(String version, String expectedNextVersion,
        String latestVersion) {
    String nextVersion = CHROME.getNextVersion(version, latestVersion);
    assertThat(nextVersion, equalTo(expectedNextVersion));
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:CustomNamesParameterizedTest.java   
@DisplayName("Display name of test container")
@ParameterizedTest(name = "[{index}] first argument=\"{0}\", second argument={1}")
@CsvSource({ "mastering, 1", "parameterized, 2", "tests, 3" })
void testWithCustomDisplayNames(String first, int second) {
    System.out.println(
            "Testing with parameters: " + first + " and " + second);
}
项目:Mastering-Software-Testing-with-JUnit-5    文件:CsvSourceParameterizedTest.java   
@ParameterizedTest
@CsvSource({ "hello, 1", "world, 2", "'happy, testing', 3" })
void testWithCsvSource(String first, int second) {
    System.out.println("Parameterized test with (String) " + first
            + " and (int) " + second);

    assertNotNull(first);
    assertNotEquals(0, second);
}
项目:pbt-junit-quickcheck    文件:PrimeFactorCalculatorShould.java   
@ParameterizedTest(name = "{0} should be factored as [{1}]")
@CsvSource({
        "2, 2",
        "3, 3",
        "4, 2;2",
        "5, 5" })
public void factorSmallNumbers(final long n, final String factors)
{
    assertThat(sut.factor(n)).isEqualTo(split(factors));
}
项目:Karus-Commons    文件:EntityLocationTest.java   
@ParameterizedTest
@CsvSource({"true, true, true", "true, false, true", "false, true, true", "false, false, false"})
void validate(boolean nullable, boolean present, boolean expected) {
    location.nullable = nullable;
    location.entity = present ? location.entity : new Weak<>(null);

    assertEquals(expected, location.validate());
}
项目:Karus-Commons    文件:LivingEntityLocationTest.java   
@ParameterizedTest
@CsvSource({"true, 1", "false, 0"})
void update(boolean present, int times) {
    location.entity = present ? location.entity : new Weak<>(null);
    doNothing().when(location).update(any(Location.class));

    location.update();

    verify(location, times(times)).update(any(Location.class));
}
项目:Karus-Commons    文件:StaticLocationTest.java   
@ParameterizedTest
@CsvSource({"true", "false"})
void updateOffset(boolean relative) {
    location.setRelative(relative);

    location.updateOffset();

    verify(internal).add(relative ? Vectors.rotate(offset, internal) : offset);
}
项目:Karus-Commons    文件:BoundLocationTest.java   
@ParameterizedTest
@CsvSource({"true, 5, 7", "false, 4, 5"})
void updateDirection(boolean relative, float yaw, float pitch) {
    bound.setRelative(relative);

    bound.updateDirection();

    verify(location).setYaw(yaw);
    verify(location).setPitch(pitch);
}
项目:Karus-Commons    文件:SingletonTest.java   
@ParameterizedTest
@CsvSource({"10, 1", "5, 0"})
void click(int slot, int times) {
    ClickEvent event = when(mock(ClickEvent.class).getRawSlot()).thenReturn(slot).getMock();

    region.click(event);

    verify(button, times(times)).click(event);
}
项目:Karus-Commons    文件:SingletonTest.java   
@ParameterizedTest
@CsvSource({"false, 10, 1", "true, 10, 0", "false, 5, 0"})
void drag(boolean cancelled, int slot, int times) {
    DragEvent event = when(mock(DragEvent.class).isCancelled()).thenReturn(cancelled).getMock();
    when(event.getRawSlots()).thenReturn(Collections.singleton(slot));

    region.drag(event);

    verify(button, times(times)).drag(event, 10);
}
项目:Karus-Commons    文件:AbstractRegionTest.java   
@ParameterizedTest
@CsvSource({"0, 0, 0", "10, 1, 0", "9, 0, 1"})
void click(int slot, int times, int blank) {
    ClickEvent event = when(mock(ClickEvent.class).getRawSlot()).thenReturn(slot).getMock();

    region.click(event);

    verify(button, times(times)).click(event);
    verify(region, times(blank)).clickBlank(event);
}
项目:Karus-Commons    文件:AbstractRegionTest.java   
@ParameterizedTest
@CsvSource({"10, true, 0, 0", "0, false, 0, 0", "10, false, 1, 0", "9, false, 0, 1"})
void drag(int slot, boolean cancelled, int times, int blank) {
    DragEvent event = when(mock(DragEvent.class).getRawSlots()).thenReturn(singleton(slot)).getMock();
    when(event.isCancelled()).thenReturn(cancelled).getMock();

    region.drag(event);

    verify(button, times(times)).drag(event, slot);
    verify(region, times(blank)).dragBlank(event, slot);
}
项目:Karus-Commons    文件:CheckBoxTest.java   
@ParameterizedTest
@CsvSource({"true, 0, 1", "false, 1, 0"})
void click(boolean checked, int check, int uncheck) {
    checkbox.checked = checked;

    ClickEvent event = mock(ClickEvent.class);

    checkbox.click(event);

    verify(checkbox, times(check)).check(event);
    verify(checkbox, times(uncheck)).uncheck(event);
    assertEquals(!checked, checkbox.checked);
}
项目:Karus-Commons    文件:CyclicButtonTest.java   
@ParameterizedTest
@CsvSource({"1, c, 2", "2, a, 0"})
void next(int index, String state, int expected) {
    button.index = index;

    assertEquals(state, button.next());
    assertEquals(expected, button.index());
    assertEquals(3, button.length());
}
项目:Karus-Commons    文件:BuilderTest.java   
@ParameterizedTest
@CsvSource({"true, 0", "false, 1"})
void lore_String(boolean hasLore, int times) {
    when(meta.hasLore()).thenReturn(hasLore);
    when(meta.getLore()).thenReturn(new ArrayList<>());

    builder.lore("line");

    verify(meta, times(times)).setLore(eq(EMPTY_LIST));
    assertEquals(singletonList("line"), meta.getLore());
}
项目:Karus-Commons    文件:BuilderTest.java   
@ParameterizedTest
@CsvSource({"true, 0", "false, 1"})
void lore_List(boolean hasLore, int setTimes) {
    when(meta.hasLore()).thenReturn(hasLore);
    when(meta.getLore()).thenReturn(new ArrayList<>());

    List<String> lines = asList("line 1", "line 2"); 
    builder.lore(lines);

    verify(meta, times(setTimes)).setLore(eq(EMPTY_LIST));
    assertEquals(lines, meta.getLore());
}
项目:Karus-Commons    文件:ConfigurationProviderTest.java   
@ParameterizedTest
@CsvSource({"ja, jp, ja_JP", "en, '', en", "'', UK, UK"})
public void set(String language, String country, String expected) {
    provider.set(player, new Locale(language, country));

    verify(config).set(player.getUniqueId().toString(), expected);
}
项目:Karus-Commons    文件:TaskTest.java   
@ParameterizedTest
@CsvSource({"true, true, 1", "true, false, 0", "false, true, 11", "false, false, 10"})
void render(boolean reset, boolean incremental, int expected) {
    task.steps = 10;

    when(effect.reset(anyInt())).thenReturn(reset);
    when(effect.isIncremental()).thenReturn(incremental);

    task.render();

    verify(effect).render(task, task.origin.getLocation(), task.target.getLocation(), task.vector);
    assertEquals(expected, task.steps);
}
项目:Karus-Commons    文件:CloudTest.java   
@ParameterizedTest
@CsvSource({"true, 2", "false, 0"})
void renderDroplets(boolean render, int expected) {
    when(mockRandom.nextBoolean()).thenReturn(render);

    cloud.renderDroplets(context, origin, offset, mockRandom);

    verify(context, times(expected)).render(COLOURED, origin, offset);
}
项目:Karus-Commons    文件:CylinderTest.java   
@ParameterizedTest
@CsvSource({"true", "false"})
void render(boolean rotate) {
    doNothing().when(cylinder).renderSurface(any(), any(), any(), any());
    cylinder.rotate = rotate;

    cylinder.render(context, origin, target, offset);

    verify(cylinder).renderSurface(context, origin, offset, RANDOM);
}
项目:Karus-Commons    文件:CylinderTest.java   
@ParameterizedTest
@CsvSource({"0.1, 2, -1.2, 2", "0.49, 0.49, -3, 0.49", "0.5, 0.5, -3, 0.5"})
void calculate(float value, double x, double y, double z) {
    when(mockRandom.nextFloat()).thenReturn(value);
    when(mockRandom.nextDouble(-1, 1)).thenReturn(-0.8);

    offset.setX(1).setY(1).setZ(1);

    cylinder.calculate(offset, mockRandom, 2);

    assertVector(from(x, y, z), offset, LOW_PRECISION);
}
项目:Karus-Commons    文件:LineTest.java   
@ParameterizedTest
@CsvSource({"2, 1.8660254037844384, -0.7320508075688774, 0.5000000000000001", "0, 2, 2, 2"})
void resolveLink(double length, double x, double y, double z) {
    line.length = length;

    line.resolveLink(context, origin, target);

    assertVector(from(x, y, z), line.link);
}
项目:Karus-Commons    文件:CubeTest.java   
@ParameterizedTest
@CsvSource({"true, 1, 0", "false, 0, 1"})
void render(boolean solid, int walls, int outlines) {
    doNothing().when(cube).renderWalls(context, origin, offset, 0, 0, 0);
    doNothing().when(cube).renderOutline(context, origin, offset, 0, 0, 0);

    cube.solid = solid;

    cube.render(context, origin, target, offset);

    verify(cube, times(walls)).renderWalls(context, origin, offset, 0, 0, 0);
    verify(cube, times(outlines)).renderOutline(context, origin, offset, 0, 0, 0);
}
项目:Karus-Commons    文件:CubeTest.java   
@ParameterizedTest
@CsvSource({"true, 1.317134151772411, 1.905858842747876, -1.17595055072672983", "false, 1.5, -1.5, 1.5"})
void renderPillarOutlines(boolean rotate, double x, double y, double z) {
    cube.rotate = rotate;
    cube.perRow = 1;

    cube.renderPillarOutline(context, origin, 0, offset, 1, 2, 3);

    verify(context).render(PARTICLES, origin, offset);
    assertVector(from(x, y, z), context.offset);
}