-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not override fields already set through constructor in build …
…method
- Loading branch information
1 parent
81726b5
commit 04ad195
Showing
4 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...edInConstructorAreBuildable/AllPublicSettersExceptThoseUsedInConstructorAreBuildable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.jonasg.bob.test; | ||
|
||
import io.jonasg.bob.Buildable; | ||
|
||
@Buildable | ||
public class AllPublicSettersExceptThoseUsedInConstructorAreBuildable { | ||
private String make; | ||
|
||
private int year; | ||
|
||
private double engineSize; | ||
|
||
private boolean isElectric; | ||
|
||
private float fuelEfficiency; | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable() { | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable(String make, int year) { | ||
this.make = make; | ||
this.year = year; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable setEngineSize(double engineSize) { | ||
this.engineSize = engineSize; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable setIsElectric(boolean isElectric) { | ||
isElectric = isElectric; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable setFuelEfficiency(float fuelEfficiency) { | ||
this.fuelEfficiency = fuelEfficiency; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable setMake(String make) { | ||
this.make = make; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable setYear(int year) { | ||
this.year = year; | ||
return this; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ructorAreBuildable/Expected_AllPublicSettersExceptThoseUsedInConstructorAreBuildable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.jonasg.bob.test.builder; | ||
|
||
import io.jonasg.bob.test.AllPublicSettersExceptThoseUsedInConstructorAreBuildable; | ||
import java.lang.String; | ||
|
||
public final class AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder { | ||
private String make; | ||
|
||
private int year; | ||
|
||
private double engineSize; | ||
|
||
private boolean isElectric; | ||
|
||
private float fuelEfficiency; | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder() { | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder make(String make) { | ||
this.make = make; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder year(int year) { | ||
this.year = year; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder engineSize( | ||
double engineSize) { | ||
this.engineSize = engineSize; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder isElectric( | ||
boolean isElectric) { | ||
this.isElectric = isElectric; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildableBuilder fuelEfficiency( | ||
float fuelEfficiency) { | ||
this.fuelEfficiency = fuelEfficiency; | ||
return this; | ||
} | ||
|
||
public AllPublicSettersExceptThoseUsedInConstructorAreBuildable build() { | ||
var instance = new AllPublicSettersExceptThoseUsedInConstructorAreBuildable(make, year); | ||
instance.setEngineSize(this.engineSize); | ||
instance.setIsElectric(this.isElectric); | ||
instance.setFuelEfficiency(this.fuelEfficiency); | ||
return instance; | ||
} | ||
} |