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
Class<?> clazz = Image.class; | |
Object imageInstance = clazz.newInstance(); | |
Field descriptionField = imageInstance | |
.getClass().getDeclaredField("description"); | |
descriptionField.setAccessible(true); | |
descriptionField | |
.set(imageInstance, "Pen Pineapple Apple Pen"); |
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
public void save(boolean validationRequired) { | |
if (validationRequired) { | |
validate(); | |
store(); | |
} else { | |
store(); | |
} | |
} |
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
//Stamp coupling | |
public EmployeeAddress findAddressFor(EmployeeData employeeData) { | |
EmployeeAddress address = repository | |
.findByEmployeeId(employeeData.getId()) | |
//method body | |
return address; | |
} | |
//Data coupling |
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
public class CoincidentalCohesion { | |
public void log(Exception e) { | |
//method body | |
} | |
public void sendMessage(Recepient recepient) { | |
//method body | |
} | |
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
public class MathUtils { | |
public static double sin(double a) { | |
//method's body | |
return sin; | |
} | |
public static double cos(double a) { | |
//method's body | |
return sin; |
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
public class DocsInitializer { | |
public void createBaseDirectoryStructure() { | |
//creating required directory structure | |
} | |
public void cacheDefaults() { | |
//caching required defaults | |
} | |
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
public class DocsRepository { | |
public Doc findById(DocId id) { | |
//method's body | |
return doc; | |
} | |
public Doc save(Doc document) { | |
//method's body | |
return doc; |
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
public class PolishTaxPolicy implements TaxPolicy { | |
public Money calculateTax(Money amount) { | |
//method body | |
return tax; | |
} | |
} |
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
test 'change advertisement content' do | |
advertisement_id = SecureRandom.random_number | |
author_id = SecureRandom.random_number | |
new_content = "Random content: #{SecureRandom.hex}" | |
command_bus.(PublishAdvertisement.new(advertisement_id, author_id)) | |
assert_events( | |
"Advertisement$#{advertisement_id}", | |
ContentHasChanged.new(data: {content: new_content}) | |
) do |
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
def assert_events(stream_name, *expected_events) | |
scope = Rails.configuration.event_store.read.stream(stream_name) | |
before = scope.last | |
yield | |
actual_events = before.nil? ? scope.to_a : scope.from(before.event_id).to_a | |
to_compare = ->(ev) { { type: ev.event_type, data: ev.data } } | |
assert_equal expected_events.map(&to_compare), | |
actual_events.map(&to_compare) | |
end |
OlderNewer