Is there any way that InetAddress.getByName( 234324.32423.234234.324234 ) will return a non-null address value? Seems like it does.
Since this happens in a unit test, all I have to do is force InetAddress to throw an exception. Is there any reason why the following mock using PowerMock won't work? I do have the annotations @RunWith(PowerMockRunner.class) and @PrepareForTest({InetAddress.class}) before my class signature
String testIp = "127.0.0.1";
PowerMockito.mockStatic( InetAddress.class );
PowerMockito.when( InetAddress.getByName( testIp ) ).thenThrow( UnknownHostException.class );
MyClass someClassThatCallsInetAddressGetByName = new MyClass( 32 );
someClassThatCallsInetAddressGetByName.setHostAddress( testIp );
someClassThatCallsInetAddressGetByName.getHostAddress();