Sitelet https://github.com/KrailOrg/q3c-util/commit/347ca942b9513f807f93704f65c92359a8ff17b3
Skip to content

Commit 347ca94

Browse files
author
David Sowerby
committed
Test added for DefaultClassNameUtils. New test package in src/main with test helpers
1 parent ef66334 commit 347ca94

6 files changed

Lines changed: 160 additions & 2 deletions

File tree

‎build.gradle‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ apply plugin: 'uk.q3c.kaytee'
2020
group='uk.q3c.util'
2121

2222
kaytee {
23-
baseVersion = "0.8.0.1"
24-
generateChangeLog = false
23+
baseVersion = "0.8.0.2"
2524
}
2625

2726
bintray {
@@ -35,6 +34,7 @@ compileKotlin {
3534
ext.assertjVersion = '3.3.0'
3635
ext.commonsLangVersion = '3.3.2'
3736
ext.guavaVersion = '23.0'
37+
ext.guiceVersion = '4.1.0'
3838
ext.slf4jVersion = '1.7.6'
3939

4040
repositories {
@@ -48,6 +48,8 @@ dependencies {
4848
compile 'ch.qos.logback:logback-classic:1.1.2'
4949
compile 'ch.qos.logback:logback-core:1.1.2'
5050
compile 'org.apache.commons:commons-lang3:' + commonsLangVersion
51+
52+
compile "com.google.inject:guice:$guiceVersion"
5153
//the easiest way to all the Jung parts
5254
compile 'net.sf.jung:jung-samples:2.0.1'
5355
compile 'com.google.code.findbugs:annotations:3.0.0'
@@ -60,6 +62,7 @@ dependencies {
6062
testCompile 'org.assertj:assertj-guava:1.3.1'
6163
compile 'org.mockito:mockito-all:1.10.19'
6264
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
65+
testCompile 'org.spockframework:spock-guice:1.1-groovy-2.4'
6366
testCompile 'cglib:cglib-nodep:3.2.0'
6467
testCompile 'org.objenesis:objenesis:2.2'
6568
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2013 David Sowerby
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package uk.q3c.util.test;
14+
15+
import com.google.inject.AbstractModule;
16+
import com.google.inject.matcher.Matchers;
17+
18+
/**
19+
* Simply generates AOP code for a single test class
20+
* <p>
21+
* *
22+
*
23+
* @author David Sowerby
24+
*/
25+
public class AOPTestModule extends AbstractModule {
26+
27+
@Override
28+
protected void configure() {
29+
bindInterceptor(Matchers.any(), Matchers.annotatedWith(NotOnWeekends.class),
30+
new WeekendBlocker());
31+
}
32+
33+
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package uk.q3c.util.test;
2+
3+
/**
4+
* Created by David Sowerby on 07 Aug 2017
5+
*/
6+
public class EnhancedClass {
7+
8+
@NotOnWeekends
9+
public void justForAOPAnnotation() {
10+
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2015. David Sowerby
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*/
11+
12+
package uk.q3c.util.test;
13+
14+
import java.lang.annotation.ElementType;
15+
import java.lang.annotation.Retention;
16+
import java.lang.annotation.RetentionPolicy;
17+
import java.lang.annotation.Target;
18+
19+
/**
20+
* Created by David Sowerby on 07/05/15.
21+
*/
22+
@Retention(RetentionPolicy.RUNTIME)
23+
@Target(ElementType.METHOD)
24+
public @interface NotOnWeekends {
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2015. David Sowerby
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*/
11+
12+
package uk.q3c.util.test;
13+
14+
import org.aopalliance.intercept.MethodInterceptor;
15+
import org.aopalliance.intercept.MethodInvocation;
16+
17+
import java.util.Calendar;
18+
import java.util.GregorianCalendar;
19+
20+
/**
21+
* Created by David Sowerby on 07/05/15.
22+
*/
23+
public class WeekendBlocker implements MethodInterceptor {
24+
public Object invoke(MethodInvocation invocation) throws Throwable {
25+
Calendar today = new GregorianCalendar();
26+
if (today.getFirstDayOfWeek() > 1) {
27+
System.out.println("Rubbish out from test class");
28+
}
29+
return invocation.proceed();
30+
}
31+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
*
3+
* * Copyright (c) 2016. David Sowerby
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6+
* * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
* *
8+
* * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
* * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
* * specific language governing permissions and limitations under the License.
11+
*
12+
*/
13+
14+
package uk.q3c.util.clazz
15+
16+
import com.google.inject.Inject
17+
import spock.guice.UseModules
18+
import spock.lang.Specification
19+
import uk.q3c.util.test.AOPTestModule
20+
import uk.q3c.util.test.EnhancedClass
21+
22+
/**
23+
24+
* Created by David on 22/10/15.
25+
*/
26+
@UseModules([AOPTestModule])
27+
class DefaultClassNameUtilsTest extends Specification {
28+
29+
ClassNameUtils utils = new DefaultClassNameUtils()
30+
31+
32+
@Inject
33+
EnhancedClass testClass
34+
35+
def "SimpleNameWithoutEnhance"() {
36+
given:
37+
String testClassName = testClass.getClass().getName()
38+
39+
expect:
40+
testClassName.startsWith('uk.q3c.util.test.EnhancedClass$$EnhancerByGuice')
41+
42+
and:
43+
utils.simpleClassNameEnhanceRemoved(EnhancedClass.class).equals('EnhancedClass')
44+
45+
and:
46+
utils.simpleClassNameEnhanceRemoved(testClass.getClass()).equals('EnhancedClass')
47+
48+
and:
49+
utils.classWithEnhanceRemoved(testClass.getClass()).equals(EnhancedClass.class)
50+
}
51+
52+
53+
}

0 commit comments

Comments
 (0)