diff --git a/build/checkstyle.xml b/build/checkstyle.xml index 35881d062fca0..9ede4dc8c0bd1 100644 --- a/build/checkstyle.xml +++ b/build/checkstyle.xml @@ -48,6 +48,9 @@ + + + diff --git a/community/collections/src/test/java/org/neo4j/helpers/collection/FirstItemIterableTest.java b/community/collections/src/test/java/org/neo4j/helpers/collection/FirstItemIterableTest.java index c97d0ac2cce9d..aceee2c3399fa 100644 --- a/community/collections/src/test/java/org/neo4j/helpers/collection/FirstItemIterableTest.java +++ b/community/collections/src/test/java/org/neo4j/helpers/collection/FirstItemIterableTest.java @@ -21,56 +21,82 @@ import org.junit.Test; -import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; +import static java.util.Arrays.asList; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; /** * @author mh * @since 19.04.12 */ -public class FirstItemIterableTest { +public class FirstItemIterableTest +{ @Test - public void testEmptyIterator() throws Exception { - final FirstItemIterable firstItemIterable = new FirstItemIterable(Collections.emptyList()); - final Iterator empty = firstItemIterable.iterator(); - assertEquals(false, empty.hasNext()); - try { - empty.next(); fail(); - } catch(NoSuchElementException nse) {} - assertEquals(null, firstItemIterable.getFirst()); + public void testEmptyIterator() throws Exception + { + FirstItemIterable firstItemIterable = new FirstItemIterable<>( Collections.emptyList() ); + Iterator empty = firstItemIterable.iterator(); + assertEquals( false, empty.hasNext() ); + try + { + empty.next(); + fail( "Exception expected" ); + } + catch ( Exception e ) + { + assertThat( e, instanceOf( NoSuchElementException.class ) ); + } + assertEquals( null, firstItemIterable.getFirst() ); } + @Test - public void testSingleIterator() throws Exception { - final FirstItemIterable firstItemIterable = new FirstItemIterable(Collections.singleton(Boolean.TRUE)); - final Iterator empty = firstItemIterable.iterator(); - assertEquals(true, empty.hasNext()); - assertEquals(Boolean.TRUE, empty.next()); - assertEquals(Boolean.TRUE, firstItemIterable.getFirst()); - assertEquals(false, empty.hasNext()); - try { - empty.next(); fail(); - } catch(NoSuchElementException nse) {} - assertEquals(Boolean.TRUE, firstItemIterable.getFirst()); + public void testSingleIterator() throws Exception + { + FirstItemIterable firstItemIterable = new FirstItemIterable<>( Collections.singleton( Boolean.TRUE ) ); + Iterator empty = firstItemIterable.iterator(); + assertEquals( true, empty.hasNext() ); + assertEquals( Boolean.TRUE, empty.next() ); + assertEquals( Boolean.TRUE, firstItemIterable.getFirst() ); + assertEquals( false, empty.hasNext() ); + try + { + empty.next(); + fail( "Exception expected" ); + } + catch ( Exception e ) + { + assertThat( e, instanceOf( NoSuchElementException.class ) ); + } + assertEquals( Boolean.TRUE, firstItemIterable.getFirst() ); } + @Test - public void testMultiIterator() throws Exception { - final FirstItemIterable firstItemIterable = new FirstItemIterable(Arrays.asList(Boolean.TRUE,Boolean.FALSE)); - final Iterator empty = firstItemIterable.iterator(); - assertEquals(true, empty.hasNext()); - assertEquals(Boolean.TRUE, empty.next()); - assertEquals(Boolean.TRUE, firstItemIterable.getFirst()); - assertEquals(true, empty.hasNext()); - assertEquals(Boolean.FALSE, empty.next()); - assertEquals(Boolean.TRUE, firstItemIterable.getFirst()); - assertEquals(false, empty.hasNext()); - try { - empty.next(); fail(); - } catch(NoSuchElementException nse) {} - assertEquals(Boolean.TRUE, firstItemIterable.getFirst()); + public void testMultiIterator() throws Exception + { + FirstItemIterable firstItemIterable = new FirstItemIterable<>( asList( Boolean.TRUE, Boolean.FALSE ) ); + Iterator empty = firstItemIterable.iterator(); + assertEquals( true, empty.hasNext() ); + assertEquals( Boolean.TRUE, empty.next() ); + assertEquals( Boolean.TRUE, firstItemIterable.getFirst() ); + assertEquals( true, empty.hasNext() ); + assertEquals( Boolean.FALSE, empty.next() ); + assertEquals( Boolean.TRUE, firstItemIterable.getFirst() ); + assertEquals( false, empty.hasNext() ); + try + { + empty.next(); + fail( "Exception expected" ); + } + catch ( Exception e ) + { + assertThat( e, instanceOf( NoSuchElementException.class ) ); + } + assertEquals( Boolean.TRUE, firstItemIterable.getFirst() ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/Neo4jConstraintsTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/Neo4jConstraintsTest.java index 63af479695bdc..f67ade00eb7d7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/Neo4jConstraintsTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/Neo4jConstraintsTest.java @@ -375,8 +375,8 @@ public void testIllegalPropertyType() fail( "Shouldn't validate" ); } catch ( Exception e ) - { - } // good + { // good + } setTransaction( getGraphDb().beginTx() ); try { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/NodeTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/NodeTest.java index 1bf2bc8ad34ce..5e5d8ac819645 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/core/NodeTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/core/NodeTest.java @@ -96,7 +96,7 @@ public void testNodeCreateAndDelete() getGraphDb().getNodeById( nodeId ); fail( "Node[" + nodeId + "] should be deleted." ); } - catch ( NotFoundException e ) + catch ( NotFoundException ignored ) { } } @@ -127,7 +127,7 @@ public void testNodeAddProperty() node1.setProperty( null, null ); fail( "Null argument should result in exception." ); } - catch ( IllegalArgumentException e ) + catch ( IllegalArgumentException ignored ) { } String key1 = "key1"; @@ -177,7 +177,7 @@ public void testNodeRemoveProperty() fail( "Remove of non existing property should return null" ); } } - catch ( NotFoundException e ) + catch ( NotFoundException ignored ) { } try @@ -185,7 +185,7 @@ public void testNodeRemoveProperty() node1.removeProperty( null ); fail( "Remove null property should throw exception." ); } - catch ( IllegalArgumentException e ) + catch ( IllegalArgumentException ignored ) { } @@ -198,7 +198,7 @@ public void testNodeRemoveProperty() node1.removeProperty( null ); fail( "Null argument should result in exception." ); } - catch ( IllegalArgumentException e ) + catch ( IllegalArgumentException ignored ) { } @@ -245,7 +245,7 @@ public void testNodeChangeProperty() node1.setProperty( null, null ); fail( "Null argument should result in exception." ); } - catch ( IllegalArgumentException e ) + catch ( IllegalArgumentException ignored ) { } catch ( NotFoundException e ) @@ -306,7 +306,7 @@ public void testNodeGetProperties() node1.getProperty( key1 ); fail( "get non existing property din't throw exception" ); } - catch ( NotFoundException e ) + catch ( NotFoundException ignored ) { } try @@ -314,7 +314,7 @@ public void testNodeGetProperties() node1.getProperty( null ); fail( "get of null key din't throw exception" ); } - catch ( IllegalArgumentException e ) + catch ( IllegalArgumentException ignored ) { } assertTrue( !node1.hasProperty( key1 ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/RWLockCompatibility.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/RWLockCompatibility.java index 82a37854b405f..ca654d55e2e37 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/RWLockCompatibility.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/locking/RWLockCompatibility.java @@ -269,9 +269,8 @@ public void run() } } } - catch ( DeadlockDetectedException e ) + catch ( DeadlockDetectedException ignored ) { - } finally { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/ManualAcquireLockTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/ManualAcquireLockTest.java index ee033d9d60881..61a861cbed2f0 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/ManualAcquireLockTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/transaction/ManualAcquireLockTest.java @@ -76,7 +76,7 @@ public void releaseReleaseManually() throws Exception worker.setProperty( node, key, "ksjd" ); fail( "Shouldn't be able to grab it" ); } - catch ( Exception e ) + catch ( Exception ignored ) { } nodeLock.release(); diff --git a/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java b/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java index 0593268b65641..93ec02384f7e4 100644 --- a/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/index/IndexConstraintsTest.java @@ -107,7 +107,7 @@ public void testMultipleCreate() throws InterruptedException ecs.take().get(); ++numSucceeded; } - catch ( ExecutionException e ) + catch ( ExecutionException ignored ) { } } diff --git a/community/server/src/test/java/org/neo4j/server/WebTestUtils.java b/community/server/src/test/java/org/neo4j/server/WebTestUtils.java deleted file mode 100644 index 21d09b3524034..0000000000000 --- a/community/server/src/test/java/org/neo4j/server/WebTestUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.server; - -import java.io.IOException; -import java.net.DatagramSocket; -import java.net.ServerSocket; - -public class WebTestUtils -{ - - private static boolean available( int port ) - { - if ( port < 1111 || port > 9999 ) - { - throw new IllegalArgumentException( "Invalid start port: " + port ); - } - - try ( ServerSocket ss = new ServerSocket( port ); - DatagramSocket ds = new DatagramSocket( port ) ) - { - ss.setReuseAddress( true ); - ds.setReuseAddress( true ); - return true; - } - catch ( IOException e ) - { - } - - return false; - } - - public static int nextAvailablePortNumber() - { - int nonPriveledgedPortNumber = 1111; - while ( !available( nonPriveledgedPortNumber ) ) - { - nonPriveledgedPortNumber++; - } - return nonPriveledgedPortNumber; - } -} diff --git a/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java b/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java index 451ee52227f8f..6a0eb0ae82f9a 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java +++ b/community/server/src/test/java/org/neo4j/server/rest/transactional/Neo4jJsonCodecTest.java @@ -134,7 +134,7 @@ public void testPathWriting() throws IOException { jsonCodec.writeValue( jsonGenerator, path ); } - catch ( Exception e ) + catch ( Exception ignored ) { } @@ -155,7 +155,7 @@ public void testIteratorWriting() throws IOException { jsonCodec.writeValue( jsonGenerator, Arrays.asList( propertyContainer ) ); } - catch ( Exception e ) + catch ( Exception ignored ) { } @@ -176,7 +176,7 @@ public void testByteArrayWriting() throws IOException { jsonCodec.writeValue( jsonGenerator, byteArray ); } - catch ( Exception e ) + catch ( Exception ignored ) { } @@ -196,7 +196,7 @@ public void testMapWriting() throws IOException { jsonCodec.writeValue( jsonGenerator, new HashMap() ); } - catch ( Exception e ) + catch ( Exception ignored ) { } diff --git a/community/server/src/test/java/org/neo4j/server/rest/web/DatabaseActionsTest.java b/community/server/src/test/java/org/neo4j/server/rest/web/DatabaseActionsTest.java index e2bf3a51cd9d7..d2b0d0cf6f5df 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/web/DatabaseActionsTest.java +++ b/community/server/src/test/java/org/neo4j/server/rest/web/DatabaseActionsTest.java @@ -483,7 +483,7 @@ public void shouldBeAbleToDeleteARelationship() throws Exception graphdbHelper.getRelationship( relationshipId ); fail(); } - catch ( NotFoundException e ) + catch ( NotFoundException ignored ) { } } diff --git a/community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java b/community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java index 3f42a302073e5..f580ee8ba44ce 100644 --- a/community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java +++ b/community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java @@ -64,14 +64,14 @@ public Response interpretLine( Serializable clientId, String line, Output out ) { out.println( message ); } - catch ( RemoteException e ) + catch ( RemoteException ignored ) { } return new Response( "", Continuation.INPUT_COMPLETE ); } }; } - catch ( RemoteException e ) + catch ( RemoteException ignored ) { } return server; @@ -119,7 +119,7 @@ public Response interpretLine( Serializable clientId, String line, Output out ) { out.println( message ); } - catch ( RemoteException e ) + catch ( RemoteException ignored ) { } return new Response( prompt, line.endsWith( ";" ) ? Continuation.EXCEPTION_CAUGHT @@ -127,7 +127,7 @@ public Response interpretLine( Serializable clientId, String line, Output out ) } }; } - catch ( RemoteException e ) + catch ( RemoteException ignored ) { } return server; diff --git a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/RaftTestNetwork.java b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/RaftTestNetwork.java index d3e3e006d1c15..521450dbb1902 100644 --- a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/RaftTestNetwork.java +++ b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/RaftTestNetwork.java @@ -19,7 +19,6 @@ */ package org.neo4j.coreedge.raft; -import org.neo4j.coreedge.network.Message; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -33,6 +32,8 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.BiFunction; +import org.neo4j.coreedge.network.Message; + public class RaftTestNetwork { private final Map inboundChannels = new HashMap<>(); @@ -107,6 +108,7 @@ public void stop() } catch ( InterruptedException e ) { + Thread.currentThread().interrupt(); } } @@ -118,6 +120,7 @@ public void stop() } catch ( InterruptedException e ) { + Thread.currentThread().interrupt(); } } } diff --git a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/state/CoreStateApplierTest.java b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/state/CoreStateApplierTest.java index b23f4132e6c49..4cef6910a1733 100644 --- a/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/state/CoreStateApplierTest.java +++ b/enterprise/core-edge/src/test/java/org/neo4j/coreedge/raft/state/CoreStateApplierTest.java @@ -46,6 +46,7 @@ public void shouldBeAbortable() throws Exception } catch ( InterruptedException e ) { + Thread.currentThread().interrupt(); } }