RDataUtil { public static String getServiceTypeNameFromRData(String rData) { if(rData == null || rData.trim().isEmpty()) { throw new IllegalArgumentException( "rData cannot be null, empty, or blank" ); } if(rData.contains( Constants.NAME )) { String serviceTypeName = rData.substring(0, rData.indexOf(Constants.NAME)).trim(); if(!serviceTypeName.isEmpty()) { return serviceTypeName; } } throw new IllegalArgumentException( "Could not extract Service Type name from rData" ); } private  RDataUtil(); static String getDnsLabelFromRData(String rData); static String getServiceTypeNameFromRData(String rData); static String getServiceTypeRData(String rData);  }
@Test public void getServiceTypeNameFromRDataTest () { String testRData = ""; testRData = "cool service type" + Constants.NAME; Assert.assertTrue("cool service type".equals( RDataUtil.getServiceTypeNameFromRData( testRData ) )); testRData = "mqtt" + Constants.NAME; Assert.assertTrue("mqtt".equals( RDataUtil.getServiceTypeNameFromRData( testRData ) )); testRData = "mqtt" + Constants.NAME + " "; Assert.assertTrue("mqtt".equals( RDataUtil.getServiceTypeNameFromRData( testRData ) )); testRData = "mqtt" + Constants.NAME + ".asdja898.asd232l.asdflk "; Assert.assertTrue("mqtt".equals( RDataUtil.getServiceTypeNameFromRData( testRData ) )); testRData = "something-with-some-hyphens" + Constants.NAME; Assert.assertTrue("something-with-some-hyphens".equals( RDataUtil.getServiceTypeNameFromRData( testRData ) )); testRData = "iot's awesome service type!" + Constants.NAME; Assert.assertTrue("iot's awesome service type!".equals( RDataUtil.getServiceTypeNameFromRData( testRData ) )); }
@Test(expected = IllegalArgumentException.class) public void nullStringSTTest(){ RDataUtil.getServiceTypeNameFromRData( null ); }
@Test(expected = IllegalArgumentException.class) public void emptyStringSTTest(){ RDataUtil.getServiceTypeNameFromRData( "" ); }
@Test(expected = IllegalArgumentException.class) public void blankStringSTTest(){ RDataUtil.getServiceTypeNameFromRData( " " ); }
@Test(expected = IllegalArgumentException.class) public void nameWithSpacesNoNameLabelTest(){ RDataUtil.getServiceTypeNameFromRData( "cool service type" ); }
@Test(expected = IllegalArgumentException.class) public void nameWithHyphensNoNameLabelTest(){ RDataUtil.getServiceTypeNameFromRData( "something-with-some-hyphens" ); }
@Test(expected = IllegalArgumentException.class) public void mqttNoNameLabelTest(){ RDataUtil.getServiceTypeNameFromRData( "mqtt" ); }
@Test(expected = IllegalArgumentException.class) public void onlyNameLabelTest(){ RDataUtil.getServiceTypeNameFromRData( Constants.NAME ); }
@Test(expected = IllegalArgumentException.class) public void onlyNameAndWhitespaceInFrontLabelTest(){ RDataUtil.getServiceTypeNameFromRData( " " + Constants.NAME ); }