8000 #111 Removed mockito usage at Log injection testing classes · seleniumQuery/seleniumQuery@10595f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 10595f0

Browse files
committed
#111 Removed mockito usage at Log injection testing classes
1 parent cf2cada commit 10595f0
Copy full SHA for 10595f0

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

src/test/java/io/github/seleniumquery/by/secondgen/csstree/selector/combinator/SQCssDirectAdjacentSelectorTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
import io.github.seleniumquery.by.secondgen.csstree.selector.SQCssTagNameSelector;
2020
import io.github.seleniumquery.by.secondgen.finder.ElementFinder;
2121
import org.junit.Test;
22-
import org.openqa.selenium.WebDriver;
2322

2423
import static org.hamcrest.CoreMatchers.is;
2524
import static org.hamcrest.collection.IsEmptyCollection.empty;
2625
import static org.junit.Assert.assertThat;
27-
import static org.mockito.Mockito.mock;
2826
import static testinfrastructure.testdouble.org.openqa.selenium.WebDriverDummy.createWebDriverDummy;
2927

3028
public class SQCssDirectAdjacentSelectorTest {

src/test/java/io/github/seleniumquery/functions/jquery/events/ClickFunctionTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@
1818

1919
import io.github.seleniumquery.SeleniumQueryException;
2020
import io.github.seleniumquery.SeleniumQueryObject;
21-
import org.apache.commons.logging.Log;
2221
import org.junit.Test;
2322
import org.openqa.selenium.ElementNotVisibleException;
2423
import org.openqa.selenium.WebElement;
24+
import testinfrastructure.testdouble.org.apache.commons.logging.LogInjector;
25+
import testinfrastructure.testdouble.org.apache.commons.logging.LogSpy;
2526
import testinfrastructure.testdouble.org.openqa.selenium.WebElementClickSpy;
26-
import testinfrastructure.testutils.LogInjector;
2727

2828
import static org.hamcrest.core.Is.is;
2929
import static org.junit.Assert.assertThat;
30-
import static org.mockito.Mockito.*;
3130
import static testinfrastructure.testdouble.io.github.seleniumquery.SeleniumQueryObjectMother.createStubSeleniumQueryObjectWithElements;
3231
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementClickSpy.createWebElementClickSpy;
3332
import static testinfrastructure.testdouble.org.openqa.selenium.WebElementMother.createWebElementClickable;
@@ -73,12 +72,12 @@ public void click__shouldCallClickOnEveryElementEvenIfSomeThrowExceptions() {
7372
@Test
7473
public void click__shouldLogInfoIfAnyElementThrewException() {
7574
// given
76-
Log logSpy = LogInjector.injectLogSpy(ClickFunction.class);
75+
LogSpy logSpy = LogInjector.injectLogSpy(ClickFunction.class);
7776
SeleniumQueryObject sqo = createStubSeleniumQueryObjectWithElements(createWebElementUnclickableHidden(), createWebElementClickable());
7877
// when
7978
ClickFunction.click(sqo);
8079
// then
81-
verify(logSpy).info(anyString(), any(ElementNotVisibleException.class));
80+
logSpy.assertInfoWithExceptionWasLogged(ElementNotVisibleException.class);
8281
}
8382

8483
@Test(expected = SeleniumQueryException.class)

src/test/java/testinfrastructure/testutils/LogInjector.java renamed to src/test/java/testinfrastructure/testdouble/org/apache/commons/logging/LogInjector.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 seleniumQuery authors
2+
* Copyright (c) 2016 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,23 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
package testinfrastructure.testutils;
18-
19-
import org.apache.commons.logging.Log;
17+
package testinfrastructure.testdouble.org.apache.commons.logging;
2018

2119
import java.lang.reflect.Field;
2220
import java.lang.reflect.Modifier;
2321

24-
import static org.mockito.Mockito.mock;
25-
2622
public class LogInjector {
2723

28-
private static Log createLogSpy() {
29 57A6 -
return mock(Log.class);
30-
}
31-
32-
public static Log injectLogSpy(Class<?> clazz) {
33-
Log logSpy = createLogSpy();
24+
public static LogSpy injectLogSpy(Class<?> clazz) {
25+
LogSpy logSpy = new LogSpy();
3426
setFinalStaticField(clazz, "LOGGER", logSpy);
3527
return logSpy;
3628
}

src/test/java/testinfrastructure/testutils/LogInjectorTest.java renamed to src/test/java/testinfrastructure/testdouble/org/apache/commons/logging/LogInjectorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015 seleniumQuery authors
2+
* Copyright (c) 2016 seleniumQuery authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package testinfrastructure.testutils;
17+
package testinfrastructure.testdouble.org.apache.commons.logging;
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
@@ -29,10 +29,10 @@ public class LogInjectorTest {
2929
@Test
3030
public void injectLogSpy__managesToInjectLog() {
3131
// when
32-
Log logSpy = LogInjector.injectLogSpy(LogInjectorTest.class);
32+
LogSpy logSpy = LogInjector.injectLogSpy(LogInjectorTest.class);
3333
// then
34-
LOGGER.info("SomeMessage");
35-
verify(logSpy).info("SomeMessage");
34+
LOGGER.info("SomeMessage", new Exception());
35+
logSpy.assertInfoWithExceptionWasLogged(Exception.class);
3636
}
3737

3838
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2016 seleniumQuery authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package testinfrastructure.testdouble.org.apache.commons.logging;
18+
19+
import org.apache.commons.logging.Log;
20+
21+
import static org.hamcrest.CoreMatchers.instanceOf;
22+
import static org.hamcrest.junit.MatcherAssert.assertThat;
23+
24+
public class LogSpy implements Log {
25+
26+
private Throwable infoLoggedThrowableClass;
27+
28+
@Override public void debug(Object o) { }
29+
@Override public void debug(Object o, Throwable throwable) { }
30+
@Override public void error(Object o) { }
31+
@Override public void error(Object o, Throwable throwable) { }
32+
@Override public void fatal(Object o) { }
33+
@Override public void fatal(Object o, Throwable throwable) { }
34+
@Override public void info(Object o) { }
35+
36+
@Override public void info(Object o, Throwable throwable) {
37+
this.infoLoggedThrowableClass = throwable;
38+
}
39+
40+
@Override public boolean isDebugEnabled() { return false; }
41+
@Override public boolean isErrorEnabled() { return false; }
42+
@Override public boolean isFatalEnabled() { return false; }
43+
@Override public boolean isInfoEnabled() { return false; }
44+
@Override public boolean isTraceEnabled() { return false; }
45+
@Override public boolean isWarnEnabled() { return false; }
46+
@Override public void trace(Object o) { }
47+
@Override public void trace(Object o, Throwable throwable) { }
48+
@Override public void warn(Object o) { }
49+
@Override public void warn(Object o, Throwable throwable) { }
50+
51+
public void assertInfoWithExceptionWasLogged(Class<? extends Throwable> throwableClass) {
52+
assertThat(this.infoLoggedThrowableClass, instanceOf(throwableClass));
53+
}
54+
55+
}

0 commit comments

Comments
 (0)
0