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

add junit 3 test (disabled) #134

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -967,12 +967,12 @@ protected boolean isLifecycleMethod(MethodDeclaration method, String methodName)
return methodName.equals(method.getName().getIdentifier());
}

private boolean isStringType(Expression expression, Class<String> classType) {
protected boolean isStringType(Expression expression, Class<String> classType) {
ITypeBinding typeBinding = expression.resolveTypeBinding();
return typeBinding != null && classType.getCanonicalName().equals(typeBinding.getQualifiedName());
}

private boolean isSubtypeOf(ITypeBinding subtype, ITypeBinding supertype) {
protected boolean isSubtypeOf(ITypeBinding subtype, ITypeBinding supertype) {
return subtype != null
&& supertype != null
&& (isTypeOrSubtype(subtype, supertype.getQualifiedName()) || implementsInterface(subtype, supertype));
Expand Down Expand Up @@ -1262,8 +1262,6 @@ public void reorderParameters(MethodInvocation node, ASTRewrite rewriter, TextEd
}
}



private void replaceFieldWithExtensionDeclaration(ClassInstanceCreation classInstanceCreation,
String nestedClassName, boolean fieldStatic, ASTRewrite rewriter, AST ast, TextEditGroup group,
ImportRewrite importRewriter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package org.eclipse.jdt.ui.tests.quickfix.Java8;

Check warning

Code scanning / PMD

Package name contains upper case characters Warning test

Package name contains upper case characters

Check warning

Code scanning / Pmd (reported by Codacy)

Package name contains upper case characters Warning test

Package name contains upper case characters

/*-
* #%L
* Sandbox junit cleanup test
* %%
* Copyright (C) 2024 hammer
* %%
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is
* available at https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
* #L%
*/

enum JUnit3CleanupCases{
Junit3Case(
"""
package test;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class MyTest extends TestCase {

public MyTest(String name) {
super(name);
}

@Override
protected void setUp() throws Exception {
// Setup vor jedem Test
}

@Override
protected void tearDown() throws Exception {
// Aufräumen nach jedem Test
}

public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new MyTest("testBasicAssertions"));
suite.addTest(new MyTest("testArrayAssertions"));
suite.addTest(new MyTest("testWithAssume"));
suite.addTest(new MyTest("testAssertThat"));
suite.addTest(new MyTest("testEqualityWithDelta"));
suite.addTest(new MyTest("testFail"));
return suite;
}

public void testBasicAssertions() {
assertEquals("Values should match", 42, 42);
assertTrue("Condition should be true", true);
assertFalse("Condition should be false", false);
assertNull("Should be null", null);
assertNotNull("Should not be null", new Object());
}

public void testArrayAssertions() {
int[] expected = {1, 2, 3};
int[] actual = {1, 2, 3};
assertEquals("Arrays should match", expected.length, actual.length);
for (int i = 0; i < expected.length; i++) {
assertEquals("Array element mismatch at index " + i, expected[i], actual[i]);
}
}

public void testWithAssume() {
assumeTrue("Precondition failed", true);
assumeFalse("Precondition not met", false);
}

public void testAssertThat() {
assertEquals("Value should match", 42, 42); // Ersatz für assertThat in JUnit 3
}

public void testEqualityWithDelta() {
assertEquals("Floating point equality with delta", 0.1 + 0.2, 0.3, 0.0001);
}

public void testFail() {
fail("This test should fail with a message.");
}
}

"""
,
"""
package test;

import static org.junit.jupiter.api.Assertions.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assumptions.*;

import org.junit.jupiter.api.*;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MyTest {

@BeforeEach
public void setUp() throws Exception {
// Setup vor jedem Test
}

@AfterEach
public void tearDown() throws Exception {
// Aufräumen nach jedem Test
}

@Test
@Order(1)
public void testBasicAssertions() {
assertEquals(42, 42, "Values should match");
assertTrue(true, "Condition should be true");
assertFalse(false, "Condition should be false");
assertNull(null, "Should be null");
assertNotNull(new Object(), "Should not be null");
}

@Test
@Order(2)
public void testArrayAssertions() {
int[] expected = {1, 2, 3};
int[] actual = {1, 2, 3};
assertArrayEquals(expected, actual, "Arrays should match");
}

@Test
@Order(3)
public void testWithAssume() {
assumeTrue(true, "Precondition failed");
assumeFalse(false, "Precondition not met");
}

@Test
@Order(4)
public void testAssertThat() {
assertThat("Value should match", 42, is(42));
}

@Test
@Order(5)
public void testEqualityWithDelta() {
assertEquals(0.3, 0.1 + 0.2, 0.0001, "Floating point equality with delta");
}

@Test
@Order(6)
public void testFail() {
fail("This test should fail with a message.");
}
}

"""
); //$NON-NLS-1$

String given;
String expected;

JUnit3CleanupCases(String given, String expected) {
this.given=given;
this.expected=expected;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.junit.JUnitCore;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -87,6 +88,30 @@
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH);
context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null);
}

@Disabled
@ParameterizedTest
@EnumSource(JUnit3CleanupCases.class)
public void testJUnit3CleanupParametrized(JUnit3CleanupCases test) throws CoreException {

Check notice

Code scanning / Pmd (reported by Codacy)

JUnit tests should include assert() or fail() Note test

JUnit tests should include assert() or fail()
IPackageFragment pack= fRootJUnit4.createPackageFragment("test", true, null);
ICompilationUnit cu= pack.createCompilationUnit("MyTest.java", test.given, true, null); //$NON-NLS-1$
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSERT);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_ASSUME);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_SUITE);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORE);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTER);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_BEFORECLASS);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_AFTERCLASS);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_IGNORE);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_TEST);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETEMPORARYFOLDER);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULETESTNAME);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RULEEXTERNALRESOURCE);
// context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_EXTERNALRESOURCE);
context4junit4.enable(MYCleanUpConstants.JUNIT_CLEANUP_4_RUNWITH);
context4junit4.assertRefactoringResultAsExpected(new ICompilationUnit[] {cu}, new String[] {test.expected}, null);
}

enum NOJUnitCleanupCases {

Expand Down
Loading