Skip to content

Instantly share code, notes, and snippets.

View irof's full-sized avatar
🏠
Working from home

irof irof

🏠
Working from home
View GitHub Profile
def xml = new XmlParser().parseText("""<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="sample.HelloTest" tests="1" skipped="0" failures="0" errors="0" timestamp="2015-12-04T00:11:21" hostname="iProf.local" time="0.22">
<properties/>
<testcase name="test_sayHello" classname="sample.HelloTest" time="0.22"/>
<system-out><![CDATA[system-out-text]]></system-out>
<system-err><![CDATA[system-err-text]]></system-err>
</testsuite>""")
assert xml."system-out".text() == "system-out-text"
死因 死因 = new SiinBuilder()
.外傷(無し)
.死亡推定時刻(2015-10-20T12:34:56)
.死亡場所(自宅近くの道路)
.add目撃証言(2015-10-18, 近隣住民)
.年齢(98)
.build();
assert 死因 == 交通事故; // => false
import java.time.LocalDateTime;
import java.util.Date;
import static org.junit.Assert.assertFalse;
/**
* @author irof
*/
public class DateAndDateTimeTest {
@org.junit.Test
@irof
irof / JerseyTestを使うときのGradleの依存解決
Last active August 29, 2015 14:20
JerseyTestを動かすのに要るjarを眺めてみる(2.17)
(https://github.com/irof/sandbox/tree/blog/20150501/jaxrs/jersey をちょっと削ったの)
% gradle dependencies --configuration testCompile :jersey:dependencies
------------------------------------------------------------
Project :jersey
------------------------------------------------------------
testCompile - Compile classpath for source set 'test'.
+--- org.glassfish.jersey.core:jersey-server:2.17
@irof
irof / hoge.sh
Last active August 29, 2015 14:07
-cpに~つかえねーとか @backpaper0 とやらがいうので https://twitter.com/backpaper0/status/522727485293596672
mkdir ~/hoge
mkdir work
cd work
echo "class Hoge { public static void main(String... args) { System.out.println(1); } }" > Hoge.java
echo "class Fuga { public static void main(String... args) { System.out.println(2); } }" > Fuga.java
javac Hoge.java Fuga.java
jar cvf Hoge.jar Hoge.class
jar cvf Fuga.jar Fuga.class
mv ./*.jar ~/hoge
public class DiamondProblem implements IHoge, IPiyo {
public static void main(String[] args) {
System.out.println(new DiamondProblem().hoge());
}
}
@irof
irof / -parametersあり
Last active December 14, 2015 17:48
java -parameters 有無それぞれで javap -v ってみた。
Classfile /x/Hoge.class
Last modified 2013/03/10; size 301 bytes
MD5 checksum 41f968697a1e7fe44a4d38e2d709d560
Compiled from "Hoge.java"
public class Hoge
SourceFile: "Hoge.java"
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
@irof
irof / ParameterNameExample.java
Created March 9, 2013 14:55
Java8で実行時にメソッドの引数の名前がとれるかんじ。 http://openjdk.java.net/jeps/118 とか。 http://download.java.net/jdk8/docs/api/java/lang/reflect/Parameter.html#getName() とか。
import java.lang.reflect.Method;
import java.util.Arrays;
public class ParameterNameExample {
public static void main(String... args) {
Class<ParameterNameExample> clz = ParameterNameExample.class;
Arrays.stream(clz.getMethods()).filter(m -> m.getName().startsWith("method"))
.map(m -> m.getName() + Arrays.toString(m.getParameters()))
@irof
irof / DbUnitTester.java
Created March 7, 2013 23:39
#junitbook P.203 のをJdbcDatabaseTesterで書いてみたもの
package net.hogedriven.irof.sandbox;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.ext.h2.H2DataTypeFactory;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@irof
irof / intellij.java
Created March 4, 2013 12:48
http://backpaper0.github.com/2013/03/03/like_bdd_by_java8.html をデフォルトのふぉーまったにかけてみた
package app;
public class CalcSpec extends Specs {
{
it("1 足す 2 は 3", () -> {
expect(() -> 1 + 2).toEqual(3);
});
it("1 割る 0 は例外", () -> {
expect(() -> 1 / 0).toThrow(ArithmeticException.class);
});