Skip to content

Instantly share code, notes, and snippets.

View acdcjunior's full-sized avatar
🌘
It's been a hard day's night

Antônio "acdc" Jr. acdcjunior

🌘
It's been a hard day's night
View GitHub Profile
@acdcjunior
acdcjunior / ExemploMethodRule.java
Created December 5, 2013 19:55
JUnit @rule MethodRule example implementation - Exemplo de implementacao de @rule no JUnit
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
public class ExemploMethodRule implements MethodRule {
@Override
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
System.out.println("ExemploMethodRule#apply() - base: " + base);
System.out.println("ExemploMethodRule#apply() - method (metodo de teste atual): " + method);
@acdcjunior
acdcjunior / ExemploTest.java
Created December 5, 2013 19:59
Exemplo de classe de teste JUnit que usa @rule - Example test class using JUnit's @rule
import org.junit.*;
public class ExemploTest {
@Rule
public ExemploMethodRule exemploRule = new ExemploMethodRule();
@BeforeClass
public static void beforeClass() {
System.out.println("@BeforeClass");
@acdcjunior
acdcjunior / ParsedUrl.js
Last active December 7, 2020 11:51
Cross-browser URL parsing in JavaScript
function ParsedUrl(url) {
var parser = document.createElement("a");
parser.href = url;
// IE 8 and 9 dont load the attributes "protocol" and "host" in case the source URL
// is just a pathname, that is, "/example" and not "http://domain.com/example".
parser.href = parser.href;
// IE 7 and 6 wont load "protocol" and "host" even with the above workaround,
// so we take the protocol/host from window.location and place them manually
@acdcjunior
acdcjunior / velocityToolsConfig.xml
Created June 2, 2014 16:45
Example configuration file for velocityTools for Apache Velocity
<!--
Notes:
- Using this file, the tools are "$dateTool" etc. not "$date" as default -- if needed, change the <key>.
- Apparently, this format is deprecated in Velocity Tools 2.0, but still works. I didn't manage to get the new
format working (http://velocity.apache.org/tools/devel/config-xml.html) so...
-->
<toolbox>
@acdcjunior
acdcjunior / pom.xml
Last active October 29, 2015 21:39
JUnit + Hamcrest + Mockito - Java Unit Tests Dependencies - Mavem pom.xml excerpt
<dependencies>
...
<!-- Test Dependencies Only -->
<!-- Last updated: 2015-10-29 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
@acdcjunior
acdcjunior / applicationContext.xml
Created June 6, 2014 18:42
Properties File in spring application context
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/applicationContext.properties</value>
</property>
</bean>
<context:property-placeholder properties-ref="configProperties" />
<!-- Now create a .properties file with the name above and reference its properties by
${propertyName} in .xml files or use @Value annotation to inject them in beans -->
@acdcjunior
acdcjunior / SeleniumQueryExample.java
Last active December 17, 2017 19:15
seleniumQuery Example class/code from demo project
import static io.github.seleniumquery.SeleniumQuery.$; // this will allow the short syntax
public class SeleniumQueryExample {
public static void main(String[] args) {
// The WebDriver will be instantiated only when first used
$.driver()
.useChrome() // sets Chrome as the driver (this is optional, if omitted, will default to HtmlUnit)
.headless() // configures chrome to be headless
.autoDriverDownload() // automatically downloads and configures chromedriver.exe
.autoQuitDriver(); // automatically quits the driver when the JVM shuts down
@acdcjunior
acdcjunior / namedKeyUpBinding.js
Last active August 29, 2015 14:10
Creating (binding) a specific event and removing (unbinding) it only
$(document).on("keyup.escKeyClosesModal", function(e) { ... });
@acdcjunior
acdcjunior / wildfly-maven-plugin-pom.xml
Created December 4, 2014 04:26
Wildfly Maven Plugin afterDeployment CLI command example snippet pom.xml
<build>...<plugins>...
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<configuration>
<afterDeployment>
<commands>
<command>/subsystem=security/security-domain="unused-domain":remove</command>
</commands>
@acdcjunior
acdcjunior / SeleniumXPathVersion2.java
Last active August 21, 2016 14:53
What XPath version does a given Selenium WebDriver support?
private String getXPathVersion(WebDriver context) {
try {
By.xpath("/nobody[@attr=lower-case('A')]").findElement(context);
return "2.0";
} catch (Exception e) {
return "1.0";
}
}