I am doing an assignment for a course, I need to get full coverage of this method
public void ourcompanyname(String companyName) {
if (companyName == ("")) {
throw new AirlineException("Warning. The company must have a name !");}
---->This is the constructor
public String getCompanyName() {
return companyName;
}
/**
* @param companyName the companyName to set
*/
public void setCompanyName(String companyName) {
this.companyName = companyName;
----->And this is the test I used
public void testSet() throws AirlineException {
airlinecompany.setCompanyName((""));
Assertions.assertEquals((""),airlinecompany.getCompanyName());
Assertions.assertThrows(AirlineException.class,()->airlinecompany.ourcompanyname(("")));
----->The problem is that I get 50% coverage when testing this code. The ("") string represents a blank field, thus when you don't fill in the name, you get an AirlineException. But I also want to test it for a string like "FLYAIR", that should not throw an exception. What choices do I have ? Better coding for the blank field ("") or just changes to this one ?
Many thanx in advance !