Structural Search and Replace - Unit tests?

Hi all,

I am trying to create a SSR template which will convert all Unit 3 tests to Unit 4 test. I want to do this by removing the extends Testcase, and removing the 'test' prefix from all methods.

This is my source:

and I want to replace this by:


So my question: is it possible? I already have problems removing the 'test' prefix from the method same. I tried defining a new variable, but that doens't seem possible in the 'replace' part...

anyone suggestions?

3 comments
Comment actions Permalink

Right it isn't possible but please file JIRA item for this
Erik Pragt wrote:

Hi all,

I am trying to create a SSR template which will convert all Unit 3 tests to Unit 4 test. I want to do this by removing the extends Testcase, and removing the 'test' prefix from all methods.

This is my source:

 import junit.framework.TestCase;
> 
> public class CalculatorTest extends TestCase {
>     private Calculator calculator = new Calculator();
> 
>     public void testOneAndOneIsTwo() {
>         assertEquals(2, calculator.add(1, 1));
>     }
> }
> ]]>

and I want to replace this by:

 
> import static junit.framework.Assert.assertEquals;
> import org.junit.Test;
> 
> public class CalculatorTest {
>     private Calculator calculator = new Calculator();
> 
>     @Test
>     public void oneAndOneIsTwo() {
>         assertEquals(2, calculator.add(1, 1));
>     }    
> }
> ]]>


So my question: is it possible? I already have problems removing the 'test' prefix from the method same. I tried defining a new variable, but that doens't seem possible in the 'replace' part...

anyone suggestions?



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Right it isn't possible but please file JIRA item for this
Erik Pragt wrote:


http://jetbrains.net/jira/browse/IDEA-20103

0
Comment actions Permalink

The YouTrack item http://jetbrains.net/jira/browse/IDEA-20103 is listed as resolved, but I'm not sure how to use it. There is no detail on the issue itself.

I'm in the same position as the original poster (with a little more detail).

I'm trying to convert

public void testFoo() throws ExceptionType {
  doSomethingExpectedToThrowException();
  ///CLOVER:OFF
  fail();
  ///CLOVER:ON
}

to

@Test(expected=ExceptionType.class)
public void foo() throws ExceptionType {
  doSomethingExpectedToThrowException();
}

SSR can't seem to replace each individual matching method. It replaces the entire class with a single matching method. I'm also not sure how to achieve the method name mutation as described in the YouTrack item.

This is on IU-90.94.

Cheers.
Brad

0

Please sign in to leave a comment.