Skip to content

Commit

Permalink
LORD Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgartner03 committed May 8, 2024
1 parent ac9cb94 commit 0840d12
Showing 1 changed file with 315 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.gepardec.wor.lord.call.ternaries;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
Expand All @@ -36,7 +37,7 @@ public void defaults(RecipeSpec spec) {

@DocumentExample
@Test
public void whenCallInInitialization_thenAddWebCall() {
public void whenCall_thenAddWebCall() {
LOG.info("Start Test");
rewriteRun(
//language=java
Expand Down Expand Up @@ -102,4 +103,317 @@ public static boolean isUseWeb() {
)
);
}
@DocumentExample
@Test
public void whenNoCall_thenDoNothing() {
LOG.info("Start Test");
rewriteRun(
//language=java
java(
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto req) {
return ret;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
}
""")
);
}
@DocumentExample
@Test
public void whenMultipleCallsDifferentTypes_thenChangeToTernaryAndAddToConfigClassOnce() {
LOG.info("Start Test");
rewriteRun(
//language=java
java(
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto req) {
AuMhHostInfoResponseDto ret = callSvcProxy(req);
ret = callSvcProxy(req);
return callSvcProxy(req);
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
}
""",
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto req) {
AuMhHostInfoResponseDto ret = ElgkkPropertiesUtil.isUseWeb() ? callSvcWeb(req) : callSvcProxy(req);
ret = ElgkkPropertiesUtil.isUseWeb() ? callSvcWeb(req) : callSvcProxy(req);
return ElgkkPropertiesUtil.isUseWeb() ? callSvcWeb(req) : callSvcProxy(req);
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
public static boolean isUseWeb() {
return true;
}
}
"""
)
);
}
@DocumentExample
@Test
public void whenCallWithDifferentVariableNames_thenChangeToTernaryAndAddToConfigClassOnce() {
LOG.info("Start Test");
rewriteRun(
//language=java
java(
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto requestDto) {
AuMhHostInfoResponseDto returnDto = callSvcProxy(requestDto);
return returnDto;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
}
""",
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto requestDto) {
AuMhHostInfoResponseDto returnDto = ElgkkPropertiesUtil.isUseWeb() ? callSvcWeb(requestDto) : callSvcProxy(requestDto);
return returnDto;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
public static boolean isUseWeb() {
return true;
}
}
"""
)
);
}
@DocumentExample
@Test
@Disabled("Fails due to a bug: missing recognition of the nested call")
public void whenCallInOtherCall_thenChangeToTernaryAndAddToConfigClassOnce() {
LOG.info("Start Test");
rewriteRun(
//language=java
java(
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto requestDto) {
System.out.print(callSvcProxy(requestDto));
return null;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
}
""",
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto requestDto) {
System.out.print(ElgkkPropertiesUtil.isUseWeb() ? callSvcWeb(requestDto) : callSvcProxy(requestDto));
return null;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
public static boolean isUseWeb() {
return true;
}
}
"""
)
);
}

@DocumentExample
@Test
@Disabled("Fails due to a bug: Ternary is missing semicolons when replacing the call")
public void whenCallWithoutTargetVariable_thenAddWebCallWithSemicolons() {
LOG.info("Start Test");
rewriteRun(
//language=java
java(
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto req) {
callSvcProxy(req);
return null;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
}
""",
"""
package com.gepardec.wor.lord;
public class Test {
public AuMhHostInfoResponseDto getAuMhHostInfo(AuMhHostInfoRequestDto req) {
ElgkkPropertiesUtil.isUseWeb() ? callSvcWeb(req) : callSvcProxy(req);
return null;
}
AuMhHostInfoResponseDto callSvcProxy(AuMhHostInfoRequestDto req) {return null;}
AuMhHostInfoResponseDto callSvcWeb(AuMhHostInfoRequestDto req) {return null;}
}
public class AuMhHostInfoResponseDto {
public Integer getCallStatus() {
return null;
}
}
public class AuMhHostInfoRequestDto {}
public class ElgkkPropertiesUtil {
public static final String getElgkkProperties(String key) {
return null;
}
public static boolean isUseWeb() {
return true;
}
}
"""
)
);
}

}

0 comments on commit 0840d12

Please sign in to comment.