Skip to content

Commit 7b7458a

Browse files
committed
- brings options tests to 100%
1 parent db1fce8 commit 7b7458a

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎src/main/java/com/microsoft/graph/options/FunctionOption.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// ------------------------------------------------------------------------------
22
// Copyright (c) 2017 Microsoft Corporation
3-
//
3+
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
66
// in the Software without restriction, including without limitation the rights
77
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
88
// copies of the Software, and to permit persons to whom the Software is
99
// furnished to do so, subject to the following conditions:
10-
//
10+
//
1111
// The above copyright notice and this permission notice shall be included in
1212
// all copies or substantial portions of the Software.
13-
//
13+
//
1414
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -34,6 +34,6 @@ public class FunctionOption extends Option {
3434
* @param value the value of the option
3535
*/
3636
public FunctionOption(@Nonnull final String name, @Nonnull final Object value) {
37-
super(name, value != null ? value : null);
37+
super(name, value);
3838
}
3939
}

‎src/main/java/com/microsoft/graph/options/Option.java‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// ------------------------------------------------------------------------------
22
// Copyright (c) 2017 Microsoft Corporation
3-
//
3+
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
66
// in the Software without restriction, including without limitation the rights
77
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
88
// copies of the Software, and to permit persons to whom the Software is
99
// furnished to do so, subject to the following conditions:
10-
//
10+
//
1111
// The above copyright notice and this permission notice shall be included in
1212
// all copies or substantial portions of the Software.
13-
//
13+
//
1414
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -41,18 +41,24 @@ public class Option {
4141

4242
/**
4343
* Creates an option object
44-
*
44+
*
4545
* @param name the name of the option
4646
* @param value the value of the option
4747
*/
4848
protected Option(@Nonnull final String name, @Nonnull final Object value) {
49+
if(name == null || name == "") {
50+
throw new IllegalArgumentException("name should not be null or empty");
51+
}
52+
if(value == null) {
53+
throw new IllegalArgumentException("value should not be null");
54+
}
4955
this.name = name;
5056
this.value = value;
5157
}
5258

5359
/**
5460
* Gets the name of the option
55-
*
61+
*
5662
* @return the name of the option
5763
*/
5864
@Nonnull
@@ -62,7 +68,7 @@ public String getName() {
6268

6369
/**
6470
* Gets the value of the option
65-
*
71+
*
6672
* @return the value of the option
6773
*/
6874
@Nonnull

‎src/test/java/com/microsoft/graph/options/OptionTests.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.microsoft.graph.options;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
import static org.junit.Assert.fail;
46

57
import org.junit.Test;
68

@@ -23,6 +25,25 @@ public void testOption() {
2325
Option option = new Option("o1","ov1");
2426
assertEquals("o1",option.getName());
2527
assertEquals("ov1",option.getValue());
28+
29+
try {
30+
new Option(null, "onion");
31+
fail("should fail on null name");
32+
} catch(Exception ex) {
33+
assertTrue("exception is IllegalArgument", ex.getClass() == IllegalArgumentException.class);
34+
}
35+
try {
36+
new Option("", "onion");
37+
fail("should fail on empty name");
38+
} catch(Exception ex) {
39+
assertTrue("exception is IllegalArgument", ex.getClass() == IllegalArgumentException.class);
40+
}
41+
try {
42+
new Option("onion", null);
43+
fail("should fail on null value");
44+
} catch(Exception ex) {
45+
assertTrue("exception is IllegalArgument", ex.getClass() == IllegalArgumentException.class);
46+
}
2647
}
2748

2849
}

0 commit comments

Comments
 (0)