Skip to content

Commit 6b8953b

Browse files
committed
Get rid of empty NetCat constructor. NetCatListener is mandatory.
1 parent 5bef972 commit 6b8953b

File tree

7 files changed

+7
-29
lines changed

7 files changed

+7
-29
lines changed

netcat/src/main/java/com/github/dddpaul/netcat/NetCat.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,11 @@ public class NetCat implements NetCater
1616
protected InputStream input;
1717
protected OutputStream output;
1818

19-
public NetCat() {}
20-
2119
public NetCat( NetCatListener listener )
2220
{
2321
this.listener = listener;
2422
}
2523

26-
@Override
27-
public void setListener( NetCatListener listener )
28-
{
29-
this.listener = listener;
30-
}
31-
3224
@Override
3325
public void setInput( InputStream input )
3426
{

netcat/src/main/java/com/github/dddpaul/netcat/NetCater.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ enum Proto { TCP, UDP }
1717
public void cancel();
1818
public void execute( String ... params );
1919
public void executeParallel( String ... params );
20-
public void setListener( NetCatListener listener );
2120
public void setInput( InputStream input );
2221
public void createOutput();
2322
public void closeOutput();

netcat/src/main/java/com/github/dddpaul/netcat/TcpNetCat.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ public class TcpNetCat extends NetCat
2525
private ServerSocketChannel serverChannel;
2626
private Socket socket;
2727

28-
public TcpNetCat()
29-
{
30-
super();
31-
}
32-
3328
public TcpNetCat( NetCatListener listener )
3429
{
3530
super( listener );

netcat/src/main/java/com/github/dddpaul/netcat/UdpNetCat.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public UdpNetCat( NetCatListener listener )
2323
super( listener );
2424
}
2525

26-
public UdpNetCat()
27-
{
28-
super();
29-
}
30-
3126
@Override
3227
public void cancel()
3328
{

netcat/src/main/java/com/github/dddpaul/netcat/ui/NetCatFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Bundle;
44
import android.support.v4.app.Fragment;
55

6+
import com.github.dddpaul.netcat.NetCatListener;
67
import com.github.dddpaul.netcat.NetCater;
78
import com.github.dddpaul.netcat.TcpNetCat;
89
import com.github.dddpaul.netcat.UdpNetCat;
@@ -34,19 +35,19 @@ public NetCater getNetCat()
3435
return netCat;
3536
}
3637

37-
public NetCater getOrCreateNetCat( Proto proto )
38+
public NetCater getOrCreateNetCat( Proto proto, NetCatListener listener )
3839
{
3940
switch( proto ) {
4041
case TCP:
4142
if( netCat != null && netCat instanceof TcpNetCat ) {
4243
return netCat;
4344
}
44-
return new TcpNetCat();
45+
return new TcpNetCat( listener );
4546
case UDP:
4647
if( netCat != null && netCat instanceof UdpNetCat ) {
4748
return netCat;
4849
}
49-
return new UdpNetCat();
50+
return new UdpNetCat( listener );
5051
}
5152
return null;
5253
}

netcat/src/main/java/com/github/dddpaul/netcat/ui/ResultFragment.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public void onResume()
108108
netCatFragment = (NetCatFragment) getFragmentManager().findFragmentByTag( NETCAT_FRAGMENT_TAG );
109109
if( netCatFragment != null ) {
110110
netCat = netCatFragment.getNetCat();
111-
netCat.setListener( this );
112111
}
113112
}
114113

@@ -203,8 +202,7 @@ public void connect( String connectTo )
203202
return;
204203
}
205204
String[] tokens = connectTo.split( ":" );
206-
netCat = netCatFragment.getOrCreateNetCat( Proto.valueOf( tokens[0] ) );
207-
netCat.setListener( this );
205+
netCat = netCatFragment.getOrCreateNetCat( Proto.valueOf( tokens[0] ), this );
208206
netCat.execute( CONNECT.toString(), tokens[1], tokens[2] );
209207
}
210208

@@ -219,8 +217,7 @@ public void listen( String listenOn )
219217
return;
220218
}
221219
String[] tokens = listenOn.split( ":" );
222-
netCat = netCatFragment.getOrCreateNetCat( Proto.valueOf( tokens[0] ) );
223-
netCat.setListener( this );
220+
netCat = netCatFragment.getOrCreateNetCat( Proto.valueOf( tokens[0] ), this );
224221
netCat.execute( LISTEN.toString(), tokens[1] );
225222
}
226223

netcat/src/test/java/com/github/dddpaul/netcat/ResultFragmentTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.github.dddpaul.netcat.NetCater.*;
2121
import static com.github.dddpaul.netcat.NetCater.Op.CONNECT;
2222
import static com.github.dddpaul.netcat.NetCater.Op.LISTEN;
23-
import static com.github.dddpaul.netcat.NetCater.Proto.*;
2423
import static org.fest.assertions.api.ANDROID.assertThat;
2524
import static org.hamcrest.core.Is.is;
2625
import static org.junit.Assert.assertThat;
@@ -52,7 +51,7 @@ public void setUp()
5251
{
5352
MockitoAnnotations.initMocks( this );
5453
when( netCatFragmentMock.getNetCat() ).thenReturn( netCatMock );
55-
when( netCatFragmentMock.getOrCreateNetCat( any( Proto.class ) ) ).thenReturn( netCatMock );
54+
when( netCatFragmentMock.getOrCreateNetCat( any( Proto.class ), any( NetCatListener.class) ) ).thenReturn( netCatMock );
5655
fragment = new ResultFragment();
5756
}
5857

0 commit comments

Comments
 (0)