Skip to content

Commit

Permalink
Bug and test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekyShiva committed Jan 27, 2020
1 parent 8d5faf4 commit 522ab41
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ God Class | Extract Class | Schema



:x: Following Code from ```Args.java``` has been decompsed into ```ArgsData.java```
:x: Following Code from ```Args.java``` has been decomposed into ```ArgsData.java```

```
private void parseSchemaElement(String element) throws ArgsException {
Expand Down Expand Up @@ -390,5 +390,66 @@ public boolean getBoolean(char arg) {
```


## Tests :zap:

:heavy_plus_sign: Following test code has been added in order to cover all the test conditions and remove any potential smells if present at all

```
public void testOkMessage() throws Exception {
ArgsException e = new ArgsException(OK, 'x', null);
assertEquals("TILT: Should not get here.", e.errorMessage());
}
```

also to handle concatinated type strings as arguments.

```
@Test
public void testContinuousFlags() throws Exception {
Args argsData = new Args("x#,y##", new String[]{"-xy", "20", "4.5"});
assertTrue(argsData.has('x'));
assertTrue(argsData.has('y'));
assertEquals(20, argsData.getInt('x'));
assertEquals(4.5, argsData.getDouble('y'),.001);
}
}
```
:heavy_plus_sign: ```MalformedMap``` has been modified as well since it was incomplete in the code.

```
@Test
public void malFormedMapArgument() throws Exception {
try {
new Args("f&", new String[] {"-f", "key1:val1,key2"});
fail();
} catch (ArgsException e) {
assertEquals(MALFORMED_MAP, e.getErrorCode());
assertEquals('f', e.getErrorArgumentId());
}
}
```

## Bug

The JavaArgs program is not fully bug free but has a bug in the schema which is described below :


The arguments essentially read only single command line character that is passed and overlooking the characters passed after.

For example
```
Args args = new Args("x,y", new String[]{"-x", "alpha", "-y", "beta"});
```

In the above code the arguments taken and tested are primarily alpha and not beta if passed as serial arguments.

### Fix

Fix for this would be changing the schema definition handling and parsing in the code

## License
[MIT](https://choosealicense.com/licenses/mit/)
13 changes: 13 additions & 0 deletions test/com/cleancoder/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,17 @@ public void testExtraArgumentsThatLookLikeFlags() throws Exception {
assertFalse(args.getBoolean('y'));
assertEquals(1, args.nextArgument());
}


@Test
public void testContinuousFlags() throws Exception {
Args argsData = new Args("x#,y##", new String[]{"-xy", "20", "4.5"});
assertTrue(argsData.has('x'));
assertTrue(argsData.has('y'));
assertEquals(20, argsData.getInt('x'));
assertEquals(4.5, argsData.getDouble('y'),.001);

}
}


0 comments on commit 522ab41

Please sign in to comment.