Skip to content

AF-1227: Adds merge method and merged constructor to ClassNameBuilder class.#167

Merged
aaronlademann-wf merged 3 commits intoWorkiva:masterfrom
kealjones-wk:AF-1227-classnamebuilder-merge
Jul 17, 2018
Merged

AF-1227: Adds merge method and merged constructor to ClassNameBuilder class.#167
aaronlademann-wf merged 3 commits intoWorkiva:masterfrom
kealjones-wk:AF-1227-classnamebuilder-merge

Conversation

@kealjones-wk
Copy link
Contributor

AF-1227

Ultimate problem:

As a consumer, I should be able to easily merge together the classes and blacklists present in two ClassNameBuilders.

How it was fixed:

Added merge method to ClassNameBuilder class.
Added merged constructor to ClassNameBuilder class.

Testing suggestions:

Run the unit tests they should pass.

Potential areas of regression:

None.


FYA: @greglittlefield-wf @aaronlademann-wf @clairesarsam-wf

@aviary-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on HipChat: InfoSec Forum.

@codecov-io
Copy link

codecov-io commented Jul 16, 2018

Codecov Report

Merging #167 into master will increase coverage by 0.04%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
+ Coverage   94.45%   94.48%   +0.04%     
==========================================
  Files          34       34              
  Lines        1601     1612      +11     
==========================================
+ Hits         1512     1523      +11     
  Misses         89       89

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some little things!!

addFromProps(props);
}

/// Creates a new `ClassNameBuilder` with [_classNamesBuffer] and [_blacklistBuffer] merged from [a] and [b]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit missing period at the end of this sentence.

/// Creates a new `ClassNameBuilder` with [_classNamesBuffer] and [_blacklistBuffer] merged from [a] and [b]
///
/// ClassNameBuilder a = new ClassNameBuilder()
/// ..add('a');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit only one-space indent instead of two


group('merge', () {
test('returns className merged from second builder instance', (){
ClassNameBuilder otherBuilder = new ClassNameBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit for local variables like this, the convention is to omit the typing on the left-hand side (LHS)

See more info here: https://www.dartlang.org/guides/language/effective-dart/design#avoid-type-annotating-initialized-local-variables

});

group('created with .merged() constructor', () {
test('',(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit formatting, missing whitespace after comma and before curly brace

});

group('merge', () {
test('returns className merged from second builder instance', (){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "returns" part of this test description is misleading, since merge is a void and doesn't return anything.

Should be something like:

group('merge, () {
  test('merges the className from the provided builder instance', (){

/// Merges together the classes and blacklists present in another `ClassNameBuilder` instance.
///
/// Takes [other._blacklistBuffer] and merges it into [_blacklistBuffer]
/// and takes [other._classNamesBuffer] and merges it into [_classNamesBuffer].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This second section is redundant, since it's just describing the below code; we could probably just remove it.




/// Merges together the classes and blacklists present in another `ClassNameBuilder` instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use a reference to [other].

#nit "ClassNameBuilder instance" is redundant: See https://www.dartlang.org/guides/language/effective-dart/documentation#avoid-redundancy-with-the-surrounding-context

Also, "merges together" is a little vague. What about:

/// Merges the classes and blacklists from [other] into this builder.

_blacklistBuffer.write(other._blacklistBuffer);

if (_classNamesBuffer == null) {
_classNamesBuffer = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always initialized (resulting in this line missing test coverage), so this case can probably be removed.

test('returns blacklist merged from second builder instance', (){
ClassNameBuilder otherBuilder = new ClassNameBuilder();

builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are only single setter usages and there's no use case for the returned instance of ClassNameBuilder that the cascade provides, it would be the same functionality and more terse to do:

builder.blacklist('a-blacklist');
otherBuilder.blacklist('b-blacklist');

test('returns classname and blacklist merged from second builder instance', (){
ClassNameBuilder otherBuilder = new ClassNameBuilder();

builder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClassNameBuilder otherBuilder = new ClassNameBuilder();

builder
..add('a');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(builder.toClassName(), equals('a b'));
});

test('returns blacklist merged from second builder instance', (){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nit needs a space after the parenthesis: (){ => () {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Occurs a couple other places in this file as well

Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome work @kealjones-wk!

+1

kid screaming and cheering with excitement

otherBuilder.add('b');

builder.merge(otherBuilder);
expect(builder.toClassName(), equals('a b'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kealjones-wk you don't have to change this, but equals is the default Matcher for the second arg of expect, so it can be omitted. Like I said - you definitely do not have to change this, as we are certainly not consistent with this in any of our repos... but I thought I'd point it out.

expect(builder.toClassName(), 'a b');

@aaronlademann-wf
Copy link
Contributor

QA +1

  • Testing instruction
  • Dev +1's
  • Unit tests created/updated
  • All unit tests pass
  • Rosie ran/Rosie comment displays expected info
  • Dependency Scan Clean

Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants