Skip to content

Commit

Permalink
Reproduce #41 (#86)
Browse files Browse the repository at this point in the history
As far as I can tell interface works fine.
  • Loading branch information
eed3si9n authored Jul 28, 2024
1 parent 53e0961 commit c7bb69f
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
15 changes: 15 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,19 @@ ThisBuild / githubWorkflowPublish := Seq(
)
)
ThisBuild / sonatypeProfileName := "com.github.sbt"
// So that publishLocal doesn't continuously create new versions
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
val snapshotSuffix = if
(out.isSnapshot()) "-SNAPSHOT"
else ""
out.ref.dropPrefix + snapshotSuffix
}

def fallbackVersion(d: java.util.Date): String = s"HEAD-${sbtdynver.DynVer timestamp d}"

ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value))
ThisBuild / dynver := {
val d = new java.util.Date
sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d))
}
Global / onChangedBuildSource := ReloadOnSourceChanges
4 changes: 4 additions & 0 deletions src/plugin/src/sbt-test/basic/interface-demo/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name := "test-project"
libraryDependencies ++= Seq(
"com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.github.sbt.junit" % "sbt-jupiter-interface" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package example;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public interface ComparableContract<T extends Comparable<T>> extends Testable<T> {

T createSmallerValue();

@Test
default void returnsZeroWhenComparedToItself() {
T value = createValue();
assertEquals(0, value.compareTo(value));
}

@Test
default void returnsPositiveNumberWhenComparedToSmallerValue() {
T value = createValue();
T smallerValue = createSmallerValue();
assertTrue(value.compareTo(smallerValue) > 0);
}

@Test
default void returnsNegativeNumberWhenComparedToLargerValue() {
T value = createValue();
T smallerValue = createSmallerValue();
assertTrue(smallerValue.compareTo(value) < 0);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package example;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public interface EqualsContract<T> extends Testable<T> {

T createNotEqualValue();

@Test
default void valueEqualsItself() {
T value = createValue();
assertEquals(value, value);
}

@Test
default void valueDoesNotEqualNull() {
T value = createValue();
assertFalse(value.equals(null));
}

@Test
default void valueDoesNotEqualDifferentValue() {
T value = createValue();
T differentValue = createNotEqualValue();
assertNotEquals(value, differentValue);
assertNotEquals(differentValue, value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package example;

class StringTests implements ComparableContract<String>, EqualsContract<String> {

@Override
public String createValue() {
return "banana";
}

@Override
public String createSmallerValue() {
return "apple"; // 'a' < 'b' in "banana"
}

@Override
public String createNotEqualValue() {
return "cherry";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package example;

public interface Testable<T> {
T createValue();
}
1 change: 1 addition & 0 deletions src/plugin/src/sbt-test/basic/interface-demo/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> test

0 comments on commit c7bb69f

Please sign in to comment.