Proguard: obfuscate classes with main() that have specific annotation - proguard

We all do:
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
But I'd like to be able to annotate the main that may be obfuscated:
#ObfuscateMe
public static void main(String[] args) {}
How can I tell Proguard to keep all the classes with a main, but obfuscate those with a main that have this annotation?

Not possible:
https://sourceforge.net/p/proguard/discussion/182455/thread/4b713549/
~~~~~~~~~~~~~~~~~~

Related

Do we need to add webdriver paths into the pom file each time we create a new class

I have created a new class and added this piece there but I get an error. The same piece runs on another class.
package BeginnerPrograms;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebLocators {
public static void main(String[] args) {
ChromeDriver driver = new ChromeDriver();
driver.get("http://www.developer.salesforce.com/signup");
}
}
Error received: The path to the driver executable must be set by the webdriver.chrome.driver system property;
No, You don't need to add WebDriver path into the POM file.
Just declare that in #BeforeSuite if you are using TestNG or in your TestBase class.
and use the instance of driver everywhere.
TestNG Example :
#BeforeSuite
public void setUpSuite() {
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe")
}
Only Java Example :
public class TestBase{
public TestBase(){
System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe")
//Your other constructor stuff here.
}
}
and in your TestClass, use it like this :
public class TestClass extends TestBase{
public void someTestMethod(){
new TestBase();
//proceed with your test case here
}
}

Where do Before and After hooks go in Cucumber

I have a fairly simple Cucumber test framework with a feature file, a step definitions file, and a test runner class that looks like this:
#RunWith(Cucumber.class)
#CucumberOptions(features = "src/test/java/com/tests/cucumber/features/ui/ExampleTest.feature",
glue = { "com.tests.cucumber.stepdefinitions" },
)
public class ExampleTestRunner {
}
This runs a scenario in the feature file just fine. Now I want to add a Before and After hook to do some setup and teardown, but I can't for the like of me get the hooks to run. I've tried adding the hooks to the ExampleTestRunner and to the StepDefinition class, but they never run. Where should I put these hooks? At the moment, the hooks just look like this, but I'll add content to them once I've worked this out!
package com.tests.cucumber.stepdefinitions;
import cucumber.api.java.After;
import cucumber.api.java.Before;
public class StepDefinitions {
#Before
public void before() {
System.out.println("starting before()");
}
}
Thanks for any help.
I am a little hesitant to answer this question even though I managed to get this to work. As far as I can tell, the problem was that I had added the Before and After methods in classes that were extended by other classes. In this situation, the tests would not run. I had to add the Before and After methods to a class that was not extended.
It feels like this is similar to the situation in which if you specify a step definition in a class that is extended by another class, then the step definition is considered to have a duplicate definition. Do I have the correct diagnosis here?
I use like this;
Runner Class:
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src\\test\\features\\ui_features"},
glue = {"com\\base\\tm\\auto_reg\\tests\\ui_tests\\price_features"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:"}
)
public class PriceFeatureRunner {
#BeforeClass
public static void setup() {
RunnerUtil.setup(PriceFeatureRunner.class);
}
#AfterClass
public static void teardown() {
RunnerUtil.teardown();
}
}
RunnerUtil.java:
public class RunnerUtil {
public static void setup(Class<?> clazz) {
String reportPath = "target/cucumber-reports/" + clazz.getSimpleName().split("_")[0] + "_report.html";
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath(reportPath);
}
public static void teardown() {
UiHooks uiHooks = new UiHooks();
uiHooks.afterScenario();
ExtentReportConfiguration.configureExtentReportTeardown();
}
}
UiHooks.java
public class UiHooks implements HookHelper {
public static final String BASE_URL = "https://www.stackoverfow.com/";
private Scenario scenario;
#Override
#Before
public void beforeScenario(Scenario scenario) {
this.scenario = scenario;
Reporter.assignAuthor(System.getProperty("user.name"));
}
#Override
#After
public void afterScenario() {
if (HookUtil.driver != null) {
HookUtil.driver.quit();
}
if (HookUtil.seleniumBase != null) {
HookUtil.seleniumBase.stopService();
}
}
#Override
#After
public void afterTest() {
if (HookUtil.driver != null) {
HookUtil.driver.quit();
}
if (HookUtil.seleniumBase != null) {
HookUtil.seleniumBase.stopService();
}
}
}
HookHelper.Java
public interface HookHelper {
#Before
void beforeScenario(Scenario scenario);
#After
void afterScenario();
void afterTest();
}

How can I have #AspectJ target specific subclasses when method signature has parent class?

Say I have a method signature that is
public void accept(ParentInterface parent)
where ParentInterface is an interface. I want my pointcut to only specifically target a class TestA, but not a class TestB, both which implement the ParentInterface.
Currently, I have the following pointcut:
#Pointcut("call(public void accept(package.ParentInterface))")
But that would catch instances where accept is taking in a TestB instance too. Is there a method of fixing this?
Interface + implementations + driver application:
package de.scrum_master.app;
public interface ParentInterface {}
package de.scrum_master.app;
public class TestA implements ParentInterface {}
package de.scrum_master.app;
public class TestB implements ParentInterface {}
package de.scrum_master.app;
public class Application {
public void accept(ParentInterface parent) {}
public static void main(String[] args) {
Application application = new Application();
application.accept(new TestA());
application.accept(new TestB());
}
}
Aspect pinning down argument type via args() + pointcut method signature:
package de.scrum_master.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import de.scrum_master.app.TestA;
#Aspect
public class MyAspect {
#Pointcut("call(public void accept(de.scrum_master.app.ParentInterface)) && args(argument)")
static void acceptCalls(TestA argument) {}
#Before("acceptCalls(argument)")
public void intercept(TestA argument, JoinPoint thisJoinPoint) {
System.out.println(thisJoinPoint + " -> " + argument);
}
}
Console log:
call(void de.scrum_master.app.Application.accept(ParentInterface)) -> de.scrum_master.app.TestA#4a574795

Why doesn't IntelliJ properly format this block of code?

public class MyClass {
public static void main(String[] args) {
System.
out
.
println
("Hello world"
)
;
}
}
Nothing happens when I press Ctrl+Alt+L. I expect that it should format it to something like:
public class MyClass {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
The code is already formatted according to the default style. If you want it formatted differently, change the configuration.

JUnit: Is there a RunListener method, which is called after #After annotated method?

Is there a way to invoke a method after all #After annotated methods of a test method had been run?
I need this for a special framework for my company.
In testng i can use the afterInvocation method, which is called after every configuration method. Is there some alternative in JUnit?
A rule will run after all the #Afters. The ExternalResource could be abused in order to do what you want:
public class VerifyTest {
#Rule public ExternalResource externalResource = new ExternalResource() {
public void after() {
System.out.println("ExternalResource.after");
}
};
#After
public void after1() {
System.out.println("after1");
}
#After
public void after2() {
System.out.println("after2");
}
#Test
public void testVerify throws IOException {
}
}