Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsunit with mvn test dependencies #206

Merged
merged 1 commit into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="test" path="src_test">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/mockito/mockito-core/3.5.13/mockito-core-3.5.13.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>junit4-in-bundle-with-dependencies</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: junit4-in-bundle-with-dependencies
Bundle-SymbolicName: junit4.in.bundle.with.dependencies
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: javax.annotation,
org.osgi.framework
Export-Package: bundle.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.tycho-its.surefire</groupId>
<artifactId>junit4.in.bundle.with.dependencies</artifactId>
<packaging>eclipse-plugin</packaging>
<version>1.0.0</version>
<repositories>
<repository>
<id>platform</id>
<url>${target-platform}</url>
<layout>p2</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.5.13</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich. - initial API and implementation
*******************************************************************************/
package bundle.test;

public class CountDown {

RefMe refFromOtherSourceFolder;

int count;

public CountDown(int initalValue) {
count = initalValue;
}

public void decrement(int x) {
if (x < 0) {
throw new IllegalArgumentException();
}
if (count-x < 0) {
throw new IllegalStateException();
}
count -= x;
}

public int get() {
return count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich. - initial API and implementation
*******************************************************************************/
package bundle.test;

public class Counter {

int count;

public void increment(int x) {
if (x < 0) {
throw new IllegalArgumentException();
}
count += x;
}

public int get() {
return count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bundle.test;

public interface MockInterface {
public void test();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich. - initial API and implementation
*******************************************************************************/

package bundle.test;

public class RefMe extends Counter{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich. - initial API and implementation
*******************************************************************************/
package bundle.test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.mockito.Mock;

public class AdderTest {

@Mock
private MockInterface myMock;

@Test
public void incrementTest() {
Counter counter = new Counter();
counter.increment(1);
counter.increment(3);
assertEquals(4, counter.get());
}

@Test(expected = IllegalArgumentException.class)
public void decrementTest() {
Counter counter = new Counter();
counter.increment(-1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package bundle.test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class SubtractorTest {

@Test
public void incrementTest() {
CountDown counter = new CountDown(10);
counter.decrement(1);
counter.decrement(3);
assertEquals(6, counter.get());
}

@Test(expected = IllegalArgumentException.class)
public void decrementTest() {
CountDown counter = new CountDown(10);
counter.decrement(-1);
}

@Test(expected = IllegalStateException.class)
public void decrementTest2() {
CountDown counter = new CountDown(1);
counter.decrement(5);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public void testJUnit4Container() throws Exception {
verifier.verifyErrorFreeLog();
}

@Test
public void testJUnit4ContainerWithDependencies() throws Exception {
Verifier verifier = getVerifier("compiler.junitcontainer/junit4-in-bundle-with-dependencies", true);
verifier.executeGoal("test");
verifier.verifyErrorFreeLog();
}

public void testLibEntry() throws Exception {
Verifier verifier = getVerifier("compiler.libentry/my.bundle", false);
verifier.executeGoal("compile");
Expand Down