Upgrade to Pro — share decks privately, control downloads, hide ads and more …

`Huh?` to `Aha!`: A Refactoring Story

`Huh?` to `Aha!`: A Refactoring Story

## Abstract
**As a Dev, I need to Refactor, to make codebase Refactorable**. Let's achieve this goal through a least spoken, yet most effective Method - **Component Isolation**. Let's discuss how to overcome major **Obstacles** that hinder this goal, and **Metrics** that help measure our success.

## Audience & Take-aways
- This applies to software developers at all levels. I use **Java** to demonstrate the code snippets, but this talk is about Software Design and is agnostic of programming language.
- Refactoring is **NOT** moving lines of code around with IDE shortcuts. The **USP** for this talk is, it takes a unique approach to Refactoring i.e., Component Isolation and provides persuasive arguments against factors that cause __quantum-entanglement__ among components.
- Take-aways for the audiences are:
- How isolated components can build long-lasting structures, keeping rate of entropy growth in check.
- How to use **MOM** process (Methods, Obstacles and Metrics), to build a case for your Refactoring story and pitch it to your team and Manager for funding.
- How to eliminate __Exceptions__ from your code using **ADTs (Algebraic Data Types)**.
- How to replace __Shared Global mutable state on your Shared Code__ with **Immutability** and **Data Transformations**.
- Demo a hello-real-world service with these problems and how applying these simple methods can change the face of this service, thereby reducing the cognitive complexity and organically boosting the testability.
- Metric-driven approach to objectively realize the results and improvements achieved.

5b88ad20a23d5cacecb20eb80f5f69d8?s=128

Gopal S Akshintala

June 21, 2021
Tweet

Transcript

  1. ! H ? t A ! A ef ct ri

    g to y 1
  2. I'm G pa S ks in al ! S S

    e E r @ S r ! @G s a ! o l .g 2
  3. W at’s ef ct ri g? @GopalAkshintala overfullstack.ga 3

  4. W at’s ef ct ri g? @GopalAkshintala overfullstack.ga 4

  5. A a ev, I ee t R fa to ,

    t m ke od ba e ef ct ra le @GopalAkshintala overfullstack.ga 5
  6. @GopalAkshintala overfullstack.ga 6

  7. H w o it h ou S or f r

    un in ? @GopalAkshintala overfullstack.ga 7
  8. M th ds O st cl s M tr cs

    @GopalAkshintala overfullstack.ga 8
  9. M th ds ! Human Readability ! Component Isolation @GopalAkshintala

    overfullstack.ga 9
  10. O st cl s ! Exceptions ! Mutability @GopalAkshintala overfullstack.ga

    10
  11. M tr cs ! Cognitive Complexity ! Testability @GopalAkshintala overfullstack.ga

    11
  12. Methods Metrics ! Human Readability " Cognitive Complexity ! Component

    Isolation " Testability Obstacles ! Exceptions ! Mutability @GopalAkshintala overfullstack.ga 12
  13. L t's ta t it o r O st cl

    s @GopalAkshintala overfullstack.ga 13
  14. O st cl - 1 E ce ti ns @GopalAkshintala

    overfullstack.ga 14
  15. E ce ti ns re he os A us d

    l ng ag f at re Catch or Rethrow anything try { !!" } catch(NullPointerException | IllegalArgumentException | IndexOutOfBoundsException e) { e.printStackTrace(); } try { !!" } catch(Exception e) { throw e; } @GopalAkshintala overfullstack.ga 15
  16. O st cl - 1 - E ce ti ns

    E ce ti ns re or ho es ! @GopalAkshintala overfullstack.ga 16
  17. I Es @GopalAkshintala overfullstack.ga 17

  18. E ce ti ns re or ho es Tightly coupled

    to not just the caller, but the entire call hierarchy void verifyUserAccess(String userId) throws NoAccessException { if (!hasAccess1(userId)) { throw new NoAccessException(ACCESS_1); } if (!hasAccess2(userId)) { throw new NoAccessException(ACCESS_2); } if (!hasAccess3(userId)) { throw new NoAccessException(ACCESS_3); } } @GopalAkshintala overfullstack.ga 18
  19. I’m so at d ! Optional<NoAccessException> verifyUserAccess(String userId) { if

    (!hasAccess1(userId)) { return Optional.of(new NoAccessException(ACCESS_1)); } if (!hasAccess2(userId)) { return Optional.of(new NoAccessException(ACCESS_2)); } if (!hasAccess3(userId)) { return Optional.of(new NoAccessException(ACCESS_3)); } return Optional.empty(); } @GopalAkshintala overfullstack.ga 19
  20. R pl ce xc pt on w th DT ‣

    Optional - some OR none ‣ Tuple (VAVR) - 1 WITH/AND 2 ‣ Either (VAVR) - left OR right ‣ With the advent of Pattern Matching in Java 16+, these blend more naturally! @GopalAkshintala overfullstack.ga 20
  21. E ce ti ns is se t r tu n

    ul ip e D ta yp s int parse(String s) { if (s.matches("-?[0-9]+")) { return Integer.parseInt(s); } throw new NumberFormatException("Not a valid integer"); } @GopalAkshintala overfullstack.ga 21
  22. R pl ce xc pt on it E th r

    !" Before int parse(String s) { if (s.matches("-?[0-9]+")) { return Integer.parseInt(s); } throw new NumberFormatException("Not a valid integer"); } !" After Either<NumberFormatException, Integer> parse(String s) { if (s.matches("-?[0-9]+")) { return Either.right(Integer.parseInt(s)); } return Either.left(new NumberFormatException("Not a valid integer")); } @GopalAkshintala overfullstack.ga 22
  23. O st cl - 1 - E ce ti ns

    T ro a ay xc pt on @GopalAkshintala overfullstack.ga 23
  24. O st cl - 2 M ta le ta e

    @GopalAkshintala overfullstack.ga 24
  25. S ar d ut bl s at @GopalAkshintala overfullstack.ga 25

  26. S ar d ut bl s at o a S

    ar d od ba e @GopalAkshintala overfullstack.ga 26
  27. O st cl - 2 - M ta il ty

    M ta le bj ct a I pu P ra s ou le om on nt @GopalAkshintala overfullstack.ga 27
  28. static int sum(List<Integer> nums) { int result = 0; for

    (int num : nums) result += num; return result; } @GopalAkshintala overfullstack.ga 28
  29. static int sumAbsolute(List<Integer> nums) { for (int i = 0;

    i < nums.size(); i!") { nums.set(i, Math.abs(nums.get(i))); } return sum(nums); !# DRY } @GopalAkshintala overfullstack.ga 29
  30. static void client() { var nums = Arrays.asList(-2, 5, -6);

    System.out.println(sumAbsolute(nums)); } ! GA release! "# @GopalAkshintala overfullstack.ga 30
  31. static void client() { var nums = Arrays.asList(-2, 5, -6);

    System.out.println(sumAbsolute(nums)); System.out.println(sum(nums)); !" 13 } @GopalAkshintala overfullstack.ga 31
  32. static int sumAbsolute(List<Integer> nums) { for (int i = 0;

    i < nums.size(); i!") { nums.set(i, Math.abs(nums.get(i))); !# Latent Bug } return sum(nums); !# DRY } static void client() { List<Integer> nums = Arrays.asList(-2, 5, -6); System.out.println(sumAbsolute(nums)); System.out.println(sum(nums)); !# } @GopalAkshintala overfullstack.ga 32
  33. O st cl - 2 - M ta il ty

    M ta le bj ct a i pu p ra s s nh ly f r so at on @GopalAkshintala overfullstack.ga 33
  34. O st cl - 2 - M ta il ty

    H w bo t ut bl O je ts a et rn yp s? @GopalAkshintala overfullstack.ga 34
  35. M ta le bj ct a R tu n yp

    s Date getEggLayingDate(int eggId) { !" heavy operation return queryEggLayingDateFromDB(eggId); } @GopalAkshintala overfullstack.ga 35
  36. !" Dependent component - 1 boolean isLaidInFirstHalf(int eggId) { var

    layingDate = getEggLayingDate(eggId); if (layingDate.getDate() < 15) { return true; } return false; } !" Dependent component - 2 int calculateEggAge(int eggId, Date today) { return today.getDate() - getEggLayingDate(eggId).getDate(); } @GopalAkshintala overfullstack.ga 36
  37. O e ay! !" Dependent component - 1 boolean isLaidInFirstHalf(int

    eggId) { var layingDate = getEggLayingDate(eggId); if (layingDate.getDate() < 15) { !" It's just logging, let's reuse the same Date obj for month and year layingDate.setDate(15); logger.info("This egg was laid before: " + layingDate); return true; } return false; } @GopalAkshintala overfullstack.ga 37
  38. A ot er ay! static final Map<Integer, Date> eggLayingDateCacheById =

    new HashMap!"(); !# Cache Date getEggLayingDate(int eggId) { return eggLayingDateCacheById .computeIfAbsent(eggId, this!$queryEggLayingDateFromDB); } @GopalAkshintala overfullstack.ga 38
  39. A ot er ay! !" Dependent component - 1 boolean

    isLaidInFirstHalf1(int eggId) { var layingDate = getEggLayingDate(eggId); if (layingDate.getDate() < 15) { !" It's just logging, let's reuse the same Date obj for month and year layingDate.setDate(15); !" Mutation ! logger.info("This egg was laid before: " + layingDate); return true; } return false; } !" Dependent component - 2 long calculateEggAge(int eggId, Date today) { return today.getDate() - getEggLayingDate(eggId).getDate(); !" What did I do? } @GopalAkshintala overfullstack.ga 39
  40. O st cl - 2 - M ta il ty

    T at’s ua tu E ta gl me t ⚛ @GopalAkshintala overfullstack.ga 40
  41. P in er E er wh re! @GopalAkshintala overfullstack.ga 41

  42. O st cl - 2 - M ta il ty

    B t hy s ut bi it p ed mi an i J va od ? @GopalAkshintala overfullstack.ga 42
  43. P we o D fa lt M ta il ty

    s he ef ul m de n av @GopalAkshintala overfullstack.ga 43
  44. O st cl - 2 - M ta il ty

    M ke mm ta il ty ou D fa lt @GopalAkshintala overfullstack.ga 44
  45. I t ke D sc pl ne o ea t

    e ef ul 1 1 Designed by rawpixel.com / Freepik @GopalAkshintala overfullstack.ga 45
  46. S me ui k in ! ‣ Make a habit

    to use final before var and function params. ‣ Follow Immutable strategy for POJOs from Oracle’s Documentation ‣ Auto-generate Immutable version of your POJO using: ‣ Lombok (More Magic, Less Effort) ‣ Google Auto (Less Magic, More Effort) ‣ Immutables (Less Magic, More Effort) @GopalAkshintala overfullstack.ga 46
  47. O st cl - 2 - M ta il ty

    W at o nt -I mu ab es s y? @GopalAkshintala overfullstack.ga 47
  48. O st cl - 2 - M ta il ty

    - A ti-i mu ab es I n't mm ta il ty nl f r ul i-t re di g? @GopalAkshintala overfullstack.ga 48
  49. I mu ab li y sn't nl f r C

    nc rr nc @GopalAkshintala overfullstack.ga 49
  50. O st cl - 2 - M ta il ty

    - A ti-i mu ab es I mu ab e bj ct d es ’t t y mp ra iv s yl ! @GopalAkshintala overfullstack.ga 50
  51. M ta il ty & I pe at vi y

    re ri nd ! @GopalAkshintala overfullstack.ga 51
  52. M ta il ty ik s o e it I

    pe at vi y void mutableFn() { var mutableList = Arrays.asList("a", "b", "c"); mutateList(mutableList); } List<String> mutateList(List<String> list) { for (var i = 0; i < list.size(); i!") { list.set(i, list.get(i).toUpperCase()); } return list; } @GopalAkshintala overfullstack.ga 52
  53. I pe at ve ut ti ns ep ac d

    y D cl ra iv T an fo ma io s void immutableFn() { final var immutableList = List.of("a", "b", "c"); transformList(immutableList); } List<String> transformList(final List<String> list) { !" `toList()` is new in Java 16 to collect Stream into UnmodifiableList. return list.stream().map(String!#toUpperCase).toList(); } @GopalAkshintala overfullstack.ga 53
  54. I mu ab li y & T an fo ma

    io a e C up e! N C oi e! @GopalAkshintala overfullstack.ga 54
  55. I mu ab li y or es ra sf rm

    ti n void immutableFn() { final var immutableList = List.of("a", "b", "c"); !" ! Throws UnsupportedOperationException mutateList(immutableList); } @GopalAkshintala overfullstack.ga 55
  56. O st cl - 2 - M ta il ty

    - A ti-i mu ab es D es 't mm ta il ty e t er ? @GopalAkshintala overfullstack.ga 56
  57. I mu ab li y nd er or an e

    ctrl-c + ctrl-v from Oracle’s Documentation ‣ The impact of object creation is often overestimated. ‣ It can be offset by decreased overhead due to garbage collection. @GopalAkshintala overfullstack.ga 57
  58. J va’s mb ac ng mm ta il ty, s

    ow y ‣ Most used Data type in any Java application? ‣ String - No coincedence that it’s Immutable. ‣ Java 8 replaced Date with immutable LocalDate. ‣ Java 11 introduced Immutable Collections. ‣ Java 16 introduced a concise Stream operation toList for UnmodifiableList. ‣ And many moreH @GopalAkshintala overfullstack.ga 58
  59. H ll R al or d @GopalAkshintala overfullstack.ga 59

  60. @GopalAkshintala overfullstack.ga 60

  61. @GopalAkshintala overfullstack.ga 61

  62. @GopalAkshintala overfullstack.ga 62

  63. H w as he od ? @GopalAkshintala overfullstack.ga 63

  64. H w as he od ? ! void filterDuplicates(Map<ID, Failure>

    failureMap, List<Egg> eggsFromRequest) {!!"} void validate(Map<ID, Failure> failureMap, List<Egg> nonDuplicateEggs) {!!"} List<EggEntity> toEntityObjs(List<Egg> validEggs) {!!"} void bulkInsertIntoDB(List<EggEntity> eggEntityObjs) throws DMLOperationException {!!"} @GopalAkshintala overfullstack.ga 64
  65. P rt ti n et ee S ep filterDuplicates(failureMap, eggsFromRequest);

    !!" !!" !# Partition `eggsFromRequest` using `failureMap` !# into `duplicateEggs`, `nonDuplicateEggs` !!" !!" validate(failureMap, nonDuplicateEggs); @GopalAkshintala overfullstack.ga 65
  66. P rt ti n et ee S ep filterDuplicates(failureMap, eggsFromRequest);

    !" Partition var nonDuplicateEggs = new ArrayList<Egg>(); for (Egg egg : eggsFromRequest) { if (!failureMap.containsKey(egg.getId())) { nonDuplicateEggs.add(egg); } } validate(failureMap, nonDuplicateEggs); @GopalAkshintala overfullstack.ga 66
  67. H w as t? ! filterDuplicates(failureMap, eggsFromRequest); !!" !# Partition

    !!" validate(failureMap, nonDuplicateEggs); !!" !# Partition !!" var eggEntityObjs = toEntityObjs(validEggs); try { bulkInsertIntoDB(eggEntityObjs); } catch (DMLOperationException ex) { handlePartialFailures(failureMap, ex); } !# Prepare response from `failureMap` and db insertion results @GopalAkshintala overfullstack.ga 67
  68. H w t's ef ct re i to ! @GopalAkshintala

    overfullstack.ga 68
  69. T e ig at re hi t !" Before void

    filterDuplicates(Map<ID, Failure> failureMap, List<Egg> eggsFromRequest) {!!#} !" After static List<Either<Tuple2<ID, Failure>, ImmutableEgg!$ filterDuplicates( final List<ImmutableEgg> eggsFromRequest) {!!#} @GopalAkshintala overfullstack.ga 69
  70. U in E th r or ar ia F il

    re List<Either<Tuple2<ID, Failure>, ImmutableEgg>> @GopalAkshintala overfullstack.ga 70
  71. P rt al ai ur s ow s re m

    ↡ List<Either<Tuple2<ID, Failure>, ImmutableEgg>> @GopalAkshintala overfullstack.ga 71
  72. V li at ng n it er !" Before void

    validate(Map<ID, Failure> failureMap, List<Egg> nonDuplicateEggs) {!!#} !" Before static Either<Tuple2<ID, Failure>, ImmutableEgg> validate( final Either<Tuple2<ID, Failure>, ImmutableEgg> egg) {!!#} @GopalAkshintala overfullstack.ga 72
  73. V li at ng n it er static Either<Tuple2<ID, Failure>,

    ImmutableEgg> validate( Either<Tuple2<ID, Failure>, ImmutableEgg> eggToValidate) { return eggToValidate !" No validations execute if egg is Either.left .flatMap(validateAge) .flatMap(validateField1) !!# !!# ; } @GopalAkshintala overfullstack.ga 73
  74. 74

  75. R fa to ed - N S ri gs tt

    ch d! !" void filterDuplicates(Map<ID, Failure> failureMap, !" List<Egg> eggsFromRequest) {!!#} static List<Either<Tuple2<ID, Failure>, ImmutableEgg!$ filterDuplicates( final List<ImmutableEgg> eggsFromRequest) {!!#} !" void validate(Map<ID, Failure> failureMap, !" List<Egg> nonDuplicateEggs) {!!#} static Either<Tuple2<ID, Failure>, ImmutableEgg> validate( final Either<Tuple2<ID, Failure>, ImmutableEgg> egg) {!!#} !" List<EggEntity> toEntityObjs(List<Egg> validEggs) {!!#} static Either<Tuple2<ID, Failure>, EggEntity> toEntityObj( final Either<Tuple2<ID, Failure>, ImmutableEgg> egg) {!!#} !" Partition !" void bulkInsertIntoDB(List<EggEntity> eggEntityObjs) !" throws DMLOperationException {!!#} static Either<DMLOperationException, List<EggEntity!$ bulkInsertIntoDB( final List<EggEntity> eggEntityObjs) {!!#} @GopalAkshintala overfullstack.ga 75
  76. L ke M th er va io static List<Either<Tuple2<ID, Failure>,

    ImmutableEgg!" filterDuplicates( final List<ImmutableEgg> eggsFromRequest) {!!#} static Either<Tuple2<ID, Failure>, ImmutableEgg> validate( final Either<Tuple2<ID, Failure>, ImmutableEgg> egg) {!!#} static Either<Tuple2<ID, Failure>, EggEntity> toEntityObj( final Either<Tuple2<ID, Failure>, ImmutableEgg> egg) {!!#} !$ Partition static Either<DMLOperationException, List<EggEntity!" bulkInsertIntoDB( final List<EggEntity> eggEntityObjs) {!!#} @GopalAkshintala overfullstack.ga 76
  77. L t’s la s me eg @GopalAkshintala overfullstack.ga 77

  78. F nc io C mp si io final var partition

    = filterDuplicates(immutableEggsFromRequest).stream() .map(EggService!"validate) .map(EggService!"toEntityObj) .collect(Collectors.partitioningBy(Either!"isRight)); final var objsToInsert = partition.get(true).stream().map(Either!"get).toList(); final var results = bulkInsertIntoDB(objsToInsert); !# Prepare response from `partition.get(false)` and `results` @GopalAkshintala overfullstack.ga 78
  79. H w re e oi g n ur oa ?

    L t's sk ur et ic @GopalAkshintala overfullstack.ga 79
  80. M tr c - 1 C gn ti e om

    le it @GopalAkshintala overfullstack.ga 80
  81. C gn ti el C mp ex filterDuplicates(failureMap, eggsFromRequest); !!"

    !# Partition !!" validate(failureMap, nonDuplicateEggs); !!" !# Partition !!" var eggEntityObjs = toEntityObjs(validEggs); try { bulkInsertIntoDB(eggEntityObjs); } catch (DMLOperationException ex) { handlePartialFailures(failureMap, ex); } !# Prepare response from `failureMap` and db insertion results @GopalAkshintala overfullstack.ga 81
  82. D d e ⊗ C gn ti e om le

    it ? final var partition = filterDuplicates(immutableEggsFromRequest).stream() .map(EggService!"validate) .map(EggService!"toEntityObj) .collect(Collectors.partitioningBy(Either!"isRight)); final var objsToInsert = partition.get(true).stream().map(Either!"get).toList(); final var results = bulkInsertIntoDB(objsToInsert); !# Prepare response from `partition.get(false)` and `results` @GopalAkshintala overfullstack.ga 82
  83. @GopalAkshintala overfullstack.ga 83

  84. C mp ex ty ‣ Different types ‣ Accidental Complexity

    ‣ Essential complexity ‣ Cognitive/Cyclomatic complexity ‣ Different layers ‣ Unfamiliarity vs Unreadability. ‣ Strict vs Non-extensible. @GopalAkshintala overfullstack.ga 84
  85. C mp ex ty er ! final var partition =

    filterDuplicates(immutableEggsFromRequest).stream() .map(EggService!"validate) .map(EggService!"toEntityObj) .collect(Collectors.partitioningBy(Either!"isRight)); final var objsToInsert = partition.get(true).stream().map(Either!"get).toList(); final var results = bulkInsertIntoDB(objsToInsert); !# Prepare response from `partition.get(false)` and `results` ! Essential Complexity ! Unfamiliarity ! Strictness @GopalAkshintala overfullstack.ga 85
  86. ! S na Qu e™ T O je ti el

    m as re og it ve om le it ! My previous talks, on the usage of SonarQube™: ! Java Version ! Kotlin Version @GopalAkshintala overfullstack.ga 86
  87. M tr c - 2 T st bi it @GopalAkshintala

    overfullstack.ga 87
  88. B os y ur es ab li y @GopalAkshintala overfullstack.ga

    88
  89. !" * EggEntity is a legacy class and cannot be

    instantiated with `new` void fillEntityObj(Egg egg, EggEntity eggEntity) { if (egg.field1() !# null) { eggEntity.put(Fields.field1, egg.field1()); } if (egg.field2() !# null) { eggEntity.put(Fields.field2, egg.field2()); } if (egg.field3() !# null) { eggEntity.put(Fields.field3, egg.field3()); } } @GopalAkshintala overfullstack.ga 89
  90. B it le es @Test void fillEntityObjTest() { !" *

    `EggEntity` Object can't be instantiated in a JUnit context. final var mockEggEntity = mock(EggEntity.class); var egg = new Egg("field1Value", null, "field3Value"); fillEntityObj(egg, mockEggEntity); verify(mockEggEntity).put(Fields.field1,"field1Value"); verify(mockEggEntity, never()).put(Fields.field2, null); verify(mockEggEntity).put(Fields.field3,"field3Value"); } @GopalAkshintala overfullstack.ga 90
  91. B os y ur es ab li y U it

    es !== T st nt rn ls @GopalAkshintala overfullstack.ga 91
  92. B os y ur es ab li y U it

    es === E2E es f r he ni @GopalAkshintala overfullstack.ga 92
  93. B os y ur es ab li y S pa

    at S at c ro S gn l @GopalAkshintala overfullstack.ga 93
  94. S pa at S at c ro S gn l

    ‣ Static: 1-1 field mapping between Egg to EggEntity ‣ Signal: For each field mapping, fill non-null Egg fields into EggEntity using put. @GopalAkshintala overfullstack.ga 94
  95. S pa at S at c ro S gn l

    !" Static static final Map<String, Function<ImmutableEgg, String!# fieldMapping = Map.of( Fields.field1, ImmutableEgg!$field1, Fields.field2, ImmutableEgg!$field2, Fields.field3, ImmutableEgg!$field3); !" Call with Static data and Function reference fillEntityObj(egg, fieldMapping, EggEntity!$put); !" Signal static void fillEntityObj( ImmutableEgg egg, Map<String, Function<ImmutableEgg, String!# fieldMapping BiConsumer<String, String> filler) { fieldMapping.forEach((fieldId, valueGetter) !% { final var fieldValue = valueGetter.apply(egg); if (fieldValue !& null) { filler.accept(fieldId, fieldValue); } }); } @GopalAkshintala overfullstack.ga 95
  96. T st nl t at at er @Test void fillEntityObjTest()

    { final var egg = ImmutableEgg.of("field1Value", null, "field3Value"); var actualPairs = new HashMap<String, String>(); fillEntityObj(egg, actualPairs!"put); var expectedPairs = Map.of( Fields.field1, "field1Value", Fields.field3, "field3Value"); assertEquals(expectedPairs, actualPairs); } @GopalAkshintala overfullstack.ga 96
  97. B os y ur es ab li y D @GopalAkshintala

    overfullstack.ga 97
  98. T y ot o nj ct nt re bj ct

    @Autowired public EggService( !!", @Qualifier(EGG_REPO) EggRepo eggRepo, !!" ) @GopalAkshintala overfullstack.ga 98
  99. I je t nl t e un ti n @Autowired

    public EggService( !!", !# @Qualifier(EGG_REPO) !# EggRepo eggRepo, @Qualifier(EGG_INSERTER) Function<EggEntity, ID> dbInserter, !!" ) @GopalAkshintala overfullstack.ga 99
  100. P rt & A ap er /C ea A ch

    te tu e w th ut xt a nt rf ce @Autowired public EggService( !!", !# @Qualifier(EGG_REPO) !# EggRepo eggRepo, @Qualifier(EGG_INSERTER) Function<EggEntity, ID> dbInserter, !!" ) !# Original Config @Bean(EGG_INSERTER) public Function<EggEntity, ID> insert( @Qualifier(EGG_REPO) EggRepo eggRepo) { return eggRepo!$insert; } !# Test Config @Bean(EGG_INSERTER) public Function<EggEntity, ID> insertNoOp() { return eggEntity !% new ID(1); !#stub } @GopalAkshintala overfullstack.ga 100
  101. M tr c - 2 - T st bi it

    T st bi it F rs T st ov ra e ol ow @GopalAkshintala overfullstack.ga 101
  102. M tr c - 2 - T st bi it

    T st ! R fa to (L st ut ot he as ) @GopalAkshintala overfullstack.ga 102
  103. @GopalAkshintala overfullstack.ga 103

  104. @GopalAkshintala overfullstack.ga 104

  105. @GopalAkshintala overfullstack.ga 105

  106. R fa to I cr me ta ly A p

    es ri ed y DD @GopalAkshintala overfullstack.ga 106
  107. @GopalAkshintala overfullstack.ga 107

  108. ! b t.l /h2a-s id s ⌨ b t.l /h2a-c

    de @GopalAkshintala overfullstack.ga 108
  109. @GopalAkshintala overfullstack.ga 109