Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize junit Assert usage #4214

Merged
merged 1 commit into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testMethodsSticky() {
for (int i = 0; i < 100; i++) {//Two different methods should always use the same invoker every time.
int count1 = testSticky("method1", true);
int count2 = testSticky("method2", true);
Assertions.assertTrue(count1 == count2);
Assertions.assertEquals(count1, count2);
}
}

Expand All @@ -129,7 +129,7 @@ public int testSticky(String methodName, boolean check) {

int count = 0;
for (int i = 0; i < runs; i++) {
Assertions.assertEquals(null, clusterinvoker.invoke(invocation));
Assertions.assertNull(clusterinvoker.invoke(invocation));
if (invoker1 == clusterinvoker.getSelectedInvoker()) {
count++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testArrayMerger() {
result = MergerFactory.getMerger(Integer[].class).merge(intArray1, intArray2, intArray3, null);
Assertions.assertTrue(result.getClass().isArray());
Assertions.assertEquals(7, Array.getLength(result));
Assertions.assertTrue(Integer.class == result.getClass().getComponentType());
Assertions.assertSame(Integer.class, result.getClass().getComponentType());
for (int i = 0; i < 7; i++) {
Assertions.assertEquals(i + 1, Array.get(result, i));
}
Expand Down Expand Up @@ -170,7 +170,7 @@ public void testDoubleArrayMerger() {
Assertions.assertEquals(4, result.length);
double[] mergedResult = {1.2d, 3.5d, 2d, 34d};
for (int i = 0; i < mergedResult.length; i++) {
Assertions.assertTrue(mergedResult[i] == result[i]);
Assertions.assertEquals(mergedResult[i], result[i], 0.0);
}

result = MergerFactory.getMerger(double[].class).merge(null);
Expand All @@ -191,7 +191,7 @@ public void testFloatArrayMerger() {
Assertions.assertEquals(4, result.length);
double[] mergedResult = {1.2f, 3.5f, 2f, 34f};
for (int i = 0; i < mergedResult.length; i++) {
Assertions.assertTrue(mergedResult[i] == result[i]);
Assertions.assertEquals(mergedResult[i], result[i], 0.0);
}

result = MergerFactory.getMerger(float[].class).merge(null);
Expand All @@ -212,7 +212,7 @@ public void testIntArrayMerger() {
Assertions.assertEquals(4, result.length);
double[] mergedResult = {1, 2, 2, 34};
for (int i = 0; i < mergedResult.length; i++) {
Assertions.assertTrue(mergedResult[i] == result[i]);
Assertions.assertEquals(mergedResult[i], result[i], 0.0);
}

result = MergerFactory.getMerger(int[].class).merge(null);
Expand Down Expand Up @@ -296,7 +296,7 @@ public void testLongArrayMerger() {
Assertions.assertEquals(4, result.length);
double[] mergedResult = {1l, 2l, 2l, 34l};
for (int i = 0; i < mergedResult.length; i++) {
Assertions.assertTrue(mergedResult[i] == result[i]);
Assertions.assertEquals(mergedResult[i], result[i], 0.0);
}

result = MergerFactory.getMerger(long[].class).merge(null);
Expand Down Expand Up @@ -352,7 +352,7 @@ public void testShortArrayMerger() {
Assertions.assertEquals(4, result.length);
double[] mergedResult = {1, 2, 2, 34};
for (int i = 0; i < mergedResult.length; i++) {
Assertions.assertTrue(mergedResult[i] == result[i]);
Assertions.assertEquals(mergedResult[i], result[i], 0.0);
}

result = MergerFactory.getMerger(short[].class).merge(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,31 @@ public void testRoute_matchWhen() {

Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => host = 1.2.3.4"));
boolean matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);

router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);

router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(false, matchWhen);
Assertions.assertFalse(matchWhen);

router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.4 & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);

router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.* & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);

router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.1 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(false, matchWhen);
Assertions.assertFalse(matchWhen);

router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.2 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer://1.1.1.1/com.foo.BarService"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);
}

@Test
Expand Down Expand Up @@ -143,23 +143,23 @@ public void testRoute_methodRoute() {
Router router = new ConditionRouterFactory().getRouter(getRouteUrl("methods=getFoo => host = 1.2.3.4"));
boolean matchWhen = ((ConditionRouter) router).matchWhen(
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=setFoo,getFoo,findFoo"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);
// Exactly one method, match
matchWhen = ((ConditionRouter) router).matchWhen(
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=getFoo"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);
// Method routing and Other condition routing can work together
Router router2 = new ConditionRouterFactory()
.getRouter(getRouteUrl("methods=getFoo & host!=1.1.1.1 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router2).matchWhen(
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=getFoo"), invocation);
Assertions.assertEquals(false, matchWhen);
Assertions.assertFalse(matchWhen);

Router router3 = new ConditionRouterFactory()
.getRouter(getRouteUrl("methods=getFoo & host=1.1.1.1 => host = 1.2.3.4"));
matchWhen = ((ConditionRouter) router3).matchWhen(
URL.valueOf("consumer://1.1.1.1/com.foo.BarService?methods=getFoo"), invocation);
Assertions.assertEquals(true, matchWhen);
Assertions.assertTrue(matchWhen);
// Test filter condition
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ public void testSelect_Invokersize0() throws Exception {
Assertions.assertNotNull(l,"cluster.initLoadBalance returns null!");
{
Invoker invoker = cluster.select(l, null, null, null);
Assertions.assertEquals(null, invoker);
Assertions.assertNull(invoker);
}
{
invokers.clear();
selectedInvokers.clear();
Invoker invoker = cluster.select(l, null, invokers, null);
Assertions.assertEquals(null, invoker);
Assertions.assertNull(invoker);
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ public void testCloseAvailablecheck() {
initlistsize5();

Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(false, sinvoker.isAvailable());
Assertions.assertFalse(sinvoker.isAvailable());
Assertions.assertEquals(invoker1, sinvoker);

}
Expand Down Expand Up @@ -308,7 +308,7 @@ public void testSelectAgainAndCheckAvailable() {
selectedInvokers.add(invoker3);
selectedInvokers.add(invoker5);
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertTrue(sinvoker == invoker4);
Assertions.assertSame(sinvoker, invoker4);
}
{
//Boundary condition test .
Expand Down Expand Up @@ -365,23 +365,23 @@ public void testSelect_multiInvokers(String lbname) throws Exception {
initlistsize5();
for (int i = 0; i < runs; i++) {
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(true, sinvoker.isAvailable());
Assertions.assertTrue(sinvoker.isAvailable());

Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
}
for (int i = 0; i < runs; i++) {
selectedInvokers.clear();
selectedInvokers.add(invoker1);
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(true, sinvoker.isAvailable());
Assertions.assertTrue(sinvoker.isAvailable());

Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
}
for (int i = 0; i < runs; i++) {
selectedInvokers.clear();
selectedInvokers.add(invoker2);
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(true, sinvoker.isAvailable());
Assertions.assertTrue(sinvoker.isAvailable());

Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
}
Expand All @@ -390,7 +390,7 @@ public void testSelect_multiInvokers(String lbname) throws Exception {
selectedInvokers.add(invoker2);
selectedInvokers.add(invoker4);
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(true, sinvoker.isAvailable());
Assertions.assertTrue(sinvoker.isAvailable());

Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
}
Expand All @@ -400,7 +400,7 @@ public void testSelect_multiInvokers(String lbname) throws Exception {
selectedInvokers.add(invoker3);
selectedInvokers.add(invoker5);
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(true, sinvoker.isAvailable());
Assertions.assertTrue(sinvoker.isAvailable());

Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
}
Expand All @@ -411,7 +411,7 @@ public void testSelect_multiInvokers(String lbname) throws Exception {
selectedInvokers.add(invoker2);
selectedInvokers.add(invoker3);
Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
Assertions.assertEquals(true, sinvoker.isAvailable());
Assertions.assertTrue(sinvoker.isAvailable());

Mockito.clearInvocations(invoker1, invoker2, invoker3, invoker4, invoker5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testMockInvokerInvoke_normal() {
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());
}

/**
Expand Down Expand Up @@ -102,13 +102,13 @@ public void testMockInvokerInvoke_failmock() {
invocation = new RpcInvocation();
invocation.setMethodName("getSomething2");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());

// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());
}


Expand Down Expand Up @@ -138,13 +138,13 @@ public void testMockInvokerInvoke_forcemock() {
invocation = new RpcInvocation();
invocation.setMethodName("getSomething2");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());

// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());
}

@Test
Expand All @@ -163,7 +163,7 @@ public void testMockInvokerInvoke_forcemock_defaultreturn() {
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
Result ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());
}

/**
Expand Down Expand Up @@ -197,7 +197,7 @@ public void testMockInvokerFromOverride_Invoke_Fock_someMethods() {
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());
}

/**
Expand Down Expand Up @@ -260,13 +260,13 @@ public void testMockInvokerFromOverride_Invoke_Fock_WithDefault() {
invocation = new RpcInvocation();
invocation.setMethodName("getSomething3");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());

// If no mock was configured, return null directly
invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
ret = cluster.invoke(invocation);
Assertions.assertEquals(null, ret.getValue());
Assertions.assertNull(ret.getValue());
}

/**
Expand Down Expand Up @@ -481,7 +481,7 @@ public void testMockInvokerFromOverride_Invoke_check_boolean() {
invocation.setMethodName("getBoolean1");
Result ret = cluster.invoke(invocation);
Assertions.assertTrue(ret.getValue() instanceof Boolean, "result type must be Boolean but was : " + ret.getValue().getClass());
Assertions.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
Assertions.assertTrue(Boolean.parseBoolean(ret.getValue().toString()));
}

@Test
Expand All @@ -494,7 +494,7 @@ public void testMockInvokerFromOverride_Invoke_check_Boolean() {
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean2");
Result ret = cluster.invoke(invocation);
Assertions.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
Assertions.assertTrue(Boolean.parseBoolean(ret.getValue().toString()));
}

@SuppressWarnings("unchecked")
Expand Down
12 changes: 6 additions & 6 deletions dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void test_valueOf_noProtocol() throws Exception {
assertNull(url.getPassword());
assertEquals("10.20.130.230", url.getHost());
assertEquals(0, url.getPort());
assertEquals(null, url.getPath());
assertNull(url.getPath());
assertEquals(0, url.getParameters().size());

url = URL.valueOf("10.20.130.230:20880");
Expand All @@ -81,7 +81,7 @@ public void test_valueOf_noProtocol() throws Exception {
assertNull(url.getPassword());
assertEquals("10.20.130.230", url.getHost());
assertEquals(20880, url.getPort());
assertEquals(null, url.getPath());
assertNull(url.getPath());
assertEquals(0, url.getParameters().size());

url = URL.valueOf("10.20.130.230/context/path");
Expand Down Expand Up @@ -190,7 +190,7 @@ public void test_valueOf_WithProtocolHost() throws Exception {
assertNull(url.getPassword());
assertEquals("10.20.130.230", url.getHost());
assertEquals(0, url.getPort());
assertEquals(null, url.getPath());
assertNull(url.getPath());
assertEquals(0, url.getParameters().size());

url = URL.valueOf("dubbo://10.20.130.230:20880/context/path");
Expand All @@ -208,7 +208,7 @@ public void test_valueOf_WithProtocolHost() throws Exception {
assertEquals("hello1234", url.getPassword());
assertEquals("10.20.130.230", url.getHost());
assertEquals(20880, url.getPort());
assertEquals(null, url.getPath());
assertNull(url.getPath());
assertEquals(0, url.getParameters().size());

url = URL.valueOf("dubbo://admin:[email protected]:20880?version=1.0.0");
Expand All @@ -217,7 +217,7 @@ public void test_valueOf_WithProtocolHost() throws Exception {
assertEquals("hello1234", url.getPassword());
assertEquals("10.20.130.230", url.getHost());
assertEquals(20880, url.getPort());
assertEquals(null, url.getPath());
assertNull(url.getPath());
assertEquals(1, url.getParameters().size());
assertEquals("1.0.0", url.getParameter("version"));

Expand Down Expand Up @@ -282,7 +282,7 @@ public void test_getAddress() throws Exception {
@Test
public void test_getAbsolutePath() throws Exception {
URL url = new URL("p1", "1.2.2.2", 33);
assertEquals(null, url.getAbsolutePath());
assertNull(url.getAbsolutePath());

url = new URL("file", null, 90, "/home/user1/route.js");
assertEquals("/home/user1/route.js", url.getAbsolutePath());
Expand Down
Loading